api/bluesky: catch video errors & prevent loading videos not from bsky
This commit is contained in:
parent
4b4fce326f
commit
645542c910
1 changed files with 11 additions and 8 deletions
|
@ -5,15 +5,20 @@ import { createStream } from "../../stream/manage.js";
|
||||||
const extractVideo = async ({ getPost, filename }) => {
|
const extractVideo = async ({ getPost, filename }) => {
|
||||||
const urlMasterHLS = getPost?.thread?.post?.embed?.playlist;
|
const urlMasterHLS = getPost?.thread?.post?.embed?.playlist;
|
||||||
if (!urlMasterHLS) return { error: "fetch.empty" };
|
if (!urlMasterHLS) return { error: "fetch.empty" };
|
||||||
|
if (!urlMasterHLS.startsWith("https://video.bsky.app/")) return { error: "fetch.empty" };
|
||||||
|
|
||||||
const masterHLS = await fetch(urlMasterHLS)
|
const masterHLS = await fetch(urlMasterHLS)
|
||||||
.then(r => r.text())
|
.then(r => {
|
||||||
.catch(() => {});
|
if (r.status !== 200) return;
|
||||||
if (!masterHLS) return { error: "fetch.fail" };
|
return r.text();
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
|
||||||
|
if (!masterHLS) return { error: "fetch.empty" };
|
||||||
|
|
||||||
const video = HLS.parse(masterHLS)
|
const video = HLS.parse(masterHLS)
|
||||||
?.variants
|
?.variants
|
||||||
?.reduce((a, b) => a?.bandwidth > b?.bandwidth ? a : b);
|
?.reduce((a, b) => a?.bandwidth > b?.bandwidth ? a : b);
|
||||||
|
|
||||||
const videoURL = new URL(video.uri, urlMasterHLS).toString();
|
const videoURL = new URL(video.uri, urlMasterHLS).toString();
|
||||||
|
|
||||||
|
@ -70,9 +75,7 @@ export default async function ({ user, post, alwaysProxy }) {
|
||||||
headers: {
|
headers: {
|
||||||
"user-agent": cobaltUserAgent
|
"user-agent": cobaltUserAgent
|
||||||
}
|
}
|
||||||
})
|
}).then(r => r.json()).catch(() => {});
|
||||||
.then(r => r.json())
|
|
||||||
.catch(() => {});
|
|
||||||
|
|
||||||
if (!getPost || getPost?.error) return { error: "fetch.empty" };
|
if (!getPost || getPost?.error) return { error: "fetch.empty" };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue