fix storage api

This commit is contained in:
jxxghp
2024-08-16 11:30:31 +08:00
parent 61e4e63a6a
commit 8485d4ec30
8 changed files with 56 additions and 8 deletions

View File

@@ -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',

View File

@@ -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]]:
"""
生成二维码

View File

@@ -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]]:
"""
生成二维码

View File

@@ -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

View File

@@ -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

View File

@@ -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():

View File

@@ -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()