60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
|
|
from app.enums.video_upscale import normalize_video_upscale_resolution
|
|
from app.schemas.common import NaiveDatetimeOptional
|
|
|
|
|
|
class VideoUpscaleResolutionRule(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
target_resolution: str = Field(..., min_length=1, max_length=16)
|
|
provider_generation_resolution: str = Field(..., min_length=1, max_length=16)
|
|
processor_key: str = Field(..., min_length=1, max_length=64)
|
|
enabled: bool = True
|
|
|
|
@field_validator("target_resolution", "provider_generation_resolution")
|
|
@classmethod
|
|
def clean_resolution(cls, value: str) -> str:
|
|
return normalize_video_upscale_resolution(value)
|
|
|
|
@field_validator("processor_key")
|
|
@classmethod
|
|
def clean_processor_key(cls, value: str) -> str:
|
|
return str(value).strip()
|
|
|
|
|
|
class VideoUpscaleConfigData(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
enabled: bool = False
|
|
version: int = Field(1, ge=1)
|
|
delete_source_after_success: bool = True
|
|
rules: list[VideoUpscaleResolutionRule] = Field(default_factory=list)
|
|
|
|
@model_validator(mode="after")
|
|
def validate_unique_rules(self) -> "VideoUpscaleConfigData":
|
|
seen: set[str] = set()
|
|
for rule in self.rules:
|
|
if not rule.enabled:
|
|
continue
|
|
if rule.target_resolution in seen:
|
|
raise ValueError(f"客户目标分辨率存在重复启用规则: {rule.target_resolution}")
|
|
seen.add(rule.target_resolution)
|
|
return self
|
|
|
|
|
|
class VideoUpscaleConfigSaveRequest(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
data: VideoUpscaleConfigData
|
|
|
|
|
|
class VideoUpscaleConfigOut(BaseModel):
|
|
id: str | None = None
|
|
key: str
|
|
description: str | None = None
|
|
data: VideoUpscaleConfigData
|
|
created_at: NaiveDatetimeOptional = None
|
|
updated_at: NaiveDatetimeOptional = None
|