From cd52b3419166a6440a5ba4e0419cd977b32633a6 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 26 Nov 2026 16:54:29 +0800 Subject: [PATCH] refactor(storage): read temp_path from api runtime config snapshot --- app/api/endpoints/storage.py | 5 ++--- tests/api/storage/test_storage_agent_security.py | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/api/endpoints/storage.py b/app/api/endpoints/storage.py index 2f919366b..02a2bf560 100644 --- a/app/api/endpoints/storage.py +++ b/app/api/endpoints/storage.py @@ -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) diff --git a/tests/api/storage/test_storage_agent_security.py b/tests/api/storage/test_storage_agent_security.py index e10ae81c7..c8dd0b390 100644 --- a/tests/api/storage/test_storage_agent_security.py +++ b/tests/api/storage/test_storage_agent_security.py @@ -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 临时文件