manyfold.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. """Request and response shapes for the Manyfold routes (#1471)."""
  2. from __future__ import annotations
  3. from pydantic import BaseModel, Field
  4. class ManyfoldConfigResponse(BaseModel):
  5. url: str
  6. client_id: str
  7. # The secret itself is never sent back, only whether one is stored.
  8. has_client_secret: bool
  9. configured: bool
  10. class ManyfoldConfigUpdate(BaseModel):
  11. url: str = Field(..., max_length=500)
  12. client_id: str = Field(..., min_length=1, max_length=200)
  13. # Left empty, the stored secret is kept.
  14. client_secret: str | None = Field(default=None, max_length=500)
  15. class ManyfoldTestRequest(BaseModel):
  16. url: str = Field(..., max_length=500)
  17. client_id: str = Field(..., min_length=1, max_length=200)
  18. # Left empty, the stored secret is tested.
  19. client_secret: str | None = Field(default=None, max_length=500)
  20. class ManyfoldTestResponse(BaseModel):
  21. model_count: int
  22. class ManyfoldStatus(BaseModel):
  23. configured: bool
  24. # For "Open in Manyfold" links; empty until configured.
  25. url: str
  26. class ManyfoldModelSummary(BaseModel):
  27. id: str
  28. name: str
  29. class ManyfoldModelList(BaseModel):
  30. total: int
  31. page: int
  32. has_next: bool
  33. has_previous: bool
  34. models: list[ManyfoldModelSummary]
  35. class ManyfoldLibraryRef(BaseModel):
  36. """The library file an earlier import of a Manyfold file created."""
  37. id: int
  38. filename: str
  39. folder_id: int | None
  40. class ManyfoldFile(BaseModel):
  41. id: str
  42. name: str
  43. mime: str
  44. importable: bool
  45. # Set while the file imported earlier is still in the library.
  46. library_file: ManyfoldLibraryRef | None = None
  47. class ManyfoldModel(BaseModel):
  48. id: str
  49. name: str
  50. caption: str | None = None
  51. description: str | None = None
  52. license: str | None = None
  53. tags: list[str]
  54. url: str
  55. has_preview: bool
  56. files: list[ManyfoldFile]
  57. class ManyfoldImportRequest(BaseModel):
  58. model_id: str = Field(..., min_length=1, max_length=64)
  59. file_id: str = Field(..., min_length=1, max_length=64)
  60. # None imports into the "Manyfold" folder, created on first use.
  61. folder_id: int | None = None
  62. class ManyfoldImportResponse(BaseModel):
  63. library_file_id: int
  64. filename: str
  65. folder_id: int | None
  66. was_existing: bool