refactor(storage): read temp_path from api runtime config snapshot

This commit is contained in:
jxxghp
2026-11-26 16:54:29 +08:00
parent 9921b8a41b
commit cd52b34191
2 changed files with 7 additions and 4 deletions

View File

@@ -34,7 +34,6 @@ from app.chain.transfer.facade import TransferChain
from app.foundation import text as text_tools
from app.runtime.localization import LocaleHelper
from app.runtime.progress import ProgressHelper
from app.runtime.settings import get_runtime_setting
from app.schemas.common import ManageRequest as _SchemaManageRequest
from app.schemas.file import FileItem as _SchemaFileItem
from app.schemas.response import Response as _SchemaResponse
@@ -518,12 +517,12 @@ def delete(
def _cleanup_remote_temp_file(fileitem: _SchemaFileItem, tmp_file: Path) -> None:
"""
清理远端存储下载至 ``TEMP_PATH`` 的临时副本,本地存储原路径绝不删除。
清理远端存储下载至临时目录的副本,本地存储原路径绝不删除。
"""
if (fileitem.storage or "local") == "local":
return
try:
temp_root = Path(get_runtime_setting("TEMP_PATH")).resolve()
temp_root = Path(get_api_runtime_config_snapshot().temp_path).resolve()
resolved_tmp = tmp_file.resolve()
if resolved_tmp != temp_root and resolved_tmp.is_relative_to(temp_root):
resolved_tmp.unlink(missing_ok=True)

View File

@@ -237,7 +237,11 @@ def test_remote_download_and_image_cleanup_temp_copy_while_preserving_local_sour
remote_image_tmp = temp_root / "remote_cover.jpg"
remote_image_tmp.write_bytes(b"remote-jpeg")
monkeypatch.setattr(storage_endpoint, "get_runtime_setting", lambda _k: temp_root)
monkeypatch.setattr(
storage_endpoint,
"get_api_runtime_config_snapshot",
lambda: SimpleNamespace(temp_path=temp_root),
)
monkeypatch.setattr(storage_endpoint, "_ensure_manage_storage_item", lambda item, _u: item)
# 1. 远端 download 返回带后台清理任务的 FileResponse,执行后删除 TEMP_PATH 临时文件