diff --git a/package.json b/package.json index 66605b2..762211b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yz-yuki-plugin", - "version": "2.0.6-7", + "version": "2.0.6-8", "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件", "author": "snowtafir", "type": "module", diff --git a/src/models/bilibili/bilibili.risk.w_webid.ts b/src/models/bilibili/bilibili.risk.w_webid.ts index 23ba51c..7b7f87c 100644 --- a/src/models/bilibili/bilibili.risk.w_webid.ts +++ b/src/models/bilibili/bilibili.risk.w_webid.ts @@ -7,7 +7,8 @@ import { cookieWithBiliTicket, readSyncCookie } from '@src/models/bilibili/bilib export async function getWebId(uid?: number) { const w_webid_key = 'Yz:yuki:bili:w_webid'; const w_webid = await Redis.get(w_webid_key); - if (w_webid) { + const keyTTL = await Redis.ttl(w_webid_key); + if (w_webid && keyTTL < 259200) { return String(w_webid); } else { const url = `https://space.bilibili.com/${uid ? uid : 401742377}/dynamic`; @@ -29,8 +30,11 @@ export async function getWebId(uid?: number) { const decoded__RENDER_DATA__JsonString = decodeURIComponent(__RENDER_DATA__[1]); const accessIdRegex = /"access_id":"(.*?)"/; const access_id = decoded__RENDER_DATA__JsonString.match(accessIdRegex); - if (access_id && access_id[1]) { - await Redis.set(w_webid_key, access_id[1], { EX: 43197 * 1000 }); + const ExpirationTimeRegex = + /document.getElementById\("__RENDER_DATA__"\).*?setTimeout\(function\(\)\s*{window.location.reload\(true\);},\s*(\d+)\s*\*\s*(\d+)\);<\/script>/; + const ExpirationTime = htmlContent.match(ExpirationTimeRegex); + if (access_id && access_id[1] && ExpirationTime && ExpirationTime[1]) { + await Redis.set(w_webid_key, access_id[1], { EX: Number(ExpirationTime[1]) }); return String(access_id[1]); } else { console.error('Failed to get access_id from __RENDER_DATA__');