From a3a60e8c9541b6c8fb5ff57060923392c23da5e4 Mon Sep 17 00:00:00 2001 From: snowtafir Date: Sat, 11 Jan 2025 17:51:51 +0800 Subject: [PATCH] fix: w_webid TTL --- models/bilibili/bilibili.risk.w_webid.ts | 8 ++++++-- package.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/models/bilibili/bilibili.risk.w_webid.ts b/models/bilibili/bilibili.risk.w_webid.ts index 7901d8d..452fbac 100644 --- a/models/bilibili/bilibili.risk.w_webid.ts +++ b/models/bilibili/bilibili.risk.w_webid.ts @@ -8,7 +8,8 @@ declare const redis: any; 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`; @@ -30,8 +31,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); + 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]) { - await redis.set(w_webid_key, access_id[1], { EX: 43197 * 1000 }); + 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__'); diff --git a/package.json b/package.json index f93ae92..856fde0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yuki-plugin", - "version": "2.0.6-7", + "version": "2.0.6-8", "author": "snowtafir", "description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件", "main": "./index",