mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-08 05:08:30 +08:00
fix storage
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
from app import schemas
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
@@ -21,3 +21,32 @@ class StorageHelper:
|
||||
if not storage_confs:
|
||||
return []
|
||||
return [schemas.StorageConf(**s) for s in storage_confs]
|
||||
|
||||
def get_storage(self, storage: str) -> Optional[schemas.StorageConf]:
|
||||
"""
|
||||
获取指定存储配置
|
||||
"""
|
||||
storagies = self.get_storagies()
|
||||
for s in storagies:
|
||||
if s.type == storage:
|
||||
return s
|
||||
return None
|
||||
|
||||
def set_storage(self, storage: str, conf: dict):
|
||||
"""
|
||||
设置存储配置
|
||||
"""
|
||||
storagies = self.get_storagies()
|
||||
if not storagies:
|
||||
storagies = [
|
||||
schemas.StorageConf(
|
||||
type=storage,
|
||||
config=conf
|
||||
)
|
||||
]
|
||||
else:
|
||||
for s in storagies:
|
||||
if s.type == storage:
|
||||
s.config = conf
|
||||
break
|
||||
self.systemconfig.set(SystemConfigKey.Storages, [s.dict() for s in storagies])
|
||||
|
||||
@@ -3,15 +3,31 @@ from pathlib import Path
|
||||
from typing import Optional, List
|
||||
|
||||
from app import schemas
|
||||
from app.helper.storage import StorageHelper
|
||||
|
||||
|
||||
class StorageBase(metaclass=ABCMeta):
|
||||
"""
|
||||
存储基类
|
||||
"""
|
||||
|
||||
schema = None
|
||||
transtype = {}
|
||||
|
||||
def __init__(self):
|
||||
self.storagehelper = StorageHelper()
|
||||
|
||||
def get_config(self) -> Optional[schemas.StorageConf]:
|
||||
"""
|
||||
获取配置
|
||||
"""
|
||||
return self.storagehelper.get_storage(self.schema.value)
|
||||
|
||||
def set_config(self, conf: dict):
|
||||
"""
|
||||
设置配置
|
||||
"""
|
||||
self.storagehelper.set_storage(self.schema.value, conf)
|
||||
|
||||
def support_transtype(self) -> dict:
|
||||
"""
|
||||
支持的整理方式
|
||||
|
||||
@@ -9,10 +9,9 @@ from requests import Response
|
||||
|
||||
from app import schemas
|
||||
from app.core.config import settings
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
from app.log import logger
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.schemas.types import SystemConfigKey, StorageSchema
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.string import StringUtils
|
||||
from app.utils.system import SystemUtils
|
||||
@@ -25,6 +24,7 @@ class AliPan(StorageBase):
|
||||
|
||||
# 存储类型
|
||||
schema = StorageSchema.Alipan
|
||||
|
||||
# 支持的整理方式
|
||||
transtype = {
|
||||
"move": "移动"
|
||||
@@ -65,9 +65,6 @@ class AliPan(StorageBase):
|
||||
# 上传文件完成
|
||||
upload_file_complete_url = "https://api.aliyundrive.com/v2/file/complete"
|
||||
|
||||
def __init__(self):
|
||||
self.systemconfig = SystemConfigOper()
|
||||
|
||||
def __handle_error(self, res: Response, apiname: str, action: bool = True):
|
||||
"""
|
||||
统一处理和打印错误信息
|
||||
@@ -103,7 +100,8 @@ class AliPan(StorageBase):
|
||||
"""
|
||||
获取阿里云盘认证参数并初始化参数格式
|
||||
"""
|
||||
return self.systemconfig.get(SystemConfigKey.UserAliyunParams) or {}
|
||||
conf = self.get_config()
|
||||
return conf.config if conf else {}
|
||||
|
||||
def __update_params(self, params: dict):
|
||||
"""
|
||||
@@ -111,13 +109,13 @@ class AliPan(StorageBase):
|
||||
"""
|
||||
current_params = self.__auth_params
|
||||
current_params.update(params)
|
||||
self.systemconfig.set(SystemConfigKey.UserAliyunParams, current_params)
|
||||
self.set_config(current_params)
|
||||
|
||||
def __clear_params(self):
|
||||
"""
|
||||
清除阿里云盘认证参数
|
||||
"""
|
||||
self.systemconfig.delete(SystemConfigKey.UserAliyunParams)
|
||||
self.set_config({})
|
||||
|
||||
def generate_qrcode(self) -> Optional[Tuple[dict, str]]:
|
||||
"""
|
||||
|
||||
@@ -8,10 +8,9 @@ from py115 import Cloud
|
||||
from py115.types import LoginTarget, QrcodeSession, QrcodeStatus, Credential
|
||||
|
||||
from app import schemas
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
from app.log import logger
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.schemas.types import SystemConfigKey, StorageSchema
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.singleton import Singleton
|
||||
|
||||
@@ -23,6 +22,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
||||
|
||||
# 存储类型
|
||||
schema = StorageSchema.U115
|
||||
|
||||
# 支持的整理方式
|
||||
transtype = {
|
||||
"move": "移动"
|
||||
@@ -31,9 +31,6 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
||||
cloud: Optional[Cloud] = None
|
||||
_session: QrcodeSession = None
|
||||
|
||||
def __init__(self):
|
||||
self.systemconfig = SystemConfigOper()
|
||||
|
||||
def __init_cloud(self) -> bool:
|
||||
"""
|
||||
初始化Cloud
|
||||
@@ -56,22 +53,22 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
||||
"""
|
||||
获取已保存的115认证参数
|
||||
"""
|
||||
cookie_dict = self.systemconfig.get(SystemConfigKey.User115Params)
|
||||
cookie_dict = self.get_config()
|
||||
if not cookie_dict:
|
||||
return None
|
||||
return Credential.from_dict(cookie_dict)
|
||||
return Credential.from_dict(cookie_dict.dict())
|
||||
|
||||
def __save_credentail(self, credential: Credential):
|
||||
"""
|
||||
设置115认证参数
|
||||
"""
|
||||
self.systemconfig.set(SystemConfigKey.User115Params, credential.to_dict())
|
||||
self.set_config(credential.to_dict())
|
||||
|
||||
def __clear_credential(self):
|
||||
"""
|
||||
清除115认证参数
|
||||
"""
|
||||
self.systemconfig.delete(SystemConfigKey.User115Params)
|
||||
self.set_config({})
|
||||
|
||||
def generate_qrcode(self) -> Optional[Tuple[dict, str]]:
|
||||
"""
|
||||
|
||||
@@ -53,8 +53,6 @@ class StorageConf(BaseModel):
|
||||
"""
|
||||
存储配置
|
||||
"""
|
||||
# 名称
|
||||
name: Optional[str] = None
|
||||
# 类型 local/alipan/u115/rclone
|
||||
type: Optional[str] = None
|
||||
# 配置
|
||||
|
||||
@@ -68,10 +68,6 @@ class SystemConfigKey(Enum):
|
||||
Directories = "Directories"
|
||||
# 存储配置
|
||||
Storages = "Storages"
|
||||
# 阿里云盘认证参数
|
||||
UserAliyunParams = "UserAliyunParams"
|
||||
# 115网盘认证参数
|
||||
User115Params = "User115Params"
|
||||
# 搜索站点范围
|
||||
IndexerSites = "IndexerSites"
|
||||
# 订阅站点范围
|
||||
|
||||
Reference in New Issue
Block a user