mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
🐞 fix: Fixed type errors
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user