Skip to content

Commit

Permalink
feat: do not proxy netease2 images
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoOwO committed Jan 15, 2023
1 parent 23a7352 commit 0002704
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
16 changes: 15 additions & 1 deletion dataModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
//-----------------------------> 歌詞
// 搜尋歌詞
Expand Down
27 changes: 9 additions & 18 deletions dataModule/netease2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0002704

Please sign in to comment.