jormungandr-bite/packages/client/src/components/MkDriveFileThumbnail.vue

81 lines
2.4 KiB
Vue
Raw Normal View History

<template>
2021-11-19 03:36:12 -07:00
<div ref="thumbnail" class="zdjebgpv">
<ImgWithBlurhash v-if="isThumbnailAvailable" :hash="file.blurhash" :src="file.thumbnailUrl" :alt="file.name" :title="file.name" :cover="fit !== 'contain'"/>
2022-11-06 19:49:47 -07:00
<i v-else-if="is === 'image'" class="ph-file-image-bold ph-lg icon"></i>
<i v-else-if="is === 'video'" class="ph-file-video-bold ph-lg icon"></i>
<i v-else-if="is === 'audio' || is === 'midi'" class="ph-file-audio-bold ph-lg icon"></i>
<i v-else-if="is === 'csv'" class="ph-file-csv-bold ph-lg icon"></i>
<i v-else-if="is === 'pdf'" class="ph-file-pdf-bold ph-lg icon"></i>
<i v-else-if="is === 'textfile'" class="ph-file-text-bold ph-lg icon"></i>
<i v-else-if="is === 'archive'" class="ph-file-zip-bold ph-lg icon"></i>
<i v-else class="ph-file-bold ph-lg icon"></i>
2022-11-06 19:49:47 -07:00
<i v-if="isThumbnailAvailable && is === 'video'" class="ph-file-video-bold ph-lg icon-sub"></i>
</div>
</template>
<script lang="ts" setup>
import { computed } from 'vue';
2022-11-06 18:33:52 -07:00
import type * as Misskey from 'misskey-js';
import ImgWithBlurhash from '@/components/MkImgWithBlurhash.vue';
const props = defineProps<{
file: Misskey.entities.DriveFile;
fit: string;
}>();
const is = computed(() => {
if (props.file.type.startsWith('image/')) return 'image';
if (props.file.type.startsWith('video/')) return 'video';
if (props.file.type === 'audio/midi') return 'midi';
if (props.file.type.startsWith('audio/')) return 'audio';
if (props.file.type.endsWith('/csv')) return 'csv';
if (props.file.type.endsWith('/pdf')) return 'pdf';
if (props.file.type.startsWith('text/')) return 'textfile';
if ([
'application/zip',
'application/x-cpio',
'application/x-bzip',
'application/x-bzip2',
'application/java-archive',
'application/x-rar-compressed',
'application/x-tar',
'application/gzip',
'application/x-7z-compressed',
].some(archiveType => archiveType === props.file.type)) return 'archive';
return 'unknown';
});
const isThumbnailAvailable = computed(() => {
return props.file.thumbnailUrl
? (is.value === 'image' as const || is.value === 'video')
: false;
});
</script>
<style lang="scss" scoped>
.zdjebgpv {
2020-02-07 04:25:49 -07:00
position: relative;
2021-12-09 18:46:29 -07:00
display: flex;
background: var(--panel);
2021-12-09 18:46:29 -07:00
border-radius: 8px;
2022-07-13 06:41:06 -06:00
overflow: clip;
> .icon-sub {
position: absolute;
width: 30%;
height: auto;
margin: 0;
right: 4%;
bottom: 4%;
}
> .icon {
pointer-events: none;
2021-12-09 18:46:29 -07:00
margin: auto;
font-size: 32px;
color: #777;
}
}
</style>