From a1feadb9176db41b61d8c717498d18fe6f1cdeb0 Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 13 Sep 2024 09:54:05 +0600 Subject: [PATCH] api/bluesky: add support for recordWithMedia embed type & catch various api errors --- api/src/processing/services/bluesky.js | 31 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/api/src/processing/services/bluesky.js b/api/src/processing/services/bluesky.js index 84571bcd..5f5cbcec 100644 --- a/api/src/processing/services/bluesky.js +++ b/api/src/processing/services/bluesky.js @@ -2,8 +2,8 @@ import HLS from "hls-parser"; import { cobaltUserAgent } from "../../config.js"; import { createStream } from "../../stream/manage.js"; -const extractVideo = async ({ getPost, filename }) => { - const urlMasterHLS = getPost?.thread?.post?.embed?.playlist; +const extractVideo = async ({ media, filename }) => { + const urlMasterHLS = media?.playlist; if (!urlMasterHLS) return { error: "fetch.empty" }; if (!urlMasterHLS.startsWith("https://video.bsky.app/")) return { error: "fetch.empty" }; @@ -77,14 +77,37 @@ export default async function ({ user, post, alwaysProxy }) { } }).then(r => r.json()).catch(() => {}); - if (!getPost || getPost?.error) return { error: "fetch.empty" }; + if (!getPost) return { error: "fetch.empty" }; + + if (getPost.error) { + switch (getPost.error) { + case "NotFound": + case "InternalServerError": + return { error: "content.post.unavailable" }; + case "InvalidRequest": + return { error: "link.unsupported" }; + default: + return { error: "fetch.empty" }; + } + } const embedType = getPost?.thread?.post?.embed?.$type; const filename = `bluesky_${user}_${post}`; if (embedType === "app.bsky.embed.video#view") { - return extractVideo({ getPost, filename }); + return extractVideo({ + media: getPost.thread?.post?.embed, + filename, + }) } + + if (embedType === "app.bsky.embed.recordWithMedia#view") { + return extractVideo({ + media: getPost.thread?.post?.embed?.media, + filename, + }) + } + if (embedType === "app.bsky.embed.images#view") { return extractImages({ getPost, filename, alwaysProxy }); }