This commit is contained in:
jxxghp
2024-07-03 07:10:46 +08:00
parent 03068778bc
commit b6800c7fda
7 changed files with 89 additions and 71 deletions

View File

@@ -1,6 +1,6 @@
from abc import ABCMeta, abstractmethod
from pathlib import Path
from typing import Optional, List
from typing import Optional, List, Union
from app import schemas
from app.helper.storage import StorageHelper
@@ -111,7 +111,7 @@ class StorageBase(metaclass=ABCMeta):
pass
@abstractmethod
def move(self, fileitm: schemas.FileItem, target_file: Path) -> bool:
def move(self, fileitm: schemas.FileItem, target: Union[schemas.FileItem, Path]) -> bool:
"""
移动文件
"""

View File

@@ -663,7 +663,7 @@ class AliPan(StorageBase):
logger.warn("上传文件失败:无法获取上传地址!")
return None
def move(self, fileitem: schemas.FileItem, target_dir: schemas.FileItem) -> bool:
def move(self, fileitem: schemas.FileItem, target: schemas.FileItem) -> bool:
"""
移动文件
"""
@@ -674,7 +674,7 @@ class AliPan(StorageBase):
res = RequestUtils(headers=headers, timeout=10).post_res(self.move_file_url, json={
"drive_id": fileitem.drive_id,
"file_id": fileitem.fileid,
"to_parent_file_id": target_dir.fileid,
"to_parent_file_id": target.fileid,
"check_name_mode": "refuse"
})
if res:

View File

@@ -176,19 +176,7 @@ class LocalStorage(StorageBase):
"""
上传文件
"""
filepath = Path(fileitem.path)
if not filepath.exists():
logger.warn(f"文件不存在:{filepath}")
return None
if not path.exists():
try:
filepath.rename(path)
except Exception as e:
logger.error(f"移动文件失败:{e}")
return None
if path.exists():
return self.__get_fileitem(path)
return None
pass
def copy(self, fileitem: schemas.FileItem, target_file: Path) -> bool:
"""
@@ -223,12 +211,12 @@ class LocalStorage(StorageBase):
return False
return True
def move(self, fileitem: schemas.FileItem, target_file: Path) -> bool:
def move(self, fileitem: schemas.FileItem, target: Path) -> bool:
"""
移动文件
"""
file_path = Path(fileitem.path)
code, message = SystemUtils.move(file_path, target_file)
code, message = SystemUtils.move(file_path, target)
if code != 0:
logger.error(f"移动文件失败:{message}")
return False

View File

@@ -250,7 +250,7 @@ class Rclone(StorageBase):
logger.error(f"获取文件详情失败:{err}")
return None
def move(self, fileitm: schemas.FileItem, target_file: Path) -> bool:
def move(self, fileitm: schemas.FileItem, target: Path) -> bool:
"""
移动文件target_file格式rclone:path
"""
@@ -259,7 +259,7 @@ class Rclone(StorageBase):
[
'rclone', 'moveto',
f'MP:{fileitm.path}',
f'MP:{target_file}'
f'MP:{target}'
],
startupinfo=self.__get_hidden_shell()
).returncode
@@ -270,23 +270,7 @@ class Rclone(StorageBase):
return False
def copy(self, fileitm: schemas.FileItem, target_file: Path) -> bool:
"""
复制文件target_file格式rclone:path
"""
try:
retcode = subprocess.run(
[
'rclone', 'copyto',
f'MP:{fileitm.path}',
f'MP:{target_file}'
],
startupinfo=self.__get_hidden_shell()
).returncode
if retcode == 0:
return True
except Exception as err:
logger.error(f"复制文件失败:{err}")
return False
pass
def link(self, fileitm: schemas.FileItem, target_file: Path) -> bool:
pass

View File

@@ -228,7 +228,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
else:
dir_file = self.create_folder(dir_file, part)
if not dir_file:
logger.warn(f"创建 115 目录 {fileitem.path}{part} 失败!")
logger.warn(f"115创建目录 {fileitem.path}{part} 失败!")
return None
fileitem = dir_file
return None
@@ -249,7 +249,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
self.cloud.storage().delete(fileitem.fileid)
return True
except Exception as e:
logger.error(f"删除115文件失败{str(e)}")
logger.error(f"115删除文件失败:{str(e)}")
return False
def rename(self, fileitem: schemas.FileItem, name: str) -> bool:
@@ -262,7 +262,7 @@ class U115Pan(StorageBase, metaclass=Singleton):
self.cloud.storage().rename(fileitem.fileid, name)
return True
except Exception as e:
logger.error(f"重命名115文件失败:{str(e)}")
logger.error(f"115重命名文件失败:{str(e)}")
return False
def download(self, fileitem: schemas.FileItem, path: Path) -> bool:
@@ -328,20 +328,20 @@ class U115Pan(StorageBase, metaclass=Singleton):
logger.warn(f"115上传文件失败{por.resp.response.text}")
return None
except Exception as e:
logger.error(f"上传115文件失败{str(e)}")
logger.error(f"115上传文件失败:{str(e)}")
return None
def move(self, fileitem: schemas.FileItem, target_dir: schemas.FileItem) -> bool:
def move(self, fileitem: schemas.FileItem, target: schemas.FileItem) -> bool:
"""
移动文件
"""
if not self.__init_cloud():
return False
try:
self.cloud.storage().move(fileitem.fileid, target_dir.fileid)
self.cloud.storage().move(fileitem.fileid, target.fileid)
return True
except Exception as e:
logger.error(f"移动115文件失败{str(e)}")
logger.error(f"115移动文件失败:{str(e)}")
return False
def copy(self, fileitm: schemas.FileItem, target_file: Path) -> bool: