taolib.testing.file_storage.processing.pipeline#

文件处理管道。

编排文件验证、存储和缩略图生成流程。

Classes#

ProcessingResult

文件处理结果。

ProcessingPipeline

文件处理管道。

Module Contents#

class taolib.testing.file_storage.processing.pipeline.ProcessingResult#

文件处理结果。

validated_content_type: str#
media_type: taolib.testing.file_storage.models.enums.MediaType#
checksum_sha256: str#
size_bytes: int#
class taolib.testing.file_storage.processing.pipeline.ProcessingPipeline(validator: taolib.testing.file_storage.processing.protocols.FileValidatorProtocol, thumbnail_generator: taolib.testing.file_storage.processing.protocols.ThumbnailGeneratorProtocol | None = None)#

文件处理管道。

编排验证和后处理步骤。

_validator#
_thumbnail_generator = None#
async process_upload(filename: str, declared_content_type: str, data: bytes, allowed_mime_types: list[str] | None = None, max_file_size_bytes: int | None = None) ProcessingResult#

处理上传的文件。

执行验证并计算校验和。

参数:
  • filename -- 文件名

  • declared_content_type -- 声明的 MIME 类型

  • data -- 文件数据

  • allowed_mime_types -- 允许的 MIME 类型

  • max_file_size_bytes -- 最大文件大小

返回:

处理结果

抛出:

FileValidationError -- 如果验证失败

async generate_thumbnails(data: bytes, content_type: str, sizes: list[taolib.testing.file_storage.models.enums.ThumbnailSize] | None = None) list[taolib.testing.file_storage.processing.protocols.ThumbnailOutput]#

生成缩略图。

参数:
  • data -- 原始文件数据

  • content_type -- MIME 类型

  • sizes -- 要生成的尺寸列表

返回:

缩略图输出列表