Skip to content

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

fix(upload-post): retain recovery IDs after malformed upload responses

Rudy Celekli3a2b650d662b
diff --git a/app/services/upload_post.py b/app/services/upload_post.py
index 8cf2dda5..089ae6eb 100644
--- a/app/services/upload_post.py
+++ b/app/services/upload_post.py
@@ -206,6 +206,16 @@ class UploadPostService:
# Generate the remote handle before POST: a lost response does not
# prove that Upload-Post stopped publishing the received video.
client_request_id = str(uuid4())
+ def unconfirmed_response(message: str) -> dict:
+ return {
+ "success": False,
+ "request_id": client_request_id,
+ "error": (
+ f"{message}; upload outcome is unconfirmed; "
+ f"check request_id {client_request_id} before submitting again"
+ ),
+ }
+
try:
with open(video_path, 'rb') as video_file:
files = {'video': video_file}
@@ -262,10 +272,7 @@ class UploadPostService:
result = response.json()
except ValueError:
logger.error("Upload-Post returned invalid JSON to upload")
- return {
- "success": False,
- "error": "Upload-Post returned invalid JSON",
- }
+ return unconfirmed_response("Upload-Post returned invalid JSON")
# Release the source file before waiting for a remote background
# upload, which can take much longer than the initial POST.
@@ -273,21 +280,16 @@ class UploadPostService:
result.get("success"), bool
):
logger.error("Upload-Post returned an invalid response to upload")
- return {
- "success": False,
- "error": "Upload-Post returned an invalid response",
- }
+ return unconfirmed_response("Upload-Post returned an invalid response")
if result["success"]:
is_background = "results" not in result
if is_background:
request_id = result.get("request_id")
if not isinstance(request_id, str) or not request_id.strip():
- return {
- "success": False,
- "error": "Upload-Post started a background upload "
- "without a request_id",
- }
+ return unconfirmed_response(
+ "Upload-Post started a background upload without a request_id"
+ )
logger.info(
"Upload-Post background upload accepted: "
f"request_id={request_id.strip()}"
diff --git a/test/services/test_upload_response_recovery.py b/test/services/test_upload_response_recovery.py
new file mode 100644
index 00000000..39ba5ea5
--- /dev/null
+++ b/test/services/test_upload_response_recovery.py
@@ -0,0 +1,30 @@
+from unittest.mock import MagicMock, patch
+import pytest
+from app.services.upload_post import UploadPostService
+
[email protected]("payload", [None, [], {"success": "true"}, {"success": True}])
+def test_unconfirmed_upload_response_retains_sent_recovery_id(tmp_path, payload):
+ video = tmp_path / "final.mp4"
+ video.write_bytes(b"video fixture")
+ response = MagicMock(status_code=200)
+ if payload is None:
+ response.json.side_effect = ValueError("truncated JSON")
+ else:
+ response.json.return_value = payload
+ service = UploadPostService({"upload_post_enabled": True, "upload_post_api_key": "fake-key", "upload_post_username": "test-user"})
+ with patch("app.services.upload_post.requests.post", return_value=response) as post:
+ result = service.upload_video(str(video), "Title", platforms=["tiktok"])
+ sent_id = dict(post.call_args.kwargs["data"])["request_id"]
+ assert result["success"] is False
+ assert result["request_id"] == sent_id
+ assert sent_id in result["error"] and "unconfirmed" in result["error"]
+ post.assert_called_once()
+
+def test_provider_rejection_remains_a_confirmed_failure(tmp_path):
+ video = tmp_path / "final.mp4"
+ video.write_bytes(b"video fixture")
+ response = MagicMock(status_code=200)
+ response.json.return_value = {"success": False, "error": "invalid title"}
+ service = UploadPostService({"upload_post_enabled": True, "upload_post_api_key": "fake-key", "upload_post_username": "test-user"})
+ with patch("app.services.upload_post.requests.post", return_value=response):
+ assert service.upload_video(str(video), "Title", platforms=["tiktok"]) == response.json.return_value