newsnow/server/sources/bilibili.ts
onlylhf 7d6ebbb669
feat(source): add bilbil (#4)
* feat(source): add bilbil

* Delete server/utils/format.ts

热度没有意义,用 icon 好一点

* Update sources.ts

* Update bilibili.ts

close #5 
---------

Co-authored-by: Ou <orongxing@gmail.com>
2024-10-25 17:57:34 +08:00

45 lines
1.0 KiB
TypeScript

interface Res {
code: number
message: string
ttl: number
data: {
trending: {
title: string
trackid: string
list: {
keyword: string
show_name: string
icon: string
uri: string
goto: string
heat_score: number
}[]
}
}
}
const hotSearch = defineSource(async () => {
const url = "https://api.bilibili.com/x/web-interface/wbi/search/square?limit=30"
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"
},
})
return res.data.trending.list.map(k => ({
id: k.keyword,
title: k.show_name,
url: `https://search.bilibili.com/all?keyword=${encodeURIComponent(k.keyword)}`,
extra: {
icon: k.icon && `/api/proxy?img=${encodeURIComponent(k.icon)}`,
},
}))
})
export default defineSource({
"bilibili": hotSearch,
"bilibili-hot-search": hotSearch,
})