diff --git a/lib/routes/bilibili/cache.ts b/lib/routes/bilibili/cache.ts index 7e4c4951caf697..a4a43e83ecda6e 100644 --- a/lib/routes/bilibili/cache.ts +++ b/lib/routes/bilibili/cache.ts @@ -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; } } @@ -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); } }); @@ -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;