forked from mirrors/amputoma-fe
fix media type handling
This commit is contained in:
parent
a2e1b6f735
commit
5565dc5a66
1 changed files with 21 additions and 0 deletions
|
@ -17,8 +17,19 @@
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
mimeType: null
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
mediaTag() {
|
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'
|
if (!this.src) return 'img'
|
||||||
const extension = this.src.split('.').pop().toLowerCase()
|
const extension = this.src.split('.').pop().toLowerCase()
|
||||||
|
|
||||||
|
@ -35,6 +46,16 @@
|
||||||
const encodedUrl = encodeURIComponent(this.src)
|
const encodedUrl = encodeURIComponent(this.src)
|
||||||
return `/api/media?url=${encodedUrl}`
|
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>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue