Skip to content

Commit

Permalink
refactor: reuse lsid() in bilibili util
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoyu committed Oct 17, 2024
1 parent c986500 commit b8695ad
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/routes/bilibili/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getCookie = () => {
for (const key of Object.keys(config.bilibili.cookies)) {
const cookie = config.bilibili.cookies[key];
if (cookie) {
const updatedCookie = cookie.replace(/b_lsid=[0-9A-F]+_[0-9A-F]+/, `b_lsid=${generateBLsid()}`);
const updatedCookie = cookie.replace(/b_lsid=[0-9A-F]+_[0-9A-F]+/, `b_lsid=${utils.lsid()}`);
config.bilibili.cookies[key] = updatedCookie;
}
}
Expand All @@ -34,7 +34,7 @@ const getCookie = () => {
const cookies = await page.cookies();
let cookieString = cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join('; ');

cookieString = cookieString.replace(/b_lsid=[0-9A-F]+_[0-9A-F]+/, `b_lsid=${generateBLsid()}`);
cookieString = cookieString.replace(/b_lsid=[0-9A-F]+_[0-9A-F]+/, `b_lsid=${utils.lsid()}`);
resolve(cookieString);
}
});
Expand All @@ -47,12 +47,6 @@ const getCookie = () => {
});
};

const generateBLsid = () => {
const randomString = Array.from({ length: 8 }, () => '0123456789ABCDEF'[Math.floor(Math.random() * 16)]).join('');
const timestamp = Date.now();
return `${randomString}_${timestamp.toString(16).toUpperCase()}`;
};

const clearCookie = () => {
cache.set('bili-cookie');
disableConfigCookie = true;
Expand Down

0 comments on commit b8695ad

Please sign in to comment.