Skip to content

Commit 0002704

Browse files
committed
feat: do not proxy netease2 images
1 parent 23a7352 commit 0002704

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

dataModule.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,21 @@ router.get("/req/", async (req, res) => {
435435
//http://localhost:3000/pokaapi/req/?moduleName=Netease2&data=http%3A%2F%2Fp3.music.126.net%2FJB1yLZyVMPsbbSlSkfJdRw%3D%3D%2F6630055116648156.jpg
436436
// -> Image
437437
let cover = await _module.req(req.query.data);
438-
return cover ? cover.pipe(res) : false;
438+
if (!cover) return res.sendStatus(404);
439+
440+
if (typeof cover == "string" && cover.startsWith("http")) return res.redirect(cover);
441+
442+
if (cover.pipe) {
443+
res.header("Cache-Control", "max-age=7200") //快取 2hr
444+
return cover.pipe(res);
445+
}
446+
447+
if (cover instanceof Buffer) {
448+
res.header("Cache-Control", "max-age=7200") //快取 2hr
449+
return res.send(cover);
450+
}
451+
452+
return res.sendStatus(500);
439453
});
440454
//-----------------------------> 歌詞
441455
// 搜尋歌詞

dataModule/netease2.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,30 +237,21 @@ async function onLoaded() {
237237
}
238238
}
239239

240+
function genReq(link) {
241+
return Buffer.from(link).toString("base64")
242+
}
243+
function deReq(x) {
244+
return Buffer.from(x, "base64").toString("utf8");
245+
}
240246
async function req(x) {
241-
function deReq(x) {
242-
const b2a = x => Buffer.from(x, "base64").toString("utf8");
243-
const decode = x => /(.{5})(.+)3C4C7CB3(.+)/.exec(x);
244-
245-
let [_, rand, link, checkSum] = decode(x);
246-
[_, rand, link, checkSum] = [_, rand, b2a(link), b2a(checkSum)];
247-
if (!Number.isInteger(Math.log10(rand.charCodeAt(0) + checkSum.charCodeAt(0)))) {
248-
return false;
249-
}
250-
return link;
251-
}
252247
let link = deReq(x);
253248
if (!link) return false;
249+
254250
const re = /^(http|https)\:\/\/p(\d+)\.music\.126\.net\/(?:.+)/;
255251
if (!re.test(link)) return false;
256-
else return client(await normalOptions(link));
257-
}
258252

259-
function genReq(link) {
260-
const a2b = x => Buffer.from(x).toString("base64");
261-
const rand = Math.random().toString(36).substring(2, 7)
262-
const checkSum = N => 10 ** Number(N).toString().length - N;
263-
return `${rand}${a2b(link)}3C4C7CB3${a2b(String.fromCharCode(checkSum(rand.charCodeAt(0))))}`;
253+
// return client(await normalOptions(link));
254+
return link;
264255
}
265256

266257
async function parseSongs(songs, br = 999000) {

0 commit comments

Comments
 (0)