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