feat: support displaying video
This commit is contained in:
parent
757a93c2a2
commit
eb3f0655eb
3 changed files with 24 additions and 3 deletions
|
@ -1,17 +1,24 @@
|
|||
<script setup lang="ts">
|
||||
import { clamp } from '@vueuse/core'
|
||||
import type { Attachment } from 'masto'
|
||||
|
||||
const { attachment } = defineProps<{
|
||||
attachment: Attachment
|
||||
}>()
|
||||
|
||||
const aspectRatio = computed(() => {
|
||||
const rawAspectRatio = computed(() => {
|
||||
if (attachment.meta?.original?.aspect)
|
||||
return attachment.meta.original.aspect
|
||||
if (attachment.meta?.small?.aspect)
|
||||
return attachment.meta.small.aspect
|
||||
return undefined
|
||||
})
|
||||
|
||||
const aspectRatio = computed(() => {
|
||||
if (rawAspectRatio.value)
|
||||
return clamp(rawAspectRatio.value, 0.5, 2)
|
||||
return undefined
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -21,13 +28,26 @@ const aspectRatio = computed(() => {
|
|||
class="status-attachment-image"
|
||||
:src="attachment.previewUrl!"
|
||||
:alt="attachment.description!"
|
||||
border="~ border"
|
||||
:style="{
|
||||
aspectRatio,
|
||||
}"
|
||||
border="~ border"
|
||||
object-cover rounded-lg
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="attachment.type === 'video'">
|
||||
<video
|
||||
:poster="attachment.previewUrl"
|
||||
controls
|
||||
border="~ border"
|
||||
object-cover
|
||||
:style="{
|
||||
aspectRatio,
|
||||
}"
|
||||
>
|
||||
<source :src="attachment.url || attachment.previewUrl" type="video/mp4">
|
||||
</video>
|
||||
</template>
|
||||
<template v-else>
|
||||
TODO:
|
||||
<pre>{{ attachment }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue