Files
bambuddy/backend/app/schemas/makerworld.py
maziggy 09b739b95d fix(cloud): stop reporting an expired Bambu Cloud sign-in as connected (issue #2562)
An expired token was indistinguishable from a working one. set_token()
stamped token_expiry = now + 30 days every time a stored token was loaded,
so the expiry reset on every request and is_authenticated could never
return False. /cloud/status answered "connected" for as long as any token
existed, while every cloud call 401'd — and the user was shown Bambu's own
{"error": "Please login."} verbatim.

Bambu is now the authority: /cloud/status validates the token upstream
(cached 5m), and any 401 from any authenticated call durably records the
credential as dead via users.cloud_token_invalid_at, so MakerWorld, cloud
profiles, slicer presets and firmware checks all agree at once. An
unreachable Bambu is treated as unknown, never as expired, so an outage
cannot sign a working session out.

The user-facing message now names the Profiles page, where the Bambu Cloud
sign-in actually lives; the old text pointed at a Settings page that does
not exist. Same stale path corrected in the wiki.
2026-07-14 11:29:56 +02:00

116 lines
4.1 KiB
Python

"""Pydantic schemas for the MakerWorld integration routes."""
from __future__ import annotations
from typing import Any
from pydantic import BaseModel, Field
class MakerWorldResolveRequest(BaseModel):
"""Body for POST /makerworld/resolve."""
url: str = Field(..., description="Any MakerWorld model URL (scheme optional)")
class MakerWorldResolvedModel(BaseModel):
"""Structured result of URL resolution.
``design`` and ``instances`` are passed through verbatim from MakerWorld's
API — we don't re-shape them because the frontend needs access to fields
MakerWorld may add over time (badges, license variants, etc.). Keeping
them as opaque dicts avoids brittle coupling.
"""
model_id: int
profile_id: int | None = Field(
default=None,
description="Specific profile from the URL's #profileId- fragment, if any",
)
design: dict[str, Any]
instances: list[dict[str, Any]]
already_imported_library_ids: list[int] = Field(
default_factory=list,
description="LibraryFile IDs that were previously imported from this model URL",
)
class MakerWorldImportRequest(BaseModel):
"""Body for POST /makerworld/import."""
model_id: int = Field(
...,
description="The MakerWorld design ID (the number in /models/{id}).",
)
profile_id: int | None = Field(
default=None,
description=(
"The profileId of the selected instance (plate configuration). Each "
"instance in `/design/{id}/instances` carries a `profileId` field — "
"the frontend forwards the picked one here. If omitted, the backend "
"falls back to the first available instance of the model."
),
)
instance_id: int | None = Field(
default=None,
description="Retained for backwards compatibility; no longer used by the download flow.",
)
folder_id: int | None = Field(default=None, description="Target library folder; null = root")
class MakerWorldRecentImport(BaseModel):
"""One row in the 'recent MakerWorld imports' list."""
library_file_id: int
filename: str
folder_id: int | None
thumbnail_path: str | None = Field(
default=None,
description="Relative path under /api/v1/library/files/{id}/thumbnail — "
"the frontend wraps it with a stream token to render.",
)
source_url: str | None = Field(
default=None,
description="Canonical MakerWorld URL (``https://makerworld.com/models/{id}"
"#profileId-{pid}``). The frontend uses it to build an 'Open on MakerWorld' "
"link and to extract model/profile ids without a second API round-trip.",
)
created_at: str
class MakerWorldImportResponse(BaseModel):
"""Result of a MakerWorld import."""
library_file_id: int
filename: str
folder_id: int | None = Field(
default=None,
description=(
"Folder the file was saved to — the auto-created 'MakerWorld' folder "
"by default, or whichever folder the caller specified. Surfaced so the "
"frontend can deep-link to File Manager → that folder after import."
),
)
profile_id: int | None = Field(
default=None,
description=(
"The MakerWorld profile (plate) id that was imported. Surfaced so the "
"frontend can match the response back to the plate row in the UI and "
"render inline 'view in library' / 'open in slicer' controls there."
),
)
was_existing: bool = Field(
description="True if a prior import from the same source URL was reused (no re-download)"
)
class MakerWorldStatus(BaseModel):
"""Integration health + auth status surfaced to the frontend."""
has_cloud_token: bool = Field(description="Whether the caller's account has a stored Bambu Cloud token")
can_download: bool = Field(description="Shortcut: has_cloud_token AND it looks valid. Downloads require it.")
sign_in_expired: bool = Field(
default=False,
description="A token is stored but Bambu has rejected it — the user must sign in to Bambu Cloud again.",
)