fix media type handling

This commit is contained in:
Leafy :3 2025-02-09 00:01:24 +01:00
parent a2e1b6f735
commit 5565dc5a66

View file

@ -17,8 +17,19 @@
required: true
}
},
data() {
return {
mimeType: null
}
},
computed: {
mediaTag() {
if (this.mimeType) {
if (this.mimeType.startsWith('video/')) return 'video'
if (this.mimeType.startsWith('audio/')) return 'audio'
if (this.mimeType.startsWith('image/')) return 'img'
}
if (!this.src) return 'img'
const extension = this.src.split('.').pop().toLowerCase()
@ -35,6 +46,16 @@
const encodedUrl = encodeURIComponent(this.src)
return `/api/media?url=${encodedUrl}`
}
},
async created() {
if (this.src) {
try {
const response = await fetch(this.src, { method: 'HEAD' })
this.mimeType = response.headers.get('Content-Type')
} catch (error) {
console.warn('Cannot detect MIME type:', error)
}
}
}
}
</script>