mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-01 18:01:47 +08:00
fix storage api
This commit is contained in:
@@ -42,6 +42,17 @@ def check(name: str, ck: str = None, t: str = None, _: schemas.TokenPayload = De
|
||||
return schemas.Response(success=False, message=errmsg)
|
||||
|
||||
|
||||
@router.post("/save/{name}", summary="保存存储配置", response_model=schemas.Response)
|
||||
def save(name: str,
|
||||
conf: dict,
|
||||
_: schemas.TokenPayload = Depends(get_current_active_superuser)) -> Any:
|
||||
"""
|
||||
保存存储配置
|
||||
"""
|
||||
StorageChain().save_config(name, conf)
|
||||
return schemas.Response(success=True)
|
||||
|
||||
|
||||
@router.post("/list", summary="所有目录和文件", response_model=List[schemas.FileItem])
|
||||
def list(fileitem: schemas.FileItem,
|
||||
sort: str = 'updated_at',
|
||||
|
||||
@@ -10,6 +10,12 @@ class StorageChain(ChainBase):
|
||||
存储处理链
|
||||
"""
|
||||
|
||||
def save_config(self, storage: str, conf: dict) -> None:
|
||||
"""
|
||||
保存存储配置
|
||||
"""
|
||||
self.run_module("save_config", storage=storage, conf=conf)
|
||||
|
||||
def generate_qrcode(self, storage: str) -> Optional[Tuple[dict, str]]:
|
||||
"""
|
||||
生成二维码
|
||||
|
||||
@@ -15,7 +15,7 @@ from app.helper.message import MessageHelper
|
||||
from app.helper.module import ModuleHelper
|
||||
from app.log import logger
|
||||
from app.modules import _ModuleBase
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.modules.filemanager.storages import StorageBase
|
||||
from app.schemas import TransferInfo, ExistMediaInfo, TmdbEpisode, TransferDirectoryConf, FileItem, StorageUsage
|
||||
from app.schemas.types import MediaType
|
||||
from app.utils.system import SystemUtils
|
||||
@@ -37,7 +37,7 @@ class FileManagerModule(_ModuleBase):
|
||||
|
||||
def init_module(self) -> None:
|
||||
# 加载模块
|
||||
self._storage_schemas = ModuleHelper.load('app.modules.filemanager.storage',
|
||||
self._storage_schemas = ModuleHelper.load('app.modules.filemanager.storages',
|
||||
filter_func=lambda _, obj: hasattr(obj, 'schema') and obj.schema)
|
||||
|
||||
@staticmethod
|
||||
@@ -110,6 +110,16 @@ class FileManagerModule(_ModuleBase):
|
||||
|
||||
pass
|
||||
|
||||
def save_config(self, storage: str, conf: Dict) -> None:
|
||||
"""
|
||||
保存存储配置
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(storage)
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {storage} 的配置保存")
|
||||
return
|
||||
storage_oper.set_config(conf)
|
||||
|
||||
def generate_qrcode(self, storage: str) -> Optional[Dict[str, str]]:
|
||||
"""
|
||||
生成二维码
|
||||
|
||||
@@ -11,7 +11,7 @@ from requests import Response
|
||||
from app import schemas
|
||||
from app.core.config import settings
|
||||
from app.log import logger
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.modules.filemanager.storages import StorageBase
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.string import StringUtils
|
||||
@@ -5,7 +5,7 @@ from typing import Optional, List
|
||||
from app import schemas
|
||||
from app.helper.directory import DirectoryHelper
|
||||
from app.log import logger
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.modules.filemanager.storages import StorageBase
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.system import SystemUtils
|
||||
|
||||
@@ -6,7 +6,7 @@ from typing import Optional, List
|
||||
|
||||
from app import schemas
|
||||
from app.log import logger
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.modules.filemanager.storages import StorageBase
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.string import StringUtils
|
||||
from app.utils.system import SystemUtils
|
||||
@@ -14,7 +14,7 @@ from app.utils.system import SystemUtils
|
||||
|
||||
class Rclone(StorageBase):
|
||||
"""
|
||||
TODO rclone相关操作
|
||||
rclone相关操作
|
||||
"""
|
||||
|
||||
# 存储类型
|
||||
@@ -26,6 +26,20 @@ class Rclone(StorageBase):
|
||||
"copy": "复制"
|
||||
}
|
||||
|
||||
def set_config(self, conf: dict):
|
||||
"""
|
||||
设置配置
|
||||
"""
|
||||
super().set_config(conf)
|
||||
filepath = conf.get("filepath")
|
||||
if not filepath:
|
||||
logger.warn("Rclone保存配置失败:未设置配置文件路径")
|
||||
logger.info(f"Rclone配置写入文件:{filepath}")
|
||||
path = Path(filepath)
|
||||
if not path.parent.exists():
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_bytes(conf.get('content'))
|
||||
|
||||
@staticmethod
|
||||
def __get_hidden_shell():
|
||||
if SystemUtils.is_windows():
|
||||
@@ -9,7 +9,7 @@ from py115.types import LoginTarget, QrcodeSession, QrcodeStatus, Credential
|
||||
|
||||
from app import schemas
|
||||
from app.log import logger
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.modules.filemanager.storages import StorageBase
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.singleton import Singleton
|
||||
@@ -236,6 +236,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
||||
"""
|
||||
获取文件或目录,不存在返回None
|
||||
"""
|
||||
|
||||
def __find_item(_fileitem: schemas.FileItem, _name: str) -> Optional[schemas.FileItem]:
|
||||
"""
|
||||
查找下级目录中匹配名称的目录或文件
|
||||
@@ -380,4 +381,10 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
||||
"""
|
||||
存储使用情况
|
||||
"""
|
||||
pass
|
||||
total, used = self.storage()
|
||||
if total:
|
||||
return schemas.StorageUsage(
|
||||
total=total,
|
||||
available=total - used
|
||||
)
|
||||
return schemas.StorageUsage()
|
||||
Reference in New Issue
Block a user