mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-09 07:26:48 +00:00
fix storage api
This commit is contained in:
@@ -17,23 +17,26 @@ from app.schemas.types import ProgressKey
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/qrcode", summary="生成二维码内容", response_model=schemas.Response)
|
||||
def qrcode(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
@router.get("/qrcode/{name}", summary="生成二维码内容", response_model=schemas.Response)
|
||||
def qrcode(name: str, _: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
生成二维码
|
||||
"""
|
||||
qrcode_data, errmsg = StorageChain().generate_qrcode()
|
||||
qrcode_data, errmsg = StorageChain().generate_qrcode(name)
|
||||
if qrcode_data:
|
||||
return schemas.Response(success=True, data=qrcode_data, message=errmsg)
|
||||
return schemas.Response(success=False)
|
||||
|
||||
|
||||
@router.get("/check", summary="二维码登录确认", response_model=schemas.Response)
|
||||
def check(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
@router.get("/check/{name}", summary="二维码登录确认", response_model=schemas.Response)
|
||||
def check(name: str, ck: str = None, t: str = None, _: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||
"""
|
||||
二维码登录确认
|
||||
"""
|
||||
data, errmsg = StorageChain().check_login()
|
||||
if ck or t:
|
||||
data, errmsg = StorageChain().check_login(name, ck=ck, t=t)
|
||||
else:
|
||||
data, errmsg = StorageChain().check_login(name)
|
||||
if data:
|
||||
return schemas.Response(success=True, data=data)
|
||||
return schemas.Response(success=False, message=errmsg)
|
||||
|
||||
@@ -10,17 +10,17 @@ class StorageChain(ChainBase):
|
||||
存储处理链
|
||||
"""
|
||||
|
||||
def generate_qrcode(self) -> Optional[Tuple[dict, str]]:
|
||||
def generate_qrcode(self, storage: str) -> Optional[Tuple[dict, str]]:
|
||||
"""
|
||||
生成二维码
|
||||
"""
|
||||
return self.run_module("generate_qrcode",)
|
||||
return self.run_module("generate_qrcode", storage=storage)
|
||||
|
||||
def check_login(self) -> Optional[Tuple[dict, str]]:
|
||||
def check_login(self, storage: str, **kwargs) -> Optional[Tuple[dict, str]]:
|
||||
"""
|
||||
登录确认
|
||||
"""
|
||||
return self.run_module("check_login",)
|
||||
return self.run_module("check_login", storage=storage, **kwargs)
|
||||
|
||||
def list_files(self, fileitem: schemas.FileItem) -> Optional[List[schemas.FileItem]]:
|
||||
"""
|
||||
|
||||
@@ -108,6 +108,28 @@ class FileManagerModule(_ModuleBase):
|
||||
)
|
||||
return str(path)
|
||||
|
||||
pass
|
||||
|
||||
def generate_qrcode(self, storage: str) -> Optional[Dict[str, str]]:
|
||||
"""
|
||||
生成二维码
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(storage, "generate_qrcode")
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {storage} 的二维码生成")
|
||||
return None
|
||||
return storage_oper.generate_qrcode()
|
||||
|
||||
def check_login(self, storage: str, **kwargs) -> Optional[Dict[str, str]]:
|
||||
"""
|
||||
登录确认
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(storage, "check_login")
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {storage} 的登录确认")
|
||||
return None
|
||||
return storage_oper.check_login(**kwargs)
|
||||
|
||||
def list_files(self, fileitem: FileItem) -> Optional[List[FileItem]]:
|
||||
"""
|
||||
浏览文件
|
||||
@@ -269,12 +291,14 @@ class FileManagerModule(_ModuleBase):
|
||||
need_scrape=need_scrape,
|
||||
need_rename=need_rename)
|
||||
|
||||
def __get_storage_oper(self, _storage: str) -> Optional[StorageBase]:
|
||||
def __get_storage_oper(self, _storage: str, _func: str = None) -> Optional[StorageBase]:
|
||||
"""
|
||||
获取存储操作对象
|
||||
"""
|
||||
for storage_schema in self._storage_schemas:
|
||||
if storage_schema.schema and storage_schema.schema.value == _storage:
|
||||
if storage_schema.schema \
|
||||
and storage_schema.schema.value == _storage \
|
||||
and (not _func or hasattr(storage_schema, _func)):
|
||||
return storage_schema()
|
||||
return None
|
||||
|
||||
|
||||
@@ -16,6 +16,12 @@ class StorageBase(metaclass=ABCMeta):
|
||||
def __init__(self):
|
||||
self.storagehelper = StorageHelper()
|
||||
|
||||
def generate_qrcode(self, *args, **kwargs) -> Optional[Dict[str, str]]:
|
||||
pass
|
||||
|
||||
def check_login(self, *args, **kwargs) -> Optional[Dict[str, str]]:
|
||||
pass
|
||||
|
||||
def get_config(self) -> Optional[schemas.StorageConf]:
|
||||
"""
|
||||
获取配置
|
||||
@@ -46,7 +52,7 @@ class StorageBase(metaclass=ABCMeta):
|
||||
检查存储是否可用
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def list(self, fileitm: schemas.FileItem) -> Optional[List[schemas.FileItem]]:
|
||||
"""
|
||||
@@ -102,7 +108,7 @@ class StorageBase(metaclass=ABCMeta):
|
||||
上传文件
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def detail(self, fileitm: schemas.FileItem) -> Optional[schemas.FileItem]:
|
||||
"""
|
||||
@@ -168,4 +174,3 @@ class StorageBase(metaclass=ABCMeta):
|
||||
__snapshot_file(fileitem)
|
||||
|
||||
return files_info
|
||||
|
||||
@@ -24,7 +24,7 @@ class Slack:
|
||||
_ds_url = f"http://127.0.0.1:{settings.PORT}/api/v1/message?token={settings.API_TOKEN}"
|
||||
_channel = ""
|
||||
|
||||
def __init__(self, oauth_token: str, app_token: str, channel: str = "", **kwargs):
|
||||
def __init__(self, oauth_token: str = None, app_token: str = None, channel: str = "", **kwargs):
|
||||
|
||||
if not oauth_token or not app_token:
|
||||
logger.error("Slack 配置不完整!")
|
||||
|
||||
@@ -14,7 +14,7 @@ lock = Lock()
|
||||
|
||||
|
||||
class SynologyChat:
|
||||
def __init__(self, webhook: str, token: str, **kwargs):
|
||||
def __init__(self, webhook: str = None, token: str = None, **kwargs):
|
||||
if not webhook or not token:
|
||||
logger.error("SynologyChat配置不完整!")
|
||||
return
|
||||
|
||||
@@ -24,7 +24,7 @@ class Telegram:
|
||||
_event = Event()
|
||||
_bot: telebot.TeleBot = None
|
||||
|
||||
def __init__(self, token: str, chat_id: str, **kwargs):
|
||||
def __init__(self, token: str = None, chat_id: str = None, **kwargs):
|
||||
"""
|
||||
初始化参数
|
||||
"""
|
||||
|
||||
@@ -22,7 +22,7 @@ class VoceChat:
|
||||
# 请求对象
|
||||
_client = None
|
||||
|
||||
def __init__(self, host: str, apikey: str, channel_id: str, **kwargs):
|
||||
def __init__(self, host: str = None, apikey: str = None, channel_id: str = None, **kwargs):
|
||||
"""
|
||||
初始化
|
||||
"""
|
||||
|
||||
@@ -37,7 +37,8 @@ class WeChat:
|
||||
# 企业微信创新菜单URL
|
||||
_create_menu_url = "/cgi-bin/menu/create?access_token=%s&agentid=%s"
|
||||
|
||||
def __init__(self, corpid: str, appsecret: str, appid: str, proxy: str = None, **kwargs):
|
||||
def __init__(self, corpid: str = None, appsecret: str = None, appid: str = None,
|
||||
proxy: str = None, **kwargs):
|
||||
"""
|
||||
初始化
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user