Patch pages-api.js to include storyboard API

This commit is contained in:
Emre Özcan 2024-03-20 19:01:57 +03:00
parent c9d19b76a6
commit 6c3d524001

View file

@ -135,6 +135,49 @@ app.get("/avatars/:v", async function (req, res) {
res.send(body);
} catch {}
});
app.use("/sb/i/:v/:imagePath/:img", async function (req, res) {
const { v, imagePath, img } = req.params;
const { sqp, xywh } = req.query;
const sighMatch = req.url.match(/&sigh=([^&#]+)/);
const sigh = sighMatch ? sighMatch[1] : undefined;
const url = `https://yt.miruku.cafe/sb/i/${v}/${imagePath}/${img}?sqp=${sqp}&sigh=${sigh}&xywh=${req.query.xywh}`;
try {
let f = await modules.fetch(url + `?cachefixer=${btoa(Date.now())}`, {
method: req.method,
});
f.body.pipe(res);
console.log(url)
} catch (error) {
console.error("Error fetching image:", error);
res.status(500).send("Error fetching image");
}
});
app.get("/api/storyboards", async (req, res) => {
const { fetch } = await import("undici");
const id = req.query.v;
const l = req.query.h;
try {
let url = `https://yt.miruku.cafe/api/v1/storyboards/${id}?width=320&height=180`;
let f = await fetch(url);
let body = await f.text();
body = body.replace(/#xywh=(\d+),(\d+),(\d+),(\d+)/g, (match, x, y, w, h) => {
return `&xywh=${x},${y},${w},${h}`;
});
res.send(body);
} catch {}
});
app.get("/feeds/videos.xml", async (req, res) => {
const id = req.query.channel_id;