mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-06-08 09:10:32 +08:00
fix storage api
This commit is contained in:
@@ -107,6 +107,71 @@ class FileTransferModule(_ModuleBase):
|
||||
)
|
||||
return str(path)
|
||||
|
||||
def list_files(self, fileitem: FileItem) -> Optional[List[FileItem]]:
|
||||
"""
|
||||
浏览文件
|
||||
:param fileitem: 源文件
|
||||
:return: 文件列表
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(fileitem.storage)
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {fileitem.storage} 的文件浏览")
|
||||
return None
|
||||
return storage_oper.list(fileitem)
|
||||
|
||||
def create_folder(self, fileitem: FileItem, name: str) -> Optional[FileItem]:
|
||||
"""
|
||||
创建目录
|
||||
:param fileitem: 源文件
|
||||
:param name: 目录名
|
||||
:return: 创建的目录
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(fileitem.storage)
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {fileitem.storage} 的目录创建")
|
||||
return None
|
||||
return storage_oper.create_folder(fileitem, name)
|
||||
|
||||
def delete_file(self, fileitem: FileItem) -> bool:
|
||||
"""
|
||||
删除文件或目录
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(fileitem.storage)
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {fileitem.storage} 的删除处理")
|
||||
return False
|
||||
return storage_oper.delete(fileitem)
|
||||
|
||||
def rename_file(self, fileitem: FileItem, name: str) -> bool:
|
||||
"""
|
||||
重命名文件或目录
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(fileitem.storage)
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {fileitem.storage} 的重命名处理")
|
||||
return False
|
||||
return storage_oper.rename(fileitem, name)
|
||||
|
||||
def download_file(self, fileitem: FileItem, path: Path) -> bool:
|
||||
"""
|
||||
下载文件
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(fileitem.storage)
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {fileitem.storage} 的下载处理")
|
||||
return False
|
||||
return storage_oper.download(fileitem, path)
|
||||
|
||||
def upload_file(self, fileitem: FileItem, path: Path) -> bool:
|
||||
"""
|
||||
上传文件
|
||||
"""
|
||||
storage_oper = self.__get_storage_oper(fileitem.storage)
|
||||
if not storage_oper:
|
||||
logger.error(f"不支持 {fileitem.storage} 的上传处理")
|
||||
return False
|
||||
return storage_oper.upload(fileitem, path)
|
||||
|
||||
def transfer(self, fileitem: FileItem, meta: MetaBase, mediainfo: MediaInfo,
|
||||
transfer_type: str, target_storage: str = None, target_path: Path = None,
|
||||
episodes_info: List[TmdbEpisode] = None,
|
||||
@@ -11,7 +11,7 @@ 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.filetransfer.storage import StorageBase
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.schemas.types import SystemConfigKey, StorageSchema
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.string import StringUtils
|
||||
@@ -4,7 +4,7 @@ from typing import Optional, List
|
||||
|
||||
from app import schemas
|
||||
from app.log import logger
|
||||
from app.modules.filetransfer.storage import StorageBase
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.system import SystemUtils
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Optional, List
|
||||
|
||||
from app import schemas
|
||||
from app.log import logger
|
||||
from app.modules.filetransfer.storage import StorageBase
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.schemas.types import StorageSchema
|
||||
from app.utils.system import SystemUtils
|
||||
|
||||
@@ -64,14 +64,14 @@ class Rclone(StorageBase):
|
||||
|
||||
def move(self, fileitm: schemas.FileItem, target_file: schemas.FileItem) -> bool:
|
||||
"""
|
||||
移动文件
|
||||
移动文件,target_file格式:rclone:path
|
||||
"""
|
||||
try:
|
||||
retcode = subprocess.run(
|
||||
[
|
||||
'rclone', 'moveto',
|
||||
fileitm.path,
|
||||
f'MP:{target_file}'
|
||||
f'{target_file}'
|
||||
],
|
||||
startupinfo=self.__get_hidden_shell()
|
||||
).returncode
|
||||
@@ -83,14 +83,14 @@ class Rclone(StorageBase):
|
||||
|
||||
def copy(self, fileitm: schemas.FileItem, target_file: Path) -> bool:
|
||||
"""
|
||||
复制文件
|
||||
复制文件,target_file格式:rclone:path
|
||||
"""
|
||||
try:
|
||||
retcode = subprocess.run(
|
||||
[
|
||||
'rclone', 'copyto',
|
||||
fileitm.path,
|
||||
f'MP:{target_file}'
|
||||
f'{target_file}'
|
||||
],
|
||||
startupinfo=self.__get_hidden_shell()
|
||||
).returncode
|
||||
@@ -10,7 +10,7 @@ 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.filetransfer.storage import StorageBase
|
||||
from app.modules.filemanager.storage import StorageBase
|
||||
from app.schemas.types import SystemConfigKey, StorageSchema
|
||||
from app.utils.http import RequestUtils
|
||||
from app.utils.singleton import Singleton
|
||||
@@ -73,7 +73,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
||||
"""
|
||||
self.systemconfig.delete(SystemConfigKey.User115Params)
|
||||
|
||||
def generate_qrcode(self) -> Optional[str]:
|
||||
def generate_qrcode(self) -> Optional[Tuple[dict, str]]:
|
||||
"""
|
||||
生成二维码
|
||||
"""
|
||||
@@ -86,10 +86,12 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
||||
return None
|
||||
# 转换为base64图片格式
|
||||
image_base64 = base64.b64encode(image_bin).decode()
|
||||
return f"data:image/png;base64,{image_base64}"
|
||||
return {
|
||||
"codeContent": f"data:image/jpeg;base64,{image_base64}"
|
||||
}, ""
|
||||
except Exception as e:
|
||||
logger.warn(f"115生成二维码失败:{str(e)}")
|
||||
return None
|
||||
return {}, f"生成二维码失败:{str(e)}"
|
||||
|
||||
def check_login(self) -> Optional[Tuple[dict, str]]:
|
||||
"""
|
||||
Reference in New Issue
Block a user