1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-16 13:17:30 +00:00
bibliogram/src/lib/structures/TimelineBaseMethods.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

const constants = require("../constants")
2020-01-29 15:20:20 +00:00
const {proxyImage, proxyVideo} = require("../utils/proxyurl")
class TimelineBaseMethods {
constructor() {
/** @type {import("../types").GraphChildAll & {owner?: any}} */
this.data
}
getType() {
if (this.data.__typename === "GraphImage") {
if (this.data.owner) return constants.symbols.TYPE_IMAGE
else return constants.symbols.TYPE_GALLERY_IMAGE
} else if (this.data.__typename === "GraphVideo") {
if (this.data.owner) return constants.symbols.TYPE_VIDEO
else return constants.symbols.TYPE_GALLERY_VIDEO
} else if (this.data.__typename === "GraphSidecar") {
return constants.symbols.TYPE_GALLERY
} else {
throw new Error("Unknown shortcode __typename: "+this.data.__typename)
}
}
2020-01-29 15:20:20 +00:00
isVideo() {
return this.data.__typename === "GraphVideo"
}
getDisplayUrlP() {
return proxyImage(this.data.display_url)
}
2020-01-29 15:20:20 +00:00
getVideoUrlP() {
return proxyVideo(this.data.video_url)
}
getAlt() {
return this.data.accessibility_caption || "No image description available."
}
}
module.exports = TimelineBaseMethods