From 645542c9105ce0582851acc2c435aa4127cf664b Mon Sep 17 00:00:00 2001 From: wukko Date: Tue, 3 Sep 2024 13:24:08 +0600 Subject: [PATCH] api/bluesky: catch video errors & prevent loading videos not from bsky --- api/src/processing/services/bluesky.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/api/src/processing/services/bluesky.js b/api/src/processing/services/bluesky.js index 14e606d0..6ffcb29f 100644 --- a/api/src/processing/services/bluesky.js +++ b/api/src/processing/services/bluesky.js @@ -5,15 +5,20 @@ import { createStream } from "../../stream/manage.js"; const extractVideo = async ({ getPost, filename }) => { const urlMasterHLS = getPost?.thread?.post?.embed?.playlist; if (!urlMasterHLS) return { error: "fetch.empty" }; + if (!urlMasterHLS.startsWith("https://video.bsky.app/")) return { error: "fetch.empty" }; const masterHLS = await fetch(urlMasterHLS) - .then(r => r.text()) - .catch(() => {}); - if (!masterHLS) return { error: "fetch.fail" }; + .then(r => { + if (r.status !== 200) return; + return r.text(); + }) + .catch(() => {}); + + if (!masterHLS) return { error: "fetch.empty" }; const video = HLS.parse(masterHLS) - ?.variants - ?.reduce((a, b) => a?.bandwidth > b?.bandwidth ? a : b); + ?.variants + ?.reduce((a, b) => a?.bandwidth > b?.bandwidth ? a : b); const videoURL = new URL(video.uri, urlMasterHLS).toString(); @@ -70,9 +75,7 @@ export default async function ({ user, post, alwaysProxy }) { headers: { "user-agent": cobaltUserAgent } - }) - .then(r => r.json()) - .catch(() => {}); + }).then(r => r.json()).catch(() => {}); if (!getPost || getPost?.error) return { error: "fetch.empty" };