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',
props: {
src: { type: String, required: true }
src: { type: String, required: true },
type: { type: String, required: true },
full: { type: Boolean, default: false }
},
data () {
@@ -54,22 +56,23 @@ export default {
item () {
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) {
const query = Object.entries(embed.params).map(entry => entry.join('=')).join('&')
const and = embed.url.indexOf('?') >= 0 ? '&' : '?'
return {
type: 'iframe',
src: this.src.replace(embed.reg, embed.url) + and + query,
attrs: { allowfullscreen: true }
src = this.src.replace(embed.reg, embed.url)
if (!this.full) {
src += embed.url.indexOf('?') >= 0 ? '&' : '?' + query
}
}
return {
type: 'video',
src: this.src,
attrs: { controls: true }
}
return { type: this.type, src, attrs }
}
}
}