From c57d51e3ebe33ea484ced9cbfed513527004ad85 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 10 Jul 2020 22:34:06 +1200 Subject: [PATCH] Embed videos in feeds --- src/lib/structures/TimelineChild.js | 19 +++++++++++++++++-- src/lib/structures/TimelineEntry.js | 9 ++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/lib/structures/TimelineChild.js b/src/lib/structures/TimelineChild.js index daa9a57..2be2028 100644 --- a/src/lib/structures/TimelineChild.js +++ b/src/lib/structures/TimelineChild.js @@ -1,9 +1,16 @@ -const config = require("../../../config") -const {proxyImage} = require("../utils/proxyurl") +const constants = require("../constants") const collectors = require("../collectors") const TimelineBaseMethods = require("./TimelineBaseMethods") +const {compile} = require("pug") require("../testimports")(collectors) +const rssImageTemplate = compile(` +img(src=constants.website_origin+entry.getDisplayUrlP() alt=entry.getAlt() width=entry.data.dimensions.width height=entry.data.dimensions.height) +`) +const rssVideoTemplate = compile(` +video(src=constants.website_origin+entry.getVideoUrlP() controls preload="auto" width=entry.data.dimensions.width height=entry.data.dimensions.height) +`) + class TimelineChild extends TimelineBaseMethods { /** * @param {import("../types").GraphChildAll} data @@ -12,6 +19,14 @@ class TimelineChild extends TimelineBaseMethods { super() this.data = data } + + getFeedItem() { + if (this.data.video_url) { + return rssVideoTemplate({entry: this, constants}) + } else { + return rssImageTemplate({entry: this, constants}) + } + } } module.exports = TimelineChild diff --git a/src/lib/structures/TimelineEntry.js b/src/lib/structures/TimelineEntry.js index 1e9b878..1b0ce8d 100644 --- a/src/lib/structures/TimelineEntry.js +++ b/src/lib/structures/TimelineEntry.js @@ -10,7 +10,7 @@ require("../testimports")(collectors, TimelineChild, TimelineBaseMethods) const rssDescriptionTemplate = compile(` p(style='white-space: pre-line')= caption each child in children - img(alt=child.alt src=child.src width=child.width height=child.height) + != child.getFeedItem() `) class TimelineEntry extends TimelineBaseMethods { @@ -262,12 +262,7 @@ class TimelineEntry extends TimelineBaseMethods { title: this.getCaptionIntroduction() || `New post from @${this.getBasicOwner().username}`, description: rssDescriptionTemplate({ caption: this.getCaption(), - children: children.map(child => ({ - src: `${constants.website_origin}${child.getDisplayUrlP()}`, - alt: child.getAlt(), - width: child.data.dimensions.width, - height: child.data.dimensions.height - })) + children }), link: `${constants.website_origin}/p/${this.data.shortcode}`, id: `bibliogram:post/${this.data.shortcode}`, // Is it wise to keep the origin in here? The same post would have a different ID from different servers.