From 489723985b9e7bcba898239119e0846bdde33a4d Mon Sep 17 00:00:00 2001 From: imsyy Date: Sat, 7 Dec 2024 09:45:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Fixed=20type=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/getToken/51cto.ts | 7 ++----- src/utils/getToken/bilibili.ts | 11 +++++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/utils/getToken/51cto.ts b/src/utils/getToken/51cto.ts index 992bdf79..f78d3bc9 100644 --- a/src/utils/getToken/51cto.ts +++ b/src/utils/getToken/51cto.ts @@ -4,15 +4,12 @@ import md5 from "md5"; export const getToken = async () => { const cachedData = await getCache("51cto-token"); - if (cachedData && typeof cachedData === "object" && "token" in cachedData) { - const { token } = cachedData as { token: string }; - return token; - } + if (cachedData?.data) return cachedData.data; const result = await get({ url: "https://api-media.51cto.com/api/token-get", }); const token = result.data.data.data.token; - await setCache("51cto-token", { token }); + await setCache("51cto-token", { data: token, updateTime: new Date().toISOString() }); return token; }; diff --git a/src/utils/getToken/bilibili.ts b/src/utils/getToken/bilibili.ts index 0d99ad93..dc8ee326 100644 --- a/src/utils/getToken/bilibili.ts +++ b/src/utils/getToken/bilibili.ts @@ -68,17 +68,16 @@ const getWbiKeys = async (): Promise => { const getBiliWbi = async (): Promise => { const cachedData = await getCache("bilibili-wbi"); - console.log(cachedData); - if (cachedData && typeof cachedData === "object" && "wbi" in cachedData) { - const { wbi } = cachedData as { wbi: string }; - return wbi; - } + if (cachedData?.data) return cachedData.data as string; const web_keys = await getWbiKeys(); const params = { foo: "114", bar: "514", baz: 1919810 }; const img_key = web_keys.img_key; const sub_key = web_keys.sub_key; const query = encWbi(params, img_key, sub_key); - await setCache("bilibili-wbi", { wbi: query }); + await setCache("bilibili-wbi", { + data: query, + updateTime: new Date().toISOString(), + }); return query; };