mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-04-27 04:02:32 +08:00
fix #3116
This commit is contained in:
@@ -57,13 +57,14 @@ class StorageChain(ChainBase):
|
|||||||
"""
|
"""
|
||||||
return self.run_module("download_file", fileitem=fileitem, path=path)
|
return self.run_module("download_file", fileitem=fileitem, path=path)
|
||||||
|
|
||||||
def upload_file(self, fileitem: schemas.FileItem, path: Path) -> Optional[bool]:
|
def upload_file(self, fileitem: schemas.FileItem, path: Path, new_name: str = None) -> Optional[bool]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
:param fileitem: 保存目录项
|
:param fileitem: 保存目录项
|
||||||
:param path: 本地文件路径
|
:param path: 本地文件路径
|
||||||
|
:param new_name: 新文件名
|
||||||
"""
|
"""
|
||||||
return self.run_module("upload_file", fileitem=fileitem, path=path)
|
return self.run_module("upload_file", fileitem=fileitem, path=path, new_name=new_name)
|
||||||
|
|
||||||
def delete_file(self, fileitem: schemas.FileItem) -> Optional[bool]:
|
def delete_file(self, fileitem: schemas.FileItem) -> Optional[bool]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ class FileManagerModule(_ModuleBase):
|
|||||||
return None
|
return None
|
||||||
return storage_oper.download(fileitem, path=path)
|
return storage_oper.download(fileitem, path=path)
|
||||||
|
|
||||||
def upload_file(self, fileitem: FileItem, path: Path) -> Optional[FileItem]:
|
def upload_file(self, fileitem: FileItem, path: Path, new_name: str = None) -> Optional[FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
"""
|
"""
|
||||||
@@ -276,7 +276,7 @@ class FileManagerModule(_ModuleBase):
|
|||||||
if not storage_oper:
|
if not storage_oper:
|
||||||
logger.error(f"不支持 {fileitem.storage} 的上传处理")
|
logger.error(f"不支持 {fileitem.storage} 的上传处理")
|
||||||
return None
|
return None
|
||||||
return storage_oper.upload(fileitem, path)
|
return storage_oper.upload(fileitem, path, new_name)
|
||||||
|
|
||||||
def get_file_item(self, storage: str, path: Path) -> Optional[FileItem]:
|
def get_file_item(self, storage: str, path: Path) -> Optional[FileItem]:
|
||||||
"""
|
"""
|
||||||
@@ -487,13 +487,8 @@ class FileManagerModule(_ModuleBase):
|
|||||||
target_fileitem = target_oper.get_folder(target_file.parent)
|
target_fileitem = target_oper.get_folder(target_file.parent)
|
||||||
if target_fileitem:
|
if target_fileitem:
|
||||||
# 上传文件
|
# 上传文件
|
||||||
new_item = target_oper.upload(target_fileitem, filepath)
|
new_item = target_oper.upload(target_fileitem, filepath, target_file.name)
|
||||||
if new_item:
|
if new_item:
|
||||||
# 重命名为目标文件名
|
|
||||||
if new_item.name != target_file.name:
|
|
||||||
if target_oper.rename(new_item, target_file.name):
|
|
||||||
new_item.name = target_file.name
|
|
||||||
new_item.path = str(Path(new_item.path).parent / target_file.name)
|
|
||||||
return new_item, ""
|
return new_item, ""
|
||||||
else:
|
else:
|
||||||
return None, f"{fileitem.path} 上传 {target_storage} 失败"
|
return None, f"{fileitem.path} 上传 {target_storage} 失败"
|
||||||
@@ -505,13 +500,8 @@ class FileManagerModule(_ModuleBase):
|
|||||||
target_fileitem = target_oper.get_folder(target_file.parent)
|
target_fileitem = target_oper.get_folder(target_file.parent)
|
||||||
if target_fileitem:
|
if target_fileitem:
|
||||||
# 上传文件
|
# 上传文件
|
||||||
new_item = target_oper.upload(target_fileitem, filepath)
|
new_item = target_oper.upload(target_fileitem, filepath, target_file.name)
|
||||||
if new_item:
|
if new_item:
|
||||||
# 重命名为目标文件名
|
|
||||||
if new_item.name != target_file.name:
|
|
||||||
if target_oper.rename(new_item, target_file.name):
|
|
||||||
new_item.name = target_file.name
|
|
||||||
new_item.path = str(Path(new_item.path).parent / target_file.name)
|
|
||||||
# 删除源文件
|
# 删除源文件
|
||||||
source_oper.delete(fileitem)
|
source_oper.delete(fileitem)
|
||||||
return new_item, ""
|
return new_item, ""
|
||||||
|
|||||||
@@ -119,11 +119,12 @@ class StorageBase(metaclass=ABCMeta):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def upload(self, fileitem: schemas.FileItem, path: Path) -> Optional[schemas.FileItem]:
|
def upload(self, fileitem: schemas.FileItem, path: Path, new_name: str = None) -> Optional[schemas.FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
:param fileitem: 上传目录项
|
:param fileitem: 上传目录项
|
||||||
:param path: 本地文件路径
|
:param path: 本地文件路径
|
||||||
|
:param new_name: 上传后文件名
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ class AliPan(StorageBase):
|
|||||||
return Path(local_path)
|
return Path(local_path)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def upload(self, fileitem: schemas.FileItem, path: Path) -> Optional[schemas.FileItem]:
|
def upload(self, fileitem: schemas.FileItem, path: Path, new_name: str = None) -> Optional[schemas.FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件,并标记完成
|
上传文件,并标记完成
|
||||||
"""
|
"""
|
||||||
@@ -361,7 +361,7 @@ class AliPan(StorageBase):
|
|||||||
return None
|
return None
|
||||||
# 上传文件
|
# 上传文件
|
||||||
result = self.aligo.upload_file(file_path=str(path), parent_file_id=fileitem.fileid,
|
result = self.aligo.upload_file(file_path=str(path), parent_file_id=fileitem.fileid,
|
||||||
drive_id=fileitem.drive_id, name=path.name,
|
drive_id=fileitem.drive_id, name=new_name or path.name,
|
||||||
check_name_mode="refuse")
|
check_name_mode="refuse")
|
||||||
if result:
|
if result:
|
||||||
item = self.aligo.get_file(file_id=result.file_id, drive_id=result.drive_id)
|
item = self.aligo.get_file(file_id=result.file_id, drive_id=result.drive_id)
|
||||||
|
|||||||
@@ -534,12 +534,13 @@ class Alist(StorageBase):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def upload(
|
def upload(
|
||||||
self, fileitem: schemas.FileItem, path: Path, task: bool = False
|
self, fileitem: schemas.FileItem, path: Path, new_name: str = None, task: bool = False
|
||||||
) -> Optional[schemas.FileItem]:
|
) -> Optional[schemas.FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
:param fileitem: 上传目录项
|
:param fileitem: 上传目录项
|
||||||
:param path: 本地文件路径
|
:param path: 本地文件路径
|
||||||
|
:param new_name: 上传后文件名
|
||||||
:param task: 是否为任务,默认为False避免未完成上传时对文件进行操作
|
:param task: 是否为任务,默认为False避免未完成上传时对文件进行操作
|
||||||
"""
|
"""
|
||||||
encoded_path = UrlUtils.quote(fileitem.path)
|
encoded_path = UrlUtils.quote(fileitem.path)
|
||||||
@@ -557,7 +558,11 @@ class Alist(StorageBase):
|
|||||||
logging.warning(f"请求上传文件 {path} 失败,状态码:{resp.status_code}")
|
logging.warning(f"请求上传文件 {path} 失败,状态码:{resp.status_code}")
|
||||||
return
|
return
|
||||||
|
|
||||||
return fileitem
|
if new_name and new_name != path.name:
|
||||||
|
if self.rename(fileitem, new_name):
|
||||||
|
return self.get_item(Path(fileitem.path).parent / new_name)
|
||||||
|
|
||||||
|
return self.get_item(Path(fileitem.path) / path.name)
|
||||||
|
|
||||||
def detail(self, fileitem: schemas.FileItem) -> Optional[schemas.FileItem]:
|
def detail(self, fileitem: schemas.FileItem) -> Optional[schemas.FileItem]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -183,12 +183,12 @@ class LocalStorage(StorageBase):
|
|||||||
"""
|
"""
|
||||||
return Path(fileitem.path)
|
return Path(fileitem.path)
|
||||||
|
|
||||||
def upload(self, fileitem: schemas.FileItem, path: Path) -> Optional[schemas.FileItem]:
|
def upload(self, fileitem: schemas.FileItem, path: Path, new_name: str = None) -> Optional[schemas.FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
"""
|
"""
|
||||||
dir_path = Path(fileitem.path)
|
dir_path = Path(fileitem.path)
|
||||||
target_path = dir_path / path.name
|
target_path = dir_path / (new_name or path.name)
|
||||||
code, message = SystemUtils.move(path, target_path)
|
code, message = SystemUtils.move(path, target_path)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
logger.error(f"移动文件失败:{message}")
|
logger.error(f"移动文件失败:{message}")
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ class Rclone(StorageBase):
|
|||||||
logger.error(f"rclone复制文件失败:{err}")
|
logger.error(f"rclone复制文件失败:{err}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def upload(self, fileitem: schemas.FileItem, path: Path) -> Optional[schemas.FileItem]:
|
def upload(self, fileitem: schemas.FileItem, path: Path, new_name: str = None) -> Optional[schemas.FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
"""
|
"""
|
||||||
@@ -269,7 +269,7 @@ class Rclone(StorageBase):
|
|||||||
[
|
[
|
||||||
'rclone', 'copyto',
|
'rclone', 'copyto',
|
||||||
str(path),
|
str(path),
|
||||||
f'MP:{Path(fileitem.path) / path.name}'
|
f'MP:{Path(fileitem.path) / (new_name or path.name)}'
|
||||||
],
|
],
|
||||||
startupinfo=self.__get_hidden_shell()
|
startupinfo=self.__get_hidden_shell()
|
||||||
).returncode
|
).returncode
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
|||||||
logger.error(f"115下载失败:{str(e)}")
|
logger.error(f"115下载失败:{str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def upload(self, fileitem: schemas.FileItem, path: Path) -> Optional[schemas.FileItem]:
|
def upload(self, fileitem: schemas.FileItem, path: Path, new_name: str = None) -> Optional[schemas.FileItem]:
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
"""
|
"""
|
||||||
@@ -359,7 +359,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
|||||||
if result:
|
if result:
|
||||||
result_data = result.get('data')
|
result_data = result.get('data')
|
||||||
logger.info(f"115上传文件成功:{result_data.get('file_name')}")
|
logger.info(f"115上传文件成功:{result_data.get('file_name')}")
|
||||||
return schemas.FileItem(
|
item = schemas.FileItem(
|
||||||
storage=self.schema.value,
|
storage=self.schema.value,
|
||||||
fileid=result_data.get('file_id'),
|
fileid=result_data.get('file_id'),
|
||||||
parent_fileid=fileitem.fileid,
|
parent_fileid=fileitem.fileid,
|
||||||
@@ -371,6 +371,13 @@ class U115Pan(StorageBase, metaclass=Singleton):
|
|||||||
extension=Path(result_data.get('file_name')).suffix[1:],
|
extension=Path(result_data.get('file_name')).suffix[1:],
|
||||||
pickcode=result_data.get('pickcode')
|
pickcode=result_data.get('pickcode')
|
||||||
)
|
)
|
||||||
|
if new_name and new_name != item.name:
|
||||||
|
if self.rename(item, new_name):
|
||||||
|
item.name = new_name
|
||||||
|
item.basename = Path(new_name).stem
|
||||||
|
item.path = f"{fileitem.path}{new_name}"
|
||||||
|
item.extension = Path(new_name).suffix[1:]
|
||||||
|
return item
|
||||||
else:
|
else:
|
||||||
logger.warn(f"115上传文件失败:{por.resp.response.text}")
|
logger.warn(f"115上传文件失败:{por.resp.response.text}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user