From 00027047535987febf44b53ddcf875309cfb5620 Mon Sep 17 00:00:00 2001 From: Leko Date: Sun, 15 Jan 2023 21:20:52 +0800 Subject: [PATCH] feat: do not proxy netease2 images --- dataModule.js | 16 +++++++++++++++- dataModule/netease2.js | 27 +++++++++------------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/dataModule.js b/dataModule.js index 5daa881..f6aaa1c 100644 --- a/dataModule.js +++ b/dataModule.js @@ -435,7 +435,21 @@ router.get("/req/", async (req, res) => { //http://localhost:3000/pokaapi/req/?moduleName=Netease2&data=http%3A%2F%2Fp3.music.126.net%2FJB1yLZyVMPsbbSlSkfJdRw%3D%3D%2F6630055116648156.jpg // -> Image let cover = await _module.req(req.query.data); - return cover ? cover.pipe(res) : false; + if (!cover) return res.sendStatus(404); + + if (typeof cover == "string" && cover.startsWith("http")) return res.redirect(cover); + + if (cover.pipe) { + res.header("Cache-Control", "max-age=7200") //快取 2hr + return cover.pipe(res); + } + + if (cover instanceof Buffer) { + res.header("Cache-Control", "max-age=7200") //快取 2hr + return res.send(cover); + } + + return res.sendStatus(500); }); //-----------------------------> 歌詞 // 搜尋歌詞 diff --git a/dataModule/netease2.js b/dataModule/netease2.js index bb0317b..590df90 100644 --- a/dataModule/netease2.js +++ b/dataModule/netease2.js @@ -237,30 +237,21 @@ async function onLoaded() { } } +function genReq(link) { + return Buffer.from(link).toString("base64") +} +function deReq(x) { + return Buffer.from(x, "base64").toString("utf8"); +} async function req(x) { - function deReq(x) { - const b2a = x => Buffer.from(x, "base64").toString("utf8"); - const decode = x => /(.{5})(.+)3C4C7CB3(.+)/.exec(x); - - let [_, rand, link, checkSum] = decode(x); - [_, rand, link, checkSum] = [_, rand, b2a(link), b2a(checkSum)]; - if (!Number.isInteger(Math.log10(rand.charCodeAt(0) + checkSum.charCodeAt(0)))) { - return false; - } - return link; - } let link = deReq(x); if (!link) return false; + const re = /^(http|https)\:\/\/p(\d+)\.music\.126\.net\/(?:.+)/; if (!re.test(link)) return false; - else return client(await normalOptions(link)); -} -function genReq(link) { - const a2b = x => Buffer.from(x).toString("base64"); - const rand = Math.random().toString(36).substring(2, 7) - const checkSum = N => 10 ** Number(N).toString().length - N; - return `${rand}${a2b(link)}3C4C7CB3${a2b(String.fromCharCode(checkSum(rand.charCodeAt(0))))}`; + // return client(await normalOptions(link)); + return link; } async function parseSongs(songs, br = 999000) {