mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
fix filemanager
This commit is contained in:
+13
-9
@@ -15,15 +15,20 @@ class DirectoryHelper:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.systemconfig = SystemConfigOper()
|
self.systemconfig = SystemConfigOper()
|
||||||
|
|
||||||
def get_download_dirs(self) -> List[schemas.TransferDirectoryConf]:
|
def get_dirs(self) -> List[schemas.TransferDirectoryConf]:
|
||||||
"""
|
"""
|
||||||
获取所有下载目录
|
获取所有下载目录
|
||||||
"""
|
"""
|
||||||
dir_confs: List[dict] = self.systemconfig.get(SystemConfigKey.Directories)
|
dir_confs: List[dict] = self.systemconfig.get(SystemConfigKey.Directories)
|
||||||
if not dir_confs:
|
if not dir_confs:
|
||||||
return []
|
return []
|
||||||
dirs = [schemas.TransferDirectoryConf(**d) for d in dir_confs]
|
return [schemas.TransferDirectoryConf(**d) for d in dir_confs]
|
||||||
return sorted([d for d in dirs if d.download_path], key=lambda x: x.priority)
|
|
||||||
|
def get_download_dirs(self) -> List[schemas.TransferDirectoryConf]:
|
||||||
|
"""
|
||||||
|
获取所有下载目录
|
||||||
|
"""
|
||||||
|
return sorted([d for d in self.get_dirs() if d.download_path], key=lambda x: x.priority)
|
||||||
|
|
||||||
def get_local_download_dirs(self) -> List[schemas.TransferDirectoryConf]:
|
def get_local_download_dirs(self) -> List[schemas.TransferDirectoryConf]:
|
||||||
"""
|
"""
|
||||||
@@ -35,11 +40,7 @@ class DirectoryHelper:
|
|||||||
"""
|
"""
|
||||||
获取所有媒体库目录
|
获取所有媒体库目录
|
||||||
"""
|
"""
|
||||||
dir_confs: List[dict] = self.systemconfig.get(SystemConfigKey.Directories)
|
return sorted([d for d in self.get_dirs() if d.library_path], key=lambda x: x.priority)
|
||||||
if not dir_confs:
|
|
||||||
return []
|
|
||||||
dirs = [schemas.TransferDirectoryConf(**d) for d in dir_confs]
|
|
||||||
return sorted([d for d in dirs if d.library_path], key=lambda x: x.priority)
|
|
||||||
|
|
||||||
def get_local_library_dirs(self) -> List[schemas.TransferDirectoryConf]:
|
def get_local_library_dirs(self) -> List[schemas.TransferDirectoryConf]:
|
||||||
"""
|
"""
|
||||||
@@ -61,9 +62,12 @@ class DirectoryHelper:
|
|||||||
media_type = media.type.value
|
media_type = media.type.value
|
||||||
else:
|
else:
|
||||||
media_type = MediaType.UNKNOWN.value
|
media_type = MediaType.UNKNOWN.value
|
||||||
dirs = self.get_download_dirs()
|
dirs = self.get_dirs()
|
||||||
# 按照配置顺序查找
|
# 按照配置顺序查找
|
||||||
for d in dirs:
|
for d in dirs:
|
||||||
|
if not d.download_path or not d.library_path:
|
||||||
|
continue
|
||||||
|
# 下载目录
|
||||||
download_path = Path(d.download_path)
|
download_path = Path(d.download_path)
|
||||||
# 有目录时直接匹配
|
# 有目录时直接匹配
|
||||||
if src_path and download_path != src_path:
|
if src_path and download_path != src_path:
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
from app import schemas
|
||||||
|
from app.db.systemconfig_oper import SystemConfigOper
|
||||||
|
from app.schemas.types import SystemConfigKey
|
||||||
|
|
||||||
|
|
||||||
|
class StorageHelper:
|
||||||
|
"""
|
||||||
|
存储帮助类
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.systemconfig = SystemConfigOper()
|
||||||
|
|
||||||
|
def get_storagies(self) -> List[schemas.StorageConf]:
|
||||||
|
"""
|
||||||
|
获取所有存储设置
|
||||||
|
"""
|
||||||
|
storage_confs: List[dict] = self.systemconfig.get(SystemConfigKey.Storages)
|
||||||
|
if not storage_confs:
|
||||||
|
return []
|
||||||
|
return [schemas.StorageConf(**s) for s in storage_confs]
|
||||||
@@ -51,31 +51,37 @@ class FileManagerModule(_ModuleBase):
|
|||||||
测试模块连接性
|
测试模块连接性
|
||||||
"""
|
"""
|
||||||
directoryhelper = DirectoryHelper()
|
directoryhelper = DirectoryHelper()
|
||||||
# 检查本地下载目录是否存在
|
# 检查目录
|
||||||
download_paths = directoryhelper.get_local_download_dirs()
|
dirs = directoryhelper.get_dirs()
|
||||||
if not download_paths:
|
if not dirs:
|
||||||
return False, "下载目录未设置"
|
return False, "未设置任何目录"
|
||||||
for d_path in download_paths:
|
for d in dirs:
|
||||||
path = d_path.download_path
|
download_path = d.download_path
|
||||||
if not path:
|
if not download_path:
|
||||||
return False, f"下载目录 {d_path.name} 对应路径未设置"
|
return False, f"{d.name} 的下载目录未设置"
|
||||||
download_path = Path(path)
|
if d.storage == "local" and not Path(download_path).exists():
|
||||||
if not download_path.exists():
|
return False, f"{d.name} 的下载目录 {download_path} 不存在"
|
||||||
return False, f"下载目录 {d_path.name} 对应路径 {path} 不存在"
|
library_path = d.library_path
|
||||||
# 检查本地媒体库目录是否存在
|
if not library_path:
|
||||||
libaray_paths = directoryhelper.get_local_library_dirs()
|
return False, f"{d.name} 的媒体库目录未设置"
|
||||||
if not libaray_paths:
|
if d.library_storage == "local" and not Path(library_path).exists():
|
||||||
return False, "媒体库目录未设置"
|
return False, f"{d.name} 的媒体库目录 {library_path} 不存在"
|
||||||
for l_path in libaray_paths:
|
# 检查软硬链接
|
||||||
path = l_path.library_path
|
if d.transfer_type in ["link", "softlink"] \
|
||||||
if not path:
|
and (d.storage != "local" or d.library_storage != "local"):
|
||||||
return False, f"媒体库目录 {l_path.name} 对应路径未设置"
|
return False, f"{d.name} 不是本地存储,不支持软硬链接"
|
||||||
library_path = Path(path)
|
# 检查硬链接
|
||||||
if not library_path.exists():
|
if d.transfer_type == "link" \
|
||||||
return False, f"媒体库目录{l_path.name} 对应的路径 {path} 不存在"
|
and not SystemUtils.is_same_disk(Path(download_path), Path(library_path)):
|
||||||
# TODO 检查硬链接条件
|
return False, f"{d.name} 的下载目录 {download_path} 与媒体库目录 {library_path} 不在同一磁盘,无法硬链接"
|
||||||
|
# 检查网盘
|
||||||
|
if d.storage != "local":
|
||||||
|
storage_oper = self.__get_storage_oper(d.storage)
|
||||||
|
if not storage_oper:
|
||||||
|
return False, f"{d.name} 的存储类型 {d.storage} 不支持"
|
||||||
|
if not storage_oper.check():
|
||||||
|
return False, f"{d.name} 的存储测试不通过"
|
||||||
|
|
||||||
# TODO 检查网盘目录
|
|
||||||
return True, ""
|
return True, ""
|
||||||
|
|
||||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||||
@@ -155,14 +161,14 @@ class FileManagerModule(_ModuleBase):
|
|||||||
return False
|
return False
|
||||||
return storage_oper.download(fileitem, path)
|
return storage_oper.download(fileitem, path)
|
||||||
|
|
||||||
def upload_file(self, fileitem: FileItem, path: Path) -> bool:
|
def upload_file(self, fileitem: FileItem, path: Path) -> Optional[FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
"""
|
"""
|
||||||
storage_oper = self.__get_storage_oper(fileitem.storage)
|
storage_oper = self.__get_storage_oper(fileitem.storage)
|
||||||
if not storage_oper:
|
if not storage_oper:
|
||||||
logger.error(f"不支持 {fileitem.storage} 的上传处理")
|
logger.error(f"不支持 {fileitem.storage} 的上传处理")
|
||||||
return False
|
return None
|
||||||
return storage_oper.upload(fileitem, path)
|
return storage_oper.upload(fileitem, path)
|
||||||
|
|
||||||
def transfer(self, fileitem: FileItem, meta: MetaBase, mediainfo: MediaInfo,
|
def transfer(self, fileitem: FileItem, meta: MetaBase, mediainfo: MediaInfo,
|
||||||
@@ -227,7 +233,7 @@ class FileManagerModule(_ModuleBase):
|
|||||||
need_scrape=need_scrape,
|
need_scrape=need_scrape,
|
||||||
need_rename=need_rename)
|
need_rename=need_rename)
|
||||||
|
|
||||||
def __get_storage_oper(self, _storage: str):
|
def __get_storage_oper(self, _storage: str) -> Optional[StorageBase]:
|
||||||
"""
|
"""
|
||||||
获取存储操作对象
|
获取存储操作对象
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -309,7 +309,13 @@ class AliPan(StorageBase):
|
|||||||
"""
|
"""
|
||||||
检查存储是否可用
|
检查存储是否可用
|
||||||
"""
|
"""
|
||||||
pass
|
params = self.__access_params
|
||||||
|
if not params:
|
||||||
|
return False
|
||||||
|
return True if self.list(schemas.FileItem(
|
||||||
|
fileid="root",
|
||||||
|
drive_id=params.get("resourceDriveId")
|
||||||
|
)) else False
|
||||||
|
|
||||||
def user_info(self) -> dict:
|
def user_info(self) -> dict:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from app.utils.system import SystemUtils
|
|||||||
|
|
||||||
class Rclone(StorageBase):
|
class Rclone(StorageBase):
|
||||||
"""
|
"""
|
||||||
rclone相关操作
|
TODO rclone相关操作
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 存储类型
|
# 存储类型
|
||||||
@@ -53,7 +53,7 @@ class Rclone(StorageBase):
|
|||||||
def rename(self, fileitm: schemas.FileItem, name: str) -> bool:
|
def rename(self, fileitm: schemas.FileItem, name: str) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def download(self, fileitm: schemas.FileItem, path: Path) -> bool:
|
def download(self, fileitm: schemas.FileItem, path: Path):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def upload(self, fileitm: schemas.FileItem, path: Path) -> Optional[schemas.FileItem]:
|
def upload(self, fileitm: schemas.FileItem, path: Path) -> Optional[schemas.FileItem]:
|
||||||
|
|||||||
@@ -153,7 +153,9 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
|||||||
"""
|
"""
|
||||||
检查存储是否可用
|
检查存储是否可用
|
||||||
"""
|
"""
|
||||||
pass
|
return True if self.list(schemas.FileItem(
|
||||||
|
fileid="0"
|
||||||
|
)) else False
|
||||||
|
|
||||||
def list(self, fileitem: schemas.FileItem) -> Optional[List[schemas.FileItem]]:
|
def list(self, fileitem: schemas.FileItem) -> Optional[List[schemas.FileItem]]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -49,6 +49,18 @@ class NotificationConf(BaseModel):
|
|||||||
enabled: Optional[bool] = False
|
enabled: Optional[bool] = False
|
||||||
|
|
||||||
|
|
||||||
|
class StorageConf(BaseModel):
|
||||||
|
"""
|
||||||
|
存储配置
|
||||||
|
"""
|
||||||
|
# 名称
|
||||||
|
name: Optional[str] = None
|
||||||
|
# 类型 local/alipan/u115/rclone
|
||||||
|
type: Optional[str] = None
|
||||||
|
# 配置
|
||||||
|
config: Optional[dict] = {}
|
||||||
|
|
||||||
|
|
||||||
class TransferDirectoryConf(BaseModel):
|
class TransferDirectoryConf(BaseModel):
|
||||||
"""
|
"""
|
||||||
文件整理目录配置
|
文件整理目录配置
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ class SystemConfigKey(Enum):
|
|||||||
Notifications = "Notifications"
|
Notifications = "Notifications"
|
||||||
# 目录配置
|
# 目录配置
|
||||||
Directories = "Directories"
|
Directories = "Directories"
|
||||||
|
# 存储配置
|
||||||
|
Storages = "Storages"
|
||||||
# 阿里云盘认证参数
|
# 阿里云盘认证参数
|
||||||
UserAliyunParams = "UserAliyunParams"
|
UserAliyunParams = "UserAliyunParams"
|
||||||
# 115网盘认证参数
|
# 115网盘认证参数
|
||||||
|
|||||||
Reference in New Issue
Block a user