1
0

Add file image as fallback preview

This commit is contained in:
Elscrux 2024-05-24 12:45:30 +02:00
parent 658936a070
commit ef8bb5aca9
3 changed files with 14 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import {
faExclamation,
faEye,
faEyeSlash,
faFileImage,
faFillDrip,
faFilter,
faForward,
@ -81,7 +82,6 @@ import {
faCheckSquare,
faClock,
faComments,
faFileImage,
faSave,
faSquareCheck,
faStar,

View File

@ -35,7 +35,6 @@
>
<div class="preview-column">
<FilePreview
v-if="canPreview(a)"
class="attachment-preview"
:model-value="a"
/>

View File

@ -1,14 +1,21 @@
<template>
<img
v-if="blobUrl"
:src="blobUrl"
alt="Attachment preview"
>
<icon
v-else
size="6x"
icon="file-image"
/>
</template>
<script setup lang="ts">
import {type PropType, ref, shallowReactive, watchEffect} from 'vue'
import AttachmentService from '@/services/attachment'
import type {IAttachment} from '@/modelTypes/IAttachment'
import {SUPPORTED_IMAGE_SUFFIX} from '@/models/attachment'
const props = defineProps({
modelValue: {
@ -21,10 +28,14 @@ const attachmentService = shallowReactive(new AttachmentService())
const blobUrl = ref<string | undefined>(undefined)
watchEffect(async () => {
if (props.modelValue) {
if (props.modelValue && canPreview(props.modelValue)) {
blobUrl.value = await attachmentService.getBlobUrl(props.modelValue)
}
})
function canPreview(attachment: IAttachment): boolean {
return SUPPORTED_IMAGE_SUFFIX.some((suffix) => attachment.file.name.endsWith(suffix))
}
</script>
<style scoped lang="scss">