2026-01-23 15:07:31 +02:00
|
|
|
import { mapState } from 'pinia'
|
|
|
|
|
|
|
|
|
|
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
2020-11-12 06:16:41 +03:00
|
|
|
|
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() {
|
2019-08-04 14:15:43 -04:00
|
|
|
return {
|
2026-01-06 16:22:52 +02:00
|
|
|
imageLoaded: false,
|
2019-08-04 14:15:43 -04:00
|
|
|
}
|
|
|
|
|
},
|
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.
|
2020-11-12 06:16:41 +03:00
|
|
|
return this.card.image && !this.censored && this.size !== 'hide'
|
|
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
censored() {
|
2020-11-12 06:16:41 +03:00
|
|
|
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)
|
2020-11-12 06:16:41 +03:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
hideNsfwConfig() {
|
2020-11-12 06:16:41 +03:00
|
|
|
return this.mergedConfig.hideNsfw
|
|
|
|
|
},
|
2026-01-23 15:07:31 +02:00
|
|
|
...mapState(useSyncConfigStore, ['mergedConfig']),
|
2019-08-04 14:15:43 -04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
created() {
|
2019-08-04 14:15:43 -04:00
|
|
|
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
|