From 9d8866de47ddd4cc78b670e205ca6020e3c009c1 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 19 Jun 2023 17:42:20 +0800 Subject: [PATCH] fix apis --- app/api/apiv1.py | 1 - app/api/endpoints/history.py | 4 ++-- app/api/endpoints/plugin.py | 35 +++++++++++++++++++++++++++++++++++ app/schemas/__init__.py | 1 + 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/api/apiv1.py b/app/api/apiv1.py index 84997941..9cdaadd4 100644 --- a/app/api/apiv1.py +++ b/app/api/apiv1.py @@ -14,6 +14,5 @@ api_router.include_router(media.router, prefix="/media", tags=["media"]) api_router.include_router(search.router, prefix="/search", tags=["search"]) api_router.include_router(douban.router, prefix="/douban", tags=["douban"]) api_router.include_router(tmdb.router, prefix="/tmdb", tags=["tmdb"]) -api_router.include_router(plugin.router, prefix="/plugin", tags=["plugin"]) api_router.include_router(history.router, prefix="/history", tags=["history"]) api_router.include_router(plugin.router, prefix="/plugin", tags=["plugin"]) diff --git a/app/api/endpoints/history.py b/app/api/endpoints/history.py index 863c578a..1b004734 100644 --- a/app/api/endpoints/history.py +++ b/app/api/endpoints/history.py @@ -13,7 +13,7 @@ from app.db.userauth import get_current_active_user router = APIRouter() -@router.get("/download", summary="下载历史记录", response_model=List[schemas.Context]) +@router.get("/download", summary="下载历史记录", response_model=List[schemas.DownloadHistory]) async def download_history(page: int = 1, count: int = 30, db: Session = Depends(get_db), @@ -24,7 +24,7 @@ async def download_history(page: int = 1, return DownloadHistory.list_by_page(db, page, count) -@router.get("/transfer", summary="转移历史记录", response_model=List[schemas.TorrentInfo]) +@router.get("/transfer", summary="转移历史记录", response_model=List[schemas.TransferHistory]) async def transfer_history(title: str = None, page: int = 1, count: int = 30, diff --git a/app/api/endpoints/plugin.py b/app/api/endpoints/plugin.py index e06ac8be..da1e1412 100644 --- a/app/api/endpoints/plugin.py +++ b/app/api/endpoints/plugin.py @@ -46,6 +46,41 @@ async def set_plugin_config(plugin_id: str, conf: dict, return schemas.Response(success=True) +@router.post("/{plugin_id}/install", summary="安装插件", response_model=schemas.Response) +async def install_plugin(plugin_id: str, + _: User = Depends(get_current_active_user)) -> Any: + """ + 安装插件 + """ + # 已安装插件 + install_plugins = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or [] + # 安装插件 + install_plugins.append(plugin_id) + # 保存设置 + SystemConfigOper().set(SystemConfigKey.UserInstalledPlugins, install_plugins) + # 重载插件管理器 + PluginManager().init_config() + return schemas.Response(success=True) + + +@router.delete("/{plugin_id}", summary="卸载插件", response_model=schemas.Response) +async def uninstall_plugin(plugin_id: str, _: User = Depends(get_current_active_user)) -> Any: + """ + 卸载插件 + """ + # 删除已安装信息 + install_plugins = SystemConfigOper().get(SystemConfigKey.UserInstalledPlugins) or [] + for plugin in install_plugins: + if plugin == plugin_id: + install_plugins.remove(plugin) + break + # 保存 + SystemConfigOper().set(SystemConfigKey.UserInstalledPlugins, install_plugins) + # 重载插件管理器 + PluginManager().init_config() + return schemas.Response(success=True) + + # 注册插件API for api in PluginManager().get_plugin_apis(): router.add_api_route(**api) diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py index 86058a17..78c6571e 100644 --- a/app/schemas/__init__.py +++ b/app/schemas/__init__.py @@ -6,3 +6,4 @@ from .subscribe import * from .context import * from .servarr import * from .plugin import * +from .history import *