schemas.py 857 B

1234567891011121314151617181920212223242526272829303132333435
  1. """请求 / 响应 Pydantic 模型。"""
  2. from typing import Any
  3. from pydantic import BaseModel, Field
  4. class SearchRequest(BaseModel):
  5. """搜索请求体(POST 用)。"""
  6. query: str = Field(..., min_length=1, description="搜索关键词")
  7. locale: str | None = Field(default=None, description="语言代码,留空使用默认")
  8. page: int = Field(default=1, ge=1)
  9. per_page: int = Field(default=25, ge=1, le=100)
  10. class SearchResponse(BaseModel):
  11. """统一响应信封。"""
  12. success: bool
  13. query: str
  14. count: int
  15. page: int
  16. per_page: int
  17. next_page: str | None = None
  18. sec_ids_used: list[int]
  19. results: list[dict[str, Any]]
  20. error: str | None = None
  21. class CacheStatus(BaseModel):
  22. """缓存状态。"""
  23. sec_ids_count: int
  24. last_updated_at: str | None
  25. next_refresh_at: str | None