🐞 fix: Fixed type errors

This commit is contained in:
imsyy
2024-12-07 09:45:18 +08:00
parent 51f27af0d6
commit 489723985b
2 changed files with 7 additions and 11 deletions

View File

@@ -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;
};

View File

@@ -68,17 +68,16 @@ const getWbiKeys = async (): Promise<EncodedKeys> => {
const getBiliWbi = async (): Promise<string> => {
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;
};