From ae832e5bb4769f435992fb3ab80b13d0d39aae7b Mon Sep 17 00:00:00 2001 From: Rewrite0 Date: Sun, 13 Aug 2023 14:43:20 +0800 Subject: [PATCH 01/15] feat: status api & ui change --- webui/src/api/program.ts | 5 ++-- webui/src/components/layout/ab-topbar.vue | 5 ++-- webui/src/hooks/useAppInfo.ts | 35 +++++++++++++++++++++++ webui/src/pages/index/log.vue | 14 ++++----- webui/src/store/program.ts | 29 ------------------- webui/types/dts/auto-imports.d.ts | 1 + 6 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 webui/src/hooks/useAppInfo.ts diff --git a/webui/src/api/program.ts b/webui/src/api/program.ts index 9bd7542b..52c2650a 100644 --- a/webui/src/api/program.ts +++ b/webui/src/api/program.ts @@ -31,10 +31,11 @@ export const apiProgram = { * 状态 */ async status() { - const { data } = await axios.get<{ status: 'running' | 'stop' }>( + const { data } = await axios.get<{ status: boolean; version: string }>( 'api/v1/status' ); - return data.status === 'running'; + + return data!; }, /** diff --git a/webui/src/components/layout/ab-topbar.vue b/webui/src/components/layout/ab-topbar.vue index 699ef9eb..7f62bc3d 100644 --- a/webui/src/components/layout/ab-topbar.vue +++ b/webui/src/components/layout/ab-topbar.vue @@ -9,14 +9,13 @@ import { } from '@icon-park/vue-next'; const { t, changeLocale } = useMyI18n(); +const { running, onUpdate, offUpdate } = useAppInfo(); const search = ref(''); const show = ref(false); const showAdd = ref(false); -const { onUpdate, offUpdate, start, pause, shutdown, restart, resetRule } = - useProgramStore(); -const { running } = storeToRefs(useProgramStore()); +const { start, pause, shutdown, restart, resetRule } = useProgramStore(); const items = [ { diff --git a/webui/src/hooks/useAppInfo.ts b/webui/src/hooks/useAppInfo.ts new file mode 100644 index 00000000..6bbba953 --- /dev/null +++ b/webui/src/hooks/useAppInfo.ts @@ -0,0 +1,35 @@ +export const useAppInfo = createSharedComposable(() => { + const { auth } = useAuth(); + const running = ref(false); + const version = ref(''); + + function getStatus() { + const { execute, onResult } = useApi(apiProgram.status); + + onResult((res) => { + running.value = res.status; + version.value = res.version; + }); + + if (auth.value !== '') { + execute(); + } + } + + const { pause: offUpdate, resume: onUpdate } = useIntervalFn( + getStatus, + 3000, + { + immediate: false, + immediateCallback: true, + } + ); + + return { + running, + version, + + onUpdate, + offUpdate, + }; +}); diff --git a/webui/src/pages/index/log.vue b/webui/src/pages/index/log.vue index 58141bb2..878d7c8a 100644 --- a/webui/src/pages/index/log.vue +++ b/webui/src/pages/index/log.vue @@ -1,6 +1,7 @@ + + diff --git a/webui/tsconfig.json b/webui/tsconfig.json index 5bcd753a..71dca94e 100644 --- a/webui/tsconfig.json +++ b/webui/tsconfig.json @@ -16,6 +16,7 @@ "baseUrl": "./", "types": ["vite-plugin-pwa/client"], "paths": { + "~/*": ["./*"], "@/*": ["src/*"], "#/*": ["types/*"] } diff --git a/webui/types/dts/auto-imports.d.ts b/webui/types/dts/auto-imports.d.ts index 723b89f4..d557e4ba 100644 --- a/webui/types/dts/auto-imports.d.ts +++ b/webui/types/dts/auto-imports.d.ts @@ -13,6 +13,7 @@ declare global { const apiLog: typeof import('../../src/api/log')['apiLog'] const apiProgram: typeof import('../../src/api/program')['apiProgram'] const apiRSS: typeof import('../../src/api/rss')['apiRSS'] + const apiSearch: typeof import('../../src/api/search')['apiSearch'] const assert: typeof import('vitest')['assert'] const asyncComputed: typeof import('@vueuse/core')['asyncComputed'] const autoResetRef: typeof import('@vueuse/core')['autoResetRef'] diff --git a/webui/types/dts/router-type.d.ts b/webui/types/dts/router-type.d.ts index ceb699a7..66ba5cf1 100644 --- a/webui/types/dts/router-type.d.ts +++ b/webui/types/dts/router-type.d.ts @@ -46,6 +46,7 @@ declare module 'vue-router/auto/routes' { 'Downloader': RouteRecordInfo<'Downloader', '/downloader', Record, Record>, 'Log': RouteRecordInfo<'Log', '/log', Record, Record>, 'Player': RouteRecordInfo<'Player', '/player', Record, Record>, + 'RSS': RouteRecordInfo<'RSS', '/rss', Record, Record>, 'Login': RouteRecordInfo<'Login', '/login', Record, Record>, } } diff --git a/webui/vite.config.ts b/webui/vite.config.ts index 683181d8..5de8be04 100644 --- a/webui/vite.config.ts +++ b/webui/vite.config.ts @@ -89,6 +89,7 @@ export default defineConfig({ }, resolve: { alias: { + '~': resolve(__dirname, './'), '@': resolve(__dirname, 'src'), '#': resolve(__dirname, 'types'), }, From bb05f40df83bdaa21b8b7e98fad892bd6ef3e9fa Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Sun, 20 Aug 2023 12:20:12 +0800 Subject: [PATCH 06/15] change: webui api accept model. --- backend/src/module/api/program.py | 2 +- backend/src/module/api/response.py | 1 + webui/src/api/bangumi.ts | 15 +++++++-------- webui/src/api/check.ts | 19 ++----------------- webui/src/api/config.ts | 13 +++++++------ webui/src/api/download.ts | 9 +++++---- webui/src/api/log.ts | 6 ++++-- webui/src/api/program.ts | 21 ++++++++++----------- webui/src/store/bangumi.ts | 4 ++-- webui/types/api.ts | 6 ++++++ webui/types/message.ts | 5 +++++ 11 files changed, 50 insertions(+), 51 deletions(-) create mode 100644 webui/types/message.ts diff --git a/backend/src/module/api/program.py b/backend/src/module/api/program.py index c29fa7eb..ded933ff 100644 --- a/backend/src/module/api/program.py +++ b/backend/src/module/api/program.py @@ -83,7 +83,7 @@ async def shutdown_program(current_user=Depends(get_current_user)): # Check status -@router.get("/check/downloader", tags=["check"]) +@router.get("/check/downloader", tags=["check"], response_model=bool) async def check_downloader_status(current_user=Depends(get_current_user)): if not current_user: raise UNAUTHORIZED diff --git a/backend/src/module/api/response.py b/backend/src/module/api/response.py index b4705cc4..00365a7e 100644 --- a/backend/src/module/api/response.py +++ b/backend/src/module/api/response.py @@ -7,6 +7,7 @@ def u_response(response_model: ResponseModel): return JSONResponse( status_code=response_model.status_code, content={ + "status": response_model.status, "msg_en": response_model.msg_en, "msg_zh": response_model.msg_zh, }, diff --git a/webui/src/api/bangumi.ts b/webui/src/api/bangumi.ts index db7b4bd2..a6b5a3ad 100644 --- a/webui/src/api/bangumi.ts +++ b/webui/src/api/bangumi.ts @@ -1,5 +1,6 @@ import type { BangumiRule, BangumiUpdate } from '#/bangumi'; -import type { ApiSuccess } from '#/api'; +import type { UniversalResponse } from '#/message'; +import type { ApiResponse } from '#/api'; export const apiBangumi = { /** @@ -34,7 +35,7 @@ export const apiBangumi = { async updateRule(bangumiId: number, bangumiRule: BangumiRule) { const rule = omit(bangumiRule, ['id']); - const { data } = await axios.patch( + const { data } = await axios.patch< ApiResponse >( `api/v1/bangumi/update/${bangumiId}`, rule ); @@ -58,7 +59,7 @@ export const apiBangumi = { ids = bangumiId; } - const { data } = await axios.delete(url, { + const { data } = await axios.delete< ApiResponse >(url, { data: ids, params: { file, @@ -84,7 +85,7 @@ export const apiBangumi = { ids = bangumiId; } - const { data } = await axios.delete(url, { + const { data } = await axios.delete< ApiResponse >(url, { data: ids, params: { file, @@ -98,7 +99,7 @@ export const apiBangumi = { * @param bangumiId - 需要启用的 bangumi 的 id */ async enableRule(bangumiId: number) { - const { data } = await axios.get( + const { data } = await axios.get< UniversalResponse >( `api/v1/bangumi/enable/${bangumiId}` ); return data; @@ -108,9 +109,7 @@ export const apiBangumi = { * 重置所有 bangumi 数据 */ async resetAll() { - const { data } = await axios.get<{ - message: 'OK'; - }>('api/v1/bangumi/resetAll'); + const { data } = await axios.get< ApiResponse >('api/v1/bangumi/resetAll'); return data; }, }; diff --git a/webui/src/api/check.ts b/webui/src/api/check.ts index 9d3289ef..a59a3a73 100644 --- a/webui/src/api/check.ts +++ b/webui/src/api/check.ts @@ -3,23 +3,8 @@ export const apiCheck = { * 检测下载器 */ async downloader() { - const { data } = await axios.get('api/v1/check/downloader'); + const { data } = await axios.get('api/v1/check/downloader'); return data; }, - /** - * 检测 RSS - */ - async rss() { - const { data } = await axios.get('api/v1/check/rss'); - return data; - }, - - /** - * 检测所有 - */ - async all() { - const { data } = await axios.get('api/v1/check'); - return data; - }, -}; +} \ No newline at end of file diff --git a/webui/src/api/config.ts b/webui/src/api/config.ts index 77e892f4..3e6771f0 100644 --- a/webui/src/api/config.ts +++ b/webui/src/api/config.ts @@ -1,11 +1,12 @@ import type { Config } from '#/config'; +import type { UniversalResponse } from '#/message'; export const apiConfig = { /** * 获取 config 数据 */ async getConfig() { - const { data } = await axios.get('api/v1/getConfig'); + const { data } = await axios.get('api/v1/config/get'); return data; }, @@ -14,10 +15,10 @@ export const apiConfig = { * @param newConfig - 需要更新的 config */ async updateConfig(newConfig: Config) { - const { data } = await axios.post<{ - message: 'Success' | 'Failed to update config'; - }>('api/v1/updateConfig', newConfig); - - return data.message === 'Success'; + const { data } = await axios.patch( + 'api/v1/config/update', + newConfig + ); + return data; }, }; diff --git a/webui/src/api/download.ts b/webui/src/api/download.ts index 52f25310..e12c9834 100644 --- a/webui/src/api/download.ts +++ b/webui/src/api/download.ts @@ -1,4 +1,5 @@ import type { BangumiRule } from '#/bangumi'; +import type { UniversalResponse } from '#/message'; interface Status { status: 'Success'; @@ -30,11 +31,11 @@ export const apiDownload = { * @param bangumiData - Bangumi 数据 */ async collection(bangumiData: BangumiRule) { - const { data } = await axios.post( + const { data } = await axios.post< UniversalResponse >( 'api/v1/download/collection', bangumiData ); - return data.status === 'Success'; + return data; }, /** @@ -42,10 +43,10 @@ export const apiDownload = { * @param bangumiData - Bangumi 数据 */ async subscribe(bangumiData: BangumiRule) { - const { data } = await axios.post( + const { data } = await axios.post< UniversalResponse >( 'api/v1/download/subscribe', bangumiData ); - return data.status === 'Success'; + return data; }, }; diff --git a/webui/src/api/log.ts b/webui/src/api/log.ts index 92e3e33e..98002425 100644 --- a/webui/src/api/log.ts +++ b/webui/src/api/log.ts @@ -1,3 +1,5 @@ +import type { UniversalResponse } from "#/message"; + export const apiLog = { async getLog() { const { data } = await axios.get('api/v1/log'); @@ -5,7 +7,7 @@ export const apiLog = { }, async clearLog() { - const { data } = await axios.get<{ status: 'ok' }>('api/v1/log/clear'); - return data.status === 'ok'; + const { data } = await axios.get('api/v1/log/clear'); + return data; }, }; diff --git a/webui/src/api/program.ts b/webui/src/api/program.ts index 52c2650a..7aff1ae8 100644 --- a/webui/src/api/program.ts +++ b/webui/src/api/program.ts @@ -1,30 +1,29 @@ -interface Success { - status: 'ok'; -} +import type { UniversalResponse } from "#/message"; + export const apiProgram = { /** * 重启 */ async restart() { - const { data } = await axios.get('api/v1/restart'); - return data.status === 'ok'; + const { data } = await axios.get< UniversalResponse >('api/v1/restart'); + return data; }, /** * 启动 */ async start() { - const { data } = await axios.get('api/v1/start'); - return data.status === 'ok'; + const { data } = await axios.get< UniversalResponse >('api/v1/start'); + return data; }, /** * 停止 */ async stop() { - const { data } = await axios.get('api/v1/stop'); - return data.status === 'ok'; + const { data } = await axios.get< UniversalResponse >('api/v1/stop'); + return data; }, /** @@ -42,7 +41,7 @@ export const apiProgram = { * 终止 */ async shutdown() { - const { data } = await axios.get('api/v1/shutdown'); - return data.status === 'ok'; + const { data } = await axios.get< UniversalResponse >('api/v1/shutdown'); + return data; }, }; diff --git a/webui/src/store/bangumi.ts b/webui/src/store/bangumi.ts index a4138310..72f47fe6 100644 --- a/webui/src/store/bangumi.ts +++ b/webui/src/store/bangumi.ts @@ -45,8 +45,8 @@ export const useBangumiStore = defineStore('bangumi', () => { getAll(); } - function actionSuccess({ msg }) { - message.success(msg); + function actionSuccess({ status }) { + message.success(status); refresh(); } onUpdateRuleResult(actionSuccess); diff --git a/webui/types/api.ts b/webui/types/api.ts index 969595b8..1ea2ebe6 100644 --- a/webui/types/api.ts +++ b/webui/types/api.ts @@ -21,3 +21,9 @@ export interface ApiError { export interface ApiSuccess { msg: string; } + +export interface ApiResponse { + status: boolean; + msg_en: string; + msg_zh: string; +} \ No newline at end of file diff --git a/webui/types/message.ts b/webui/types/message.ts new file mode 100644 index 00000000..ea4c516c --- /dev/null +++ b/webui/types/message.ts @@ -0,0 +1,5 @@ +export interface UniversalResponse { + status: boolean; + msg_en: string; + msg_zh: string; +} \ No newline at end of file From a872622b57a957db6e94e1d51808e9436e74ccdb Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Sun, 20 Aug 2023 15:11:16 +0800 Subject: [PATCH 07/15] change: add universal api response model in src. --- backend/src/module/api/program.py | 31 ++++++++++++++++++++----- backend/src/module/api/response.py | 27 ++++++++++++++------- backend/src/module/models/response.py | 1 + webui/src/api/bangumi.ts | 3 +-- webui/src/api/config.ts | 4 ++-- webui/src/api/download.ts | 6 ++--- webui/src/api/log.ts | 4 ++-- webui/src/api/program.ts | 10 ++++---- webui/src/api/rss.ts | 16 +++++++------ webui/src/components/ab-add-bangumi.vue | 20 +++++++++++++++- webui/src/i18n/en.json | 6 ++++- webui/src/i18n/zh-CN.json | 6 ++++- webui/types/message.ts | 5 ---- webui/types/torrent.ts | 7 ++++++ 14 files changed, 103 insertions(+), 43 deletions(-) delete mode 100644 webui/types/message.ts create mode 100644 webui/types/torrent.ts diff --git a/backend/src/module/api/program.py b/backend/src/module/api/program.py index ded933ff..411cab58 100644 --- a/backend/src/module/api/program.py +++ b/backend/src/module/api/program.py @@ -6,6 +6,7 @@ from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import JSONResponse from module.core import Program +from module.models import APIResponse from module.conf import VERSION from module.security.api import get_current_user, UNAUTHORIZED @@ -24,20 +25,29 @@ async def shutdown(): program.stop() -@router.get("/restart") +@router.get("/restart", response_model=APIResponse) async def restart(current_user=Depends(get_current_user)): if not current_user: raise UNAUTHORIZED try: program.restart() - return {"status": "ok"} + return JSONResponse( + status_code=200, + content={"msg_en": "Restart program successfully.", "msg_zh": "重启程序成功。"}, + ) except Exception as e: logger.debug(e) logger.warning("Failed to restart program") - raise HTTPException(status_code=500, detail="Failed to restart program") + raise HTTPException( + status_code=500, + detail={ + "msg_en": "Failed to restart program.", + "msg_zh": "重启程序失败。", + } + ) -@router.get("/start") +@router.get("/start", response_model=APIResponse) async def start(current_user=Depends(get_current_user)): if not current_user: raise UNAUTHORIZED @@ -46,7 +56,13 @@ async def start(current_user=Depends(get_current_user)): except Exception as e: logger.debug(e) logger.warning("Failed to start program") - raise HTTPException(status_code=500, detail="Failed to start program") + raise HTTPException( + status_code=500, + detail={ + "msg_en": "Failed to start program.", + "msg_zh": "启动程序失败。", + } + ) @router.get("/stop") @@ -79,7 +95,10 @@ async def shutdown_program(current_user=Depends(get_current_user)): program.stop() logger.info("Shutting down program...") os.kill(os.getpid(), signal.SIGINT) - return {"status": "ok"} + return JSONResponse( + status_code=200, + content={"msg_en": "Shutdown program successfully.", "msg_zh": "关闭程序成功。"}, + ) # Check status diff --git a/backend/src/module/api/response.py b/backend/src/module/api/response.py index 00365a7e..5e090e52 100644 --- a/backend/src/module/api/response.py +++ b/backend/src/module/api/response.py @@ -1,14 +1,25 @@ from fastapi.responses import JSONResponse +from fastapi.exceptions import HTTPException from module.models.response import ResponseModel def u_response(response_model: ResponseModel): - return JSONResponse( - status_code=response_model.status_code, - content={ - "status": response_model.status, - "msg_en": response_model.msg_en, - "msg_zh": response_model.msg_zh, - }, - ) + if response_model.status: + return JSONResponse( + status_code=response_model.status_code, + content={ + "status": response_model.status, + "msg_en": response_model.msg_en, + "msg_zh": response_model.msg_zh, + }, + ) + else: + raise HTTPException( + status_code=response_model.status_code, + detail={ + "status": response_model.status, + "msg_en": response_model.msg_en, + "msg_zh": response_model.msg_zh, + }, + ) \ No newline at end of file diff --git a/backend/src/module/models/response.py b/backend/src/module/models/response.py index 73079631..9bd35272 100644 --- a/backend/src/module/models/response.py +++ b/backend/src/module/models/response.py @@ -9,5 +9,6 @@ class ResponseModel(BaseModel): class APIResponse(BaseModel): + status: bool = Field(..., example=True) msg_en: str = Field(..., example="Success") msg_zh: str = Field(..., example="成功") \ No newline at end of file diff --git a/webui/src/api/bangumi.ts b/webui/src/api/bangumi.ts index a6b5a3ad..56945a4d 100644 --- a/webui/src/api/bangumi.ts +++ b/webui/src/api/bangumi.ts @@ -1,5 +1,4 @@ import type { BangumiRule, BangumiUpdate } from '#/bangumi'; -import type { UniversalResponse } from '#/message'; import type { ApiResponse } from '#/api'; export const apiBangumi = { @@ -99,7 +98,7 @@ export const apiBangumi = { * @param bangumiId - 需要启用的 bangumi 的 id */ async enableRule(bangumiId: number) { - const { data } = await axios.get< UniversalResponse >( + const { data } = await axios.get< ApiResponse >( `api/v1/bangumi/enable/${bangumiId}` ); return data; diff --git a/webui/src/api/config.ts b/webui/src/api/config.ts index 3e6771f0..da5530bc 100644 --- a/webui/src/api/config.ts +++ b/webui/src/api/config.ts @@ -1,5 +1,5 @@ import type { Config } from '#/config'; -import type { UniversalResponse } from '#/message'; +import type { ApiResponse } from '#/api'; export const apiConfig = { /** @@ -15,7 +15,7 @@ export const apiConfig = { * @param newConfig - 需要更新的 config */ async updateConfig(newConfig: Config) { - const { data } = await axios.patch( + const { data } = await axios.patch( 'api/v1/config/update', newConfig ); diff --git a/webui/src/api/download.ts b/webui/src/api/download.ts index e12c9834..ea0e0a95 100644 --- a/webui/src/api/download.ts +++ b/webui/src/api/download.ts @@ -1,5 +1,5 @@ import type { BangumiRule } from '#/bangumi'; -import type { UniversalResponse } from '#/message'; +import type { ApiResponse } from '#/api'; interface Status { status: 'Success'; @@ -31,7 +31,7 @@ export const apiDownload = { * @param bangumiData - Bangumi 数据 */ async collection(bangumiData: BangumiRule) { - const { data } = await axios.post< UniversalResponse >( + const { data } = await axios.post< ApiResponse >( 'api/v1/download/collection', bangumiData ); @@ -43,7 +43,7 @@ export const apiDownload = { * @param bangumiData - Bangumi 数据 */ async subscribe(bangumiData: BangumiRule) { - const { data } = await axios.post< UniversalResponse >( + const { data } = await axios.post< ApiResponse >( 'api/v1/download/subscribe', bangumiData ); diff --git a/webui/src/api/log.ts b/webui/src/api/log.ts index 98002425..faa3ce2c 100644 --- a/webui/src/api/log.ts +++ b/webui/src/api/log.ts @@ -1,4 +1,4 @@ -import type { UniversalResponse } from "#/message"; +import type { ApiResponse } from "#/api"; export const apiLog = { async getLog() { @@ -7,7 +7,7 @@ export const apiLog = { }, async clearLog() { - const { data } = await axios.get('api/v1/log/clear'); + const { data } = await axios.get('api/v1/log/clear'); return data; }, }; diff --git a/webui/src/api/program.ts b/webui/src/api/program.ts index 7aff1ae8..bcde388e 100644 --- a/webui/src/api/program.ts +++ b/webui/src/api/program.ts @@ -1,4 +1,4 @@ -import type { UniversalResponse } from "#/message"; +import type { ApiResponse } from "#/api"; export const apiProgram = { @@ -6,7 +6,7 @@ export const apiProgram = { * 重启 */ async restart() { - const { data } = await axios.get< UniversalResponse >('api/v1/restart'); + const { data } = await axios.get< ApiResponse >('api/v1/restart'); return data; }, @@ -14,7 +14,7 @@ export const apiProgram = { * 启动 */ async start() { - const { data } = await axios.get< UniversalResponse >('api/v1/start'); + const { data } = await axios.get< ApiResponse >('api/v1/start'); return data; }, @@ -22,7 +22,7 @@ export const apiProgram = { * 停止 */ async stop() { - const { data } = await axios.get< UniversalResponse >('api/v1/stop'); + const { data } = await axios.get< ApiResponse >('api/v1/stop'); return data; }, @@ -41,7 +41,7 @@ export const apiProgram = { * 终止 */ async shutdown() { - const { data } = await axios.get< UniversalResponse >('api/v1/shutdown'); + const { data } = await axios.get< ApiResponse >('api/v1/shutdown'); return data; }, }; diff --git a/webui/src/api/rss.ts b/webui/src/api/rss.ts index a8bdc461..976240d0 100644 --- a/webui/src/api/rss.ts +++ b/webui/src/api/rss.ts @@ -1,4 +1,6 @@ import type { RSS } from '#/rss'; +import type { Torrent } from '#/torrent'; +import type { ApiResponse } from '#/api'; export const apiRSS = { async get() { @@ -7,32 +9,32 @@ export const apiRSS = { }, async add(rss: RSS) { - const { data } = await axios.post('api/v1/rss/add', rss); - return data!; + const { data } = await axios.post('api/v1/rss/add', rss); + return data; }, async delete(rss_id: number) { - const { data } = await axios.delete(`api/v1/rss/delete/${rss_id}`); + const { data } = await axios.delete(`api/v1/rss/delete/${rss_id}`); return data!; }, async update(rss_id: number, rss: RSS) { - const { data } = await axios.patch(`api/v1/rss/update/${rss_id}`, rss); + const { data } = await axios.patch(`api/v1/rss/update/${rss_id}`, rss); return data!; }, async refreshAll() { - const { data } = await axios.get('api/v1/rss/refresh/all'); + const { data } = await axios.get('api/v1/rss/refresh/all'); return data!; }, async refresh(rss_id: number) { - const { data } = await axios.get(`api/v1/rss/refresh/${rss_id}`); + const { data } = await axios.get(`api/v1/rss/refresh/${rss_id}`); return data!; }, async getTorrent(rss_id: number) { - const { data } = await axios.get(`api/v1/rss/torrent/${rss_id}`); + const { data } = await axios.get(`api/v1/rss/torrent/${rss_id}`); return data!; }, }; diff --git a/webui/src/components/ab-add-bangumi.vue b/webui/src/components/ab-add-bangumi.vue index 9a0e57f7..d73959fe 100644 --- a/webui/src/components/ab-add-bangumi.vue +++ b/webui/src/components/ab-add-bangumi.vue @@ -98,8 +98,26 @@ async function subscribe() { :label="$t('topbar.add.rss_link')" type="input" :prop="{ - placeholder: $t('topbar.add.placeholder'), + placeholder: $t('topbar.add.placeholder_link'), }" + > + + + diff --git a/webui/src/i18n/en.json b/webui/src/i18n/en.json index 26a30f7e..961b72a5 100644 --- a/webui/src/i18n/en.json +++ b/webui/src/i18n/en.json @@ -33,7 +33,11 @@ "add": { "title": "Add Bangumi", "rss_link": "RSS Link", - "placeholder": "Please enter the RSS link", + "name": "Name", + "aggregate": "Aggregate RSS", + "parser": "Parser", + "placeholder_link": "Please enter the RSS link", + "placeholder_name": "Optional", "analyse": "Analyse" } }, diff --git a/webui/src/i18n/zh-CN.json b/webui/src/i18n/zh-CN.json index 3b13c481..83b16546 100644 --- a/webui/src/i18n/zh-CN.json +++ b/webui/src/i18n/zh-CN.json @@ -33,7 +33,11 @@ "add": { "title": "添加番剧", "rss_link": "RSS链接", - "placeholder": "请输入RSS链接", + "name": "名称", + "aggregate": "聚合 RSS", + "parser": "解析器", + "placeholder_link": "请输入RSS链接", + "placeholder_name": "可选", "analyse": "分析" } }, diff --git a/webui/types/message.ts b/webui/types/message.ts deleted file mode 100644 index ea4c516c..00000000 --- a/webui/types/message.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface UniversalResponse { - status: boolean; - msg_en: string; - msg_zh: string; -} \ No newline at end of file diff --git a/webui/types/torrent.ts b/webui/types/torrent.ts new file mode 100644 index 00000000..4461727f --- /dev/null +++ b/webui/types/torrent.ts @@ -0,0 +1,7 @@ +export interface Torrent { + id: number; + name: string; + url: string; + homepage: string; + downloaded: boolean; +} \ No newline at end of file From 0714722b081e96e2fca27da598fa8ea5c11f2914 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Sun, 20 Aug 2023 17:13:53 +0800 Subject: [PATCH 08/15] feat: change rss add card, add aggregation rss judgment conditions --- webui/src/components/ab-add-bangumi.vue | 48 +++++++++++++++++++------ webui/src/i18n/en.json | 2 +- webui/src/i18n/zh-CN.json | 6 ++-- webui/types/rss.ts | 9 +++++ 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/webui/src/components/ab-add-bangumi.vue b/webui/src/components/ab-add-bangumi.vue index d73959fe..174905db 100644 --- a/webui/src/components/ab-add-bangumi.vue +++ b/webui/src/components/ab-add-bangumi.vue @@ -1,7 +1,10 @@ diff --git a/webui/types/dts/auto-imports.d.ts b/webui/types/dts/auto-imports.d.ts index d557e4ba..b29e8c41 100644 --- a/webui/types/dts/auto-imports.d.ts +++ b/webui/types/dts/auto-imports.d.ts @@ -234,6 +234,7 @@ declare global { const usePreferredDark: typeof import('@vueuse/core')['usePreferredDark'] const usePreferredLanguages: typeof import('@vueuse/core')['usePreferredLanguages'] const useProgramStore: typeof import('../../src/store/program')['useProgramStore'] + const useRSSStore: typeof import('../../src/store/rss')['useRSSStore'] const useRafFn: typeof import('@vueuse/core')['useRafFn'] const useRefHistory: typeof import('@vueuse/core')['useRefHistory'] const useResizeObserver: typeof import('@vueuse/core')['useResizeObserver'] diff --git a/webui/types/dts/components.d.ts b/webui/types/dts/components.d.ts index 97992e62..7ee76f43 100644 --- a/webui/types/dts/components.d.ts +++ b/webui/types/dts/components.d.ts @@ -21,6 +21,7 @@ declare module '@vue/runtime-core' { AbLabel: typeof import('./../../src/components/ab-label.vue')['default'] AbPageTitle: typeof import('./../../src/components/basic/ab-page-title.vue')['default'] AbPopup: typeof import('./../../src/components/ab-popup.vue')['default'] + AbRssItem: typeof import('./../../src/components/ab-rss-item.vue')['default'] AbRule: typeof import('./../../src/components/ab-rule.vue')['default'] AbSearch: typeof import('./../../src/components/basic/ab-search.vue')['default'] AbSelect: typeof import('./../../src/components/basic/ab-select.vue')['default'] From 02eaafc4fa27cb6fa2a2e25ce15bc97563cb2891 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Mon, 28 Aug 2023 18:24:28 +0800 Subject: [PATCH 12/15] webui: rss i18n update. --- webui/src/i18n/en.json | 9 ++++++++ webui/src/i18n/zh-CN.json | 9 ++++++++ webui/src/pages/index/rss.vue | 41 +++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/webui/src/i18n/en.json b/webui/src/i18n/en.json index 25e8e31a..8d1e260d 100644 --- a/webui/src/i18n/en.json +++ b/webui/src/i18n/en.json @@ -60,6 +60,15 @@ "edit_rule": "Edit Rule" } }, + "rss": { + "title": "RSS Item", + "selectbox": "select", + "name": "Name", + "url": "Url", + "status": "Status", + "delete": "Delete", + "disable": "Disable" + }, "player": { "hit": "Please set up the media player" }, diff --git a/webui/src/i18n/zh-CN.json b/webui/src/i18n/zh-CN.json index b6e9cf29..de47a238 100644 --- a/webui/src/i18n/zh-CN.json +++ b/webui/src/i18n/zh-CN.json @@ -60,6 +60,15 @@ "edit_rule": "编辑规则" } }, + "rss": { + "title": "RSS 条目", + "selectbox": "选择", + "name": "名称", + "url": "Url", + "status": "状态", + "delete": "删除", + "disable": "禁用", + }, "player": { "hit": "请设置媒体播放器地址" }, diff --git a/webui/src/pages/index/rss.vue b/webui/src/pages/index/rss.vue index ccf208f3..e7e7d92e 100644 --- a/webui/src/pages/index/rss.vue +++ b/webui/src/pages/index/rss.vue @@ -1,6 +1,6 @@ From 89fc6693fb4a9d821dc3c84473e8f935b03a8ef7 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Mon, 28 Aug 2023 18:24:50 +0800 Subject: [PATCH 13/15] webui: rss class update --- webui/src/components/ab-rss-item.vue | 27 +++++++++++++++ webui/src/store/rss.ts | 49 ++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 webui/src/components/ab-rss-item.vue create mode 100644 webui/src/store/rss.ts diff --git a/webui/src/components/ab-rss-item.vue b/webui/src/components/ab-rss-item.vue new file mode 100644 index 00000000..5b63caf1 --- /dev/null +++ b/webui/src/components/ab-rss-item.vue @@ -0,0 +1,27 @@ + + + \ No newline at end of file diff --git a/webui/src/store/rss.ts b/webui/src/store/rss.ts new file mode 100644 index 00000000..e6ec86a4 --- /dev/null +++ b/webui/src/store/rss.ts @@ -0,0 +1,49 @@ +import type { RSS } from '#/rss'; +import type { ApiSuccess } from '#/api'; + +export const useRSSStore = defineStore('rss', () => { + const message = useMessage(); + const rss = ref(); + + const { execute: getAll, onResult: onRSSResult } = useApi( + apiRSS.get + ); + const { execute: updateRSS, onResult: onUpdateRSSResult } = useApi( + apiRSS.update + ); + const { execute: deleteRSS, onResult: onDeleteRSSResult } = useApi( + apiRSS.delete + ); + + + onRSSResult((res) => { + function sort(arr: RSS[]) { + return arr.sort((a, b) => b.id - a.id); + } + + const enabled = sort(res.filter((e) => e.enabled)); + const disabled = sort(res.filter((e) => !e.enabled)); + + rss.value = [...enabled, ...disabled]; + }); + + function refresh() { + getAll(); + } + + function actionSuccess(apiRes: ApiSuccess) { + message.success(apiRes.msg_en); + refresh(); + } + + onUpdateRSSResult(actionSuccess); + onDeleteRSSResult(actionSuccess); + + return { + rss, + getAll, + refresh, + updateRSS, + deleteRSS, + }; +}); From ea97218855a66a8bc06e81feb75da99724e4c672 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Mon, 28 Aug 2023 20:18:43 +0800 Subject: [PATCH 14/15] webui: change some component style. Add tag components. --- webui/src/components/basic/ab-add.vue | 20 ++++- webui/src/components/basic/ab-checkbox.vue | 43 +++++----- webui/src/components/basic/ab-tag.stories.ts | 23 ++++++ webui/src/components/basic/ab-tag.vue | 86 ++++++++++++++++++++ webui/types/dts/components.d.ts | 1 + 5 files changed, 149 insertions(+), 24 deletions(-) create mode 100644 webui/src/components/basic/ab-tag.stories.ts create mode 100644 webui/src/components/basic/ab-tag.vue diff --git a/webui/src/components/basic/ab-add.vue b/webui/src/components/basic/ab-add.vue index 51ede24f..588dd532 100644 --- a/webui/src/components/basic/ab-add.vue +++ b/webui/src/components/basic/ab-add.vue @@ -1,10 +1,20 @@