pleroma-fe/src/components/link-preview/link-preview.js

40 lines
962 B
JavaScript
Raw Normal View History

import { mapGetters } from 'vuex'
2019-01-27 13:47:30 +00:00
const LinkPreview = {
name: 'LinkPreview',
2026-01-06 16:22:52 +02:00
props: ['card', 'size', 'nsfw'],
data() {
return {
2026-01-06 16:22:52 +02:00
imageLoaded: false,
}
},
2019-01-27 22:33:36 +02:00
computed: {
2026-01-06 16:22:52 +02:00
useImage() {
2019-01-27 22:33:36 +02:00
// Currently BE shoudn't give cards if tagged NSFW, this is a bit paranoid
// as it makes sure to hide the image if somehow NSFW tagged preview can
// exist.
return this.card.image && !this.censored && this.size !== 'hide'
},
2026-01-06 16:22:52 +02:00
censored() {
return this.nsfw && this.hideNsfwConfig
2019-01-27 22:33:36 +02:00
},
2026-01-06 16:22:52 +02:00
useDescription() {
2019-01-27 22:33:36 +02:00
return this.card.description && /\S/.test(this.card.description)
},
2026-01-06 16:22:52 +02:00
hideNsfwConfig() {
return this.mergedConfig.hideNsfw
},
2026-01-06 16:22:52 +02:00
...mapGetters(['mergedConfig']),
},
2026-01-06 16:22:52 +02:00
created() {
if (this.useImage) {
const newImg = new Image()
newImg.onload = () => {
this.imageLoaded = true
}
newImg.src = this.card.image
}
2026-01-06 16:22:52 +02:00
},
2019-01-27 13:47:30 +00:00
}
export default LinkPreview