slicer_presets.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """Pydantic schemas for the unified slicer-presets endpoint.
  2. The SliceModal pulls printer/process/filament options from three sources, in
  3. priority order: cloud (the user's Bambu Cloud account), local (DB-backed
  4. imported profiles), and standard (slicer-bundled stock profiles). The endpoint
  5. returns all three lists with name-based dedup applied so each preset appears
  6. exactly once across the response.
  7. """
  8. from typing import Literal
  9. from pydantic import BaseModel
  10. CloudStatus = Literal["ok", "not_authenticated", "expired", "unreachable"]
  11. class UnifiedPreset(BaseModel):
  12. """A single printer/process/filament preset with its source.
  13. The ``id`` shape varies by source:
  14. - cloud → Bambu Cloud setting_id (e.g. ``"PFUS9ac902733670a9"``)
  15. - local → stringified DB row id from ``local_presets``
  16. - standard → preset name as written in the bundled JSON (the slicer
  17. resolves bundled profiles by name during inheritance walk)
  18. The frontend treats ``id`` as opaque; the slice dispatch path uses
  19. ``(source, id)`` to fetch / pass the preset content to the sidecar.
  20. """
  21. id: str
  22. name: str
  23. source: Literal["cloud", "local", "standard"]
  24. class UnifiedPresetsBySlot(BaseModel):
  25. """Three slots in the order Bambu Studio / OrcaSlicer use."""
  26. printer: list[UnifiedPreset] = []
  27. process: list[UnifiedPreset] = []
  28. filament: list[UnifiedPreset] = []
  29. class UnifiedPresetsResponse(BaseModel):
  30. """Each tier carries only the names that didn't appear in a higher tier.
  31. Cloud is the highest priority (user's personal customisations win), then
  32. the local imports the user explicitly curated, then the slicer's stock
  33. fallback. A name that appears in cloud is filtered out of local and
  34. standard; a name that appears in local is filtered out of standard.
  35. ``cloud_status`` lets the frontend show a banner explaining why the cloud
  36. tier is empty when the user expected to see it (signed out / token
  37. expired / network down).
  38. """
  39. cloud: UnifiedPresetsBySlot = UnifiedPresetsBySlot()
  40. local: UnifiedPresetsBySlot = UnifiedPresetsBySlot()
  41. standard: UnifiedPresetsBySlot = UnifiedPresetsBySlot()
  42. cloud_status: CloudStatus = "ok"