fix: handle OpenList delayed transfer metadata

This commit is contained in:
jxxghp
2026-05-20 13:08:45 +08:00
parent a5745af484
commit 3ec0964a01
5 changed files with 229 additions and 26 deletions

View File

@@ -61,6 +61,24 @@ class Alist(StorageBase, metaclass=WeakSingleton):
return fileitem
return None
def __build_transfer_item(
self, source_item: schemas.FileItem, target_path: Path
) -> schemas.FileItem:
"""
根据目标路径构造文件项,用于 OpenList 操作成功但元数据短时间不可见的场景。
"""
return schemas.FileItem(
storage=self.schema.value,
type=source_item.type,
path=target_path.as_posix(),
name=target_path.name,
basename=target_path.stem,
extension=target_path.suffix[1:] if source_item.type != "dir" else None,
size=getattr(source_item, "size", None),
modify_time=getattr(source_item, "modify_time", None),
thumbnail=getattr(source_item, "thumbnail", None),
)
@property
def __get_base_url(self) -> str:
"""
@@ -799,6 +817,28 @@ class Alist(StorageBase, metaclass=WeakSingleton):
self.rename(new_item, new_name)
return True
def copy_item(
self, fileitem: schemas.FileItem, path: Path, new_name: str
) -> Optional[schemas.FileItem]:
"""
复制文件并返回目标文件项,兼容 OpenList 成功响应不携带目标对象的格式。
"""
if not self.copy(fileitem=fileitem, path=path, new_name=new_name):
return None
target_path = path / new_name
target_item = self._delay_get_item(target_path, refresh=True)
if target_item:
return target_item
if fileitem.name == new_name:
return self.__build_transfer_item(fileitem, target_path)
copied_item = self._delay_get_item(path / fileitem.name, refresh=True)
if copied_item and self.rename(copied_item, new_name):
return self._delay_get_item(
target_path, refresh=True
) or self.__build_transfer_item(fileitem, target_path)
return None
def move(self, fileitem: schemas.FileItem, path: Path, new_name: str) -> bool:
"""
移动文件
@@ -852,6 +892,19 @@ class Alist(StorageBase, metaclass=WeakSingleton):
return False
return True
def move_item(
self, fileitem: schemas.FileItem, path: Path, new_name: str
) -> Optional[schemas.FileItem]:
"""
移动文件并返回目标文件项,兼容 OpenList 成功响应不携带目标对象的格式。
"""
if not self.move(fileitem=fileitem, path=path, new_name=new_name):
return None
target_path = path / new_name
return self._delay_get_item(target_path, refresh=True) or self.__build_transfer_item(
fileitem, target_path
)
def link(self, fileitem: schemas.FileItem, target_file: Path) -> bool:
"""
硬链接文件

View File

@@ -709,12 +709,20 @@ class TransHandler:
# 复制文件到新目录
target_fileitem = target_oper.get_folder(target_file.parent)
if target_fileitem:
if source_oper.copy(
fileitem, Path(target_fileitem.path), target_file.name
copy_item = getattr(source_oper, "copy_item", None)
if callable(copy_item):
new_item = copy_item(
fileitem, Path(target_fileitem.path), target_file.name
)
if new_item:
return new_item, ""
elif source_oper.copy(
fileitem, Path(target_fileitem.path), target_file.name
):
return target_oper.get_item(target_file), ""
else:
return None, f"{target_storage}{fileitem.path} 复制文件失败"
new_item = target_oper.get_item(target_file)
if new_item:
return new_item, ""
return None, f"{target_storage}{fileitem.path} 复制文件失败"
else:
return (
None,
@@ -724,12 +732,20 @@ class TransHandler:
# 移动文件到新目录
target_fileitem = target_oper.get_folder(target_file.parent)
if target_fileitem:
if source_oper.move(
fileitem, Path(target_fileitem.path), target_file.name
move_item = getattr(source_oper, "move_item", None)
if callable(move_item):
new_item = move_item(
fileitem, Path(target_fileitem.path), target_file.name
)
if new_item:
return new_item, ""
elif source_oper.move(
fileitem, Path(target_fileitem.path), target_file.name
):
return target_oper.get_item(target_file), ""
else:
return None, f"{target_storage}{fileitem.path} 移动文件失败"
new_item = target_oper.get_item(target_file)
if new_item:
return new_item, ""
return None, f"{target_storage}{fileitem.path} 移动文件失败"
else:
return (
None,