refactor: update EmbedVideo to receive other media

This commit is contained in:
axolotle
2024-09-24 18:41:51 +02:00
parent 19b47b4f6c
commit 7963315023
+14 -11
View File
@@ -12,7 +12,9 @@ export default {
name: 'EmbedVideo', name: 'EmbedVideo',
props: { props: {
src: { type: String, required: true } src: { type: String, required: true },
type: { type: String, required: true },
full: { type: Boolean, default: false }
}, },
data () { data () {
@@ -54,22 +56,23 @@ export default {
item () { item () {
const embed = this.embed const embed = this.embed
let src = this.src
const attrs = this.type === 'iframe' ? { allowfullscreen: true } : { controls: true }
if (this.full && this.type === 'iframe') {
attrs.width = '100%'
attrs.height = '100%'
}
if (embed) { if (embed) {
const query = Object.entries(embed.params).map(entry => entry.join('=')).join('&') const query = Object.entries(embed.params).map(entry => entry.join('=')).join('&')
const and = embed.url.indexOf('?') >= 0 ? '&' : '?' src = this.src.replace(embed.reg, embed.url)
return { if (!this.full) {
type: 'iframe', src += embed.url.indexOf('?') >= 0 ? '&' : '?' + query
src: this.src.replace(embed.reg, embed.url) + and + query,
attrs: { allowfullscreen: true }
} }
} }
return { return { type: this.type, src, attrs }
type: 'video',
src: this.src,
attrs: { controls: true }
}
} }
} }
} }