Skip to content

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

fix(api): bound task listing page size

Rudy Celeklie8e8c80bfc12
diff --git a/app/controllers/v1/video.py b/app/controllers/v1/video.py
index 592d2e11..dd26f5b4 100644
--- a/app/controllers/v1/video.py
+++ b/app/controllers/v1/video.py
@@ -273,7 +273,7 @@ def create_task(
def get_all_tasks(
request: Request,
page: int = Query(1, ge=1),
- page_size: int = Query(10, ge=1),
+ page_size: int = Query(10, ge=1, le=1000),
):
tasks, total = sm.state.get_all_tasks(page, page_size)
request_id = base.get_task_id(request)
diff --git a/test/services/test_controller_video.py b/test/services/test_controller_video.py
index f3b657c0..f79b28e0 100644
--- a/test/services/test_controller_video.py
+++ b/test/services/test_controller_video.py
@@ -584,6 +584,26 @@ class TestVideoControllerCreateHTTP(unittest.TestCase):
add_task.assert_not_called()
+class TestVideoControllerListHTTP(unittest.TestCase):
+ def test_task_page_size_is_bounded_before_state_scan(self):
+ """A client cannot request an unbounded Redis scan and response body."""
+ with (
+ patch.dict(config.app, {"api_key": ""}),
+ patch.object(
+ video_controller.sm.state,
+ "get_all_tasks",
+ return_value=([], 0),
+ ) as get_all,
+ ):
+ client = TestClient(asgi.app)
+ allowed = client.get("/api/v1/tasks?page_size=1000")
+ rejected = client.get("/api/v1/tasks?page_size=1001")
+
+ self.assertEqual(allowed.status_code, 200)
+ self.assertEqual(rejected.status_code, 400)
+ get_all.assert_called_once_with(1, 1000)
+
+
class TestVideoControllerDeleteHTTP(unittest.TestCase):
"""DELETE /api/v1/tasks/{task_id} 的真实 HTTP 级回归测试。"""