From 7d6ebbb669d6a0669cbc9b2f51db2998c9ac9519 Mon Sep 17 00:00:00 2001 From: onlylhf <542182964@qq.com> Date: Fri, 25 Oct 2024 17:57:34 +0800 Subject: [PATCH] feat(source): add bilbil (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(source): add bilbil * Delete server/utils/format.ts 热度没有意义,用 icon 好一点 * Update sources.ts * Update bilibili.ts close #5 --------- Co-authored-by: Ou --- server/glob.d.ts | 1 + server/sources/bilibili.ts | 44 ++++++++++++++++++++++++++++++++++++++ shared/sources.ts | 11 ++++++++++ 3 files changed, 56 insertions(+) create mode 100644 server/sources/bilibili.ts diff --git a/server/glob.d.ts b/server/glob.d.ts index 9a6776e..9e966db 100644 --- a/server/glob.d.ts +++ b/server/glob.d.ts @@ -2,6 +2,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' { export const _36kr: typeof import('./sources/_36kr') + export const bilibili: typeof import('./sources/bilibili') export const cankaoxiaoxi: typeof import('./sources/cankaoxiaoxi') export const cls: typeof import('./sources/cls/index') export const coolapk: typeof import('./sources/coolapk/index') diff --git a/server/sources/bilibili.ts b/server/sources/bilibili.ts new file mode 100644 index 0000000..85999fa --- /dev/null +++ b/server/sources/bilibili.ts @@ -0,0 +1,44 @@ +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, +}) diff --git a/shared/sources.ts b/shared/sources.ts index 1760bf3..8ae2b6f 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -214,6 +214,17 @@ export const originSources = { }, }, }, + "bilibili": { + name: "哔哩哔哩", + color: "blue", + home: "https://www.bilibili.com", + sub: { + "hot-search": { + title: "热搜", + type: "hottest", + }, + }, + }, } as const satisfies Record export const sources = genSources()