Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(api): return correctly encoded task artifact URLs

Rudy Celekli71848c9e0979
diff --git a/app/controllers/v1/video.py b/app/controllers/v1/video.py
index 1be32d2d..b401a7e3 100644
--- a/app/controllers/v1/video.py
+++ b/app/controllers/v1/video.py
@@ -130,8 +130,10 @@ def _task_file_to_uri(file: str, endpoint: str, task_dir: str, request_id: str)
)
return file
- relative_path = os.path.relpath(resolved_path, task_dir).replace("\\", "/")
- uri_path = f"tasks/{relative_path}"
+ relative_path = os.path.relpath(
+ resolved_path, os.path.realpath(task_dir)
+ ).replace("\\", "/")
+ uri_path = f"tasks/{quote(relative_path, safe='/')}"
if endpoint:
return f"{endpoint.rstrip('/')}/{uri_path}"
return f"/{uri_path}"
diff --git a/test/services/test_artifact_uri_escaping.py b/test/services/test_artifact_uri_escaping.py
new file mode 100644
index 00000000..cdeedc94
--- /dev/null
+++ b/test/services/test_artifact_uri_escaping.py
@@ -0,0 +1,22 @@
+import tempfile
+from pathlib import Path
+from urllib.parse import urlsplit, unquote
+import pytest
+from app.controllers.v1.video import _task_file_to_uri
+
[email protected]("filename", ["two words.mp4", "episode#1.mp4", "50% complete.mp3", "字幕.srt"])
[email protected]("endpoint", ["", "https://example.test/output"])
+def test_task_artifact_uri_preserves_filename(filename, endpoint):
+ with tempfile.TemporaryDirectory() as root:
+ output = Path(root) / "task-1" / filename
+ output.parent.mkdir()
+ output.write_bytes(b"artifact")
+ uri = _task_file_to_uri(str(output), endpoint, root, "request")
+ parsed = urlsplit(uri)
+ assert not parsed.query and not parsed.fragment
+ assert " " not in parsed.path and "% " not in parsed.path
+ assert unquote(parsed.path).endswith("/tasks/task-1/" + filename)
+
+def test_remote_artifact_uri_is_not_reencoded():
+ uri = "https://example.test/video.mp4?signature=unchanged%20value"
+ assert _task_file_to_uri(uri, "", "/unused", "request") == uri