From adb4975573daa1537dd406d705223e35a69e4588 Mon Sep 17 00:00:00 2001 From: the1812 Date: Sun, 28 May 2023 20:13:36 +0800 Subject: [PATCH] Support uid & live search (#677) --- registry/lib/plugins/launch-bar/common.ts | 8 ++++-- .../plugins/launch-bar/number-search/index.ts | 25 ++++++++++++++++--- src/components/launch-bar/ActionItem.vue | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/registry/lib/plugins/launch-bar/common.ts b/registry/lib/plugins/launch-bar/common.ts index 1ecf7917e..3aebaedcd 100644 --- a/registry/lib/plugins/launch-bar/common.ts +++ b/registry/lib/plugins/launch-bar/common.ts @@ -1,3 +1,5 @@ +import type { LaunchBarAction } from '@/components/launch-bar/launch-bar-action' + export const matchInput = (input: string, pattern: RegExp) => { const match = input.match(pattern) if (!match) { @@ -16,13 +18,15 @@ export const matchInput = (input: string, pattern: RegExp) => { export const createLinkAction = (input: { name: string + displayName?: string description?: string indexer: string link: string -}) => { - const { name, description, indexer, link } = input +}): LaunchBarAction => { + const { name, displayName, description, indexer, link } = input return { name: name || indexer, + displayName, icon: 'mdi-open-in-new', indexer, description, diff --git a/registry/lib/plugins/launch-bar/number-search/index.ts b/registry/lib/plugins/launch-bar/number-search/index.ts index 905e91ca9..1a22ab2f1 100644 --- a/registry/lib/plugins/launch-bar/number-search/index.ts +++ b/registry/lib/plugins/launch-bar/number-search/index.ts @@ -15,25 +15,44 @@ export const plugin: PluginMetadata = { if (!match) { return [] } - const [aidJson, cvJson] = await Promise.all([ + const [aidJson, cvJson, uidJson] = await Promise.all([ await getJsonWithCredentials(`https://api.bilibili.com/x/web-interface/view?aid=${id}`), await getJson(`https://api.bilibili.com/x/article/viewinfo?id=${id}`), + await getJson(`https://api.bilibili.com/x/web-interface/card?mid=${id}`), ]) const { title: videoName } = lodash.get(aidJson, 'data', {}) const { title: articleName } = lodash.get(cvJson, 'data', {}) + const { name: userName } = lodash.get(uidJson, 'data.card', {}) + const prefix = (name: string) => (name ? `numberSearchAction.${name}` : name) return [ createLinkAction({ - name: videoName, + name: prefix(videoName), + displayName: videoName, description: '视频跳转', link: `https://www.bilibili.com/av${id}`, indexer, }), createLinkAction({ - name: articleName, + name: prefix(id), + displayName: id, + description: '直播间跳转', + link: `https://live.bilibili.com/${id}`, + indexer, + }), + createLinkAction({ + name: prefix(articleName), + displayName: articleName, description: '专栏跳转', link: `https://www.bilibili.com/read/cv${id}`, indexer, }), + createLinkAction({ + name: prefix(userName), + displayName: userName, + description: '用户跳转', + link: `https://space.bilibili.com/${id}`, + indexer, + }), ] }, }) diff --git a/src/components/launch-bar/ActionItem.vue b/src/components/launch-bar/ActionItem.vue index 7969536bd..b5b4b3d6c 100644 --- a/src/components/launch-bar/ActionItem.vue +++ b/src/components/launch-bar/ActionItem.vue @@ -22,7 +22,7 @@ :name="action.name" >
- {{ action.title || action.name }} + {{ action.displayName || action.name }}
{{ action.description }}