fix(source): bilibili

This commit is contained in:
Ou 2024-10-26 22:31:18 +08:00
parent c65d818245
commit 77f1a887ea
3 changed files with 16 additions and 3 deletions

View File

@ -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/",
},
})

View File

@ -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: "热搜",

View File

@ -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<T>(arr: T[]) {
return arr[Math.floor(Math.random() * arr.length)]
}