From e5a81efad54214262854ba952b1862638096e83e Mon Sep 17 00:00:00 2001 From: Rewrite0 Date: Thu, 10 Aug 2023 09:19:35 +0800 Subject: [PATCH 1/8] feat: clean types --- webui/src/api/bangumi.ts | 2 +- webui/types/bangumi.ts | 21 --------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/webui/src/api/bangumi.ts b/webui/src/api/bangumi.ts index 07432309..06c27c52 100644 --- a/webui/src/api/bangumi.ts +++ b/webui/src/api/bangumi.ts @@ -1,4 +1,4 @@ -import type { BangumiRule, BangumiUpdate } from '#/bangumi'; +import type { BangumiRule } from '#/bangumi'; import type { ApiSuccess } from '#/api'; export const apiBangumi = { diff --git a/webui/types/bangumi.ts b/webui/types/bangumi.ts index 17c56924..eeed433d 100644 --- a/webui/types/bangumi.ts +++ b/webui/types/bangumi.ts @@ -19,24 +19,3 @@ export interface BangumiRule { title_raw: string; year: string | null; } - -export interface BangumiUpdate { - added: boolean; - deleted: boolean; - dpi: string; - eps_collect: boolean; - filter: string; - group_name: string; - official_title: string; - offset: number; - poster_link: string | null; - rss_link: string; - rule_name: string; - save_path: string; - season: number; - season_raw: string; - source: string | null; - subtitle: string; - title_raw: string; - year: string | null; -} From d68c8b1ac4ce56de2e66842d2b3aafeb3e2be7cb Mon Sep 17 00:00:00 2001 From: Rewrite0 Date: Thu, 10 Aug 2023 09:21:12 +0800 Subject: [PATCH 2/8] fix: fix eslint dependencies error --- webui/.npmrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webui/.npmrc b/webui/.npmrc index 13e14bcc..dbed7938 100644 --- a/webui/.npmrc +++ b/webui/.npmrc @@ -1 +1,3 @@ public-hoist-pattern[]=@vue/runtime-core +public-hoist-pattern[]=*eslint* +public-hoist-pattern[]=*prettier* From 34a065f05ed8c33687b30028518f8b2291312b1b Mon Sep 17 00:00:00 2001 From: Rewrite0 Date: Thu, 10 Aug 2023 10:13:06 +0800 Subject: [PATCH 3/8] refactor: analysis fn --- webui/src/api/download.ts | 32 +++++++-------------- webui/src/components/ab-add-bangumi.vue | 38 ++++++++++++------------- webui/src/hooks/useApi.ts | 3 ++ 3 files changed, 33 insertions(+), 40 deletions(-) diff --git a/webui/src/api/download.ts b/webui/src/api/download.ts index 51b7028b..52f25310 100644 --- a/webui/src/api/download.ts +++ b/webui/src/api/download.ts @@ -4,35 +4,25 @@ interface Status { status: 'Success'; } -interface AnalysisError { - status: 'Failed to parse link'; -} - export const apiDownload = { /** * 解析 RSS 链接 * @param rss_link - RSS 链接 */ async analysis(rss_link: string) { - const fetchResult = createEventHook(); - const fetchError = createEventHook(); - - axios - .post('api/v1/download/analysis', { + const { data } = await axios.post( + 'api/v1/download/analysis', + { rss_link, - }) - .then(({ data }) => { - if (data.status) { - fetchError.trigger(data as AnalysisError); - } else { - fetchResult.trigger(data as BangumiRule); - } - }); + } + ); - return { - onResult: fetchResult.on, - onError: fetchError.on, - }; + // 解析失败抛出错误 + if (data.status) { + throw data; + } + + return data; }, /** diff --git a/webui/src/components/ab-add-bangumi.vue b/webui/src/components/ab-add-bangumi.vue index 77a73ebb..cd265196 100644 --- a/webui/src/components/ab-add-bangumi.vue +++ b/webui/src/components/ab-add-bangumi.vue @@ -47,28 +47,24 @@ watch(show, (val) => { } }); -async function analyser() { +async function analysisRss() { if (rss.value === '') { message.error('Please enter the RSS link!'); } else { - try { - analysis.loading = true; - const { onError, onResult } = await apiDownload.analysis(rss.value); - onResult((data) => { - rule.value = data; - analysis.loading = false; - analysis.next = true; - console.log('rule', data); - }); + analysis.loading = true; - onError((err) => { - message.error(err.status); - analysis.loading = false; - console.log('error', err); - }); + try { + const data = await apiDownload.analysis(rss.value); + rule.value = data; + analysis.next = true; + console.log('rule', data); } catch (error) { - message.error('Failed to analyser!'); + const err = error as { status: string }; + message.error(err.status); + console.log('error', err); } + + analysis.loading = false; } } @@ -90,6 +86,7 @@ async function collect() { } } } + async function subscribe() { if (rule.value) { try { @@ -124,9 +121,12 @@ async function subscribe() { >
- {{ - $t('topbar.add.analyse') - }} + {{ $t('topbar.add.analyse') }}
diff --git a/webui/src/hooks/useApi.ts b/webui/src/hooks/useApi.ts index ca099d74..ad2bfe78 100644 --- a/webui/src/hooks/useApi.ts +++ b/webui/src/hooks/useApi.ts @@ -20,6 +20,7 @@ export function useApi< const fetchResult = createEventHook(); const fetchError = createEventHook(); + const fetchFinally = createEventHook(); const message = useMessage(); function execute(...params: Parameters) { @@ -43,6 +44,7 @@ export function useApi< }) .finally(() => { isLoading.value = false; + fetchFinally.trigger(''); }); } @@ -53,5 +55,6 @@ export function useApi< execute, onResult: fetchResult.on, onError: fetchError.on, + onFinally: fetchFinally.on, }; } From 6339b26d99923951660a983bdd7aa2bd552dd0d9 Mon Sep 17 00:00:00 2001 From: Rewrite0 Date: Thu, 10 Aug 2023 10:16:46 +0800 Subject: [PATCH 4/8] refactor: rule template --- webui/src/components/ab-add-bangumi.vue | 23 ++--------------------- webui/src/pages/index/bangumi.vue | 23 ++--------------------- webui/types/bangumi.ts | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 42 deletions(-) diff --git a/webui/src/components/ab-add-bangumi.vue b/webui/src/components/ab-add-bangumi.vue index cd265196..31b1c506 100644 --- a/webui/src/components/ab-add-bangumi.vue +++ b/webui/src/components/ab-add-bangumi.vue @@ -1,33 +1,14 @@