diff --git a/server/sources/bilibili.ts b/server/sources/bilibili.ts index 85999fa..6aa2bfe 100644 --- a/server/sources/bilibili.ts +++ b/server/sources/bilibili.ts @@ -20,11 +20,12 @@ interface Res { const hotSearch = defineSource(async () => { const url = "https://api.bilibili.com/x/web-interface/wbi/search/square?limit=30" - + const cookie = (await $fetch.raw(`https://bilibili.tv`)).headers.getSetCookie() const res: Res = await $fetch(url, { headers: { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", - // "Cookie": "your_cookie_here" + "cookie": cookie[0].replace(/.tv/g, ".com"), + "referer": "https://www.bilibili.com/", }, }) diff --git a/shared/sources.ts b/shared/sources.ts index 3fbb11b..48f2a23 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -241,7 +241,7 @@ export const originSources = { color: "blue", home: "https://www.bilibili.com", // cloudflare pages cannot access - disable: true, + // disable: true, sub: { "hot-search": { title: "热搜", diff --git a/shared/utils.ts b/shared/utils.ts index 27aa23f..ced5d9e 100644 --- a/shared/utils.ts +++ b/shared/utils.ts @@ -26,3 +26,15 @@ export function relativeTime(timestamp: string | number) { export function delay(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)) } + +export function randomUUID() { + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { + const r = (Math.random() * 16) | 0 + const v = c === "x" ? r : (r & 0x3) | 0x8 + return v.toString(16) + }) +} + +export function randomItem(arr: T[]) { + return arr[Math.floor(Math.random() * arr.length)] +}