Skip to content

Commit

Permalink
fix: w_webid TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Jan 11, 2025
1 parent 57cb132 commit ff3f6d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/models/bilibili/bilibili.risk.w_webid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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__');
Expand Down

0 comments on commit ff3f6d0

Please sign in to comment.