Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: w_webid TTL
Browse files Browse the repository at this point in the history
snowtafir committed Jan 11, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c9a6873 commit a67ab8f
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions models/bilibili/bilibili.risk.w_webid.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@ import { cookieWithBiliTicket, readSyncCookie } from '@/models/bilibili/bilibili
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);
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__');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit a67ab8f

Please sign in to comment.