fix(civitai): tolerate null availability, expose early access fields

The /model-versions endpoint now serializes availability as null, which
failed str validation and turned every version lookup into a 404. Coerce
null to the default like the creator username validator already does.

Pass through earlyAccessEndsAt and earlyAccessConfig so clients can see
that a download requires a Buzz purchase before requesting the file.
This commit is contained in:
CalamitousFelicitousness
2026-07-09 23:34:54 +01:00
parent d2937166d3
commit a274f57aab
+9
View File
@@ -58,6 +58,8 @@ class CivitVersion(BaseModel):
base_model: str = Field("Unknown", alias="baseModel")
published_at: str | None = Field(None, alias="publishedAt")
availability: str = "Unknown"
early_access_ends_at: str | None = Field(None, alias="earlyAccessEndsAt")
early_access_config: dict | None = Field(None, alias="earlyAccessConfig")
description: str | None = None
trained_words: list[str] = Field(default_factory=list, alias="trainedWords")
stats: CivitStats = Field(default_factory=CivitStats)
@@ -66,6 +68,13 @@ class CivitVersion(BaseModel):
nsfw_level: int = Field(0, alias="nsfwLevel")
download_url: str = Field("", alias="downloadUrl")
@validator('availability', pre=True)
def coerce_null_availability(cls, v): # pylint: disable=no-self-argument
# /model-versions/{id} serializes availability as null, which failed
# str validation and turned every version lookup into a 404. Fall back
# to the default instead of rejecting the whole version.
return "Unknown" if v in (None, "") else v
class CivitCreator(BaseModel):
class Config: