Ctrl K
ComunidadGuías…

api/fields/file_fields.py

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
from __future__ import annotations

from datetime import datetime
from typing import Annotated

from pydantic import ConfigDict, WithJsonSchema, field_validator

from fields.base import ResponseModel
from libs.helper import to_timestamp

UUIDString = Annotated[str, WithJsonSchema({"format": "uuid", "type": "string"})]
Int64 = Annotated[int, WithJsonSchema({"format": "int64", "type": "integer"})]


class UploadConfig(ResponseModel):
    file_size_limit: int
    knowledge_file_size_limit: int
    batch_count_limit: int
    file_upload_limit: int
    image_file_size_limit: int
    video_file_size_limit: int
    audio_file_size_limit: int
    skill_file_size_limit: int
    workflow_file_upload_limit: int
    image_file_batch_limit: int
    single_chunk_attachment_limit: int
    attachment_image_file_size_limit: int


class FileResponse(ResponseModel):
    id: UUIDString
    reference: str | None = None
    name: str
    size: int
    extension: str | None = None
    mime_type: str | None = None
    created_by: UUIDString | None = None
    created_at: Int64 | None = None
    preview_url: str | None = None
    source_url: str | None = None
    original_url: str | None = None
    user_id: UUIDString | None = None
    tenant_id: UUIDString | None = None
    conversation_id: UUIDString | None = None
    file_key: str | None = None

    @field_validator("created_at", mode="before")
    @classmethod
    def _normalize_created_at(cls, value: datetime | int | None) -> int | None:
        return to_timestamp(value)


class RemoteFileInfo(ResponseModel):
    file_type: str
    file_length: int


class FileWithSignedUrl(ResponseModel):
    model_config = ConfigDict(json_schema_serialization_defaults_required=True)

    id: str
    name: str
    size: int
    extension: str | None = None
    url: str | None = None
    mime_type: str | None = None
    created_by: str | None = None
    created_at: int | None = None

    @field_validator("created_at", mode="before")
    @classmethod
    def _normalize_created_at(cls, value: datetime | int | None) -> int | None:
        return to_timestamp(value)


__all__ = [
    "FileResponse",
    "FileWithSignedUrl",
    "RemoteFileInfo",
    "UploadConfig",
]