cloud_server.thumbnail_generator

Thumbnail generation for images and videos.

Classes

ThumbnailGenerator(thumbnails_directory)

Generate thumbnails for images and videos.

class cloud_server.thumbnail_generator.ThumbnailGenerator(thumbnails_directory)[source]

Generate thumbnails for images and videos.

__init__(thumbnails_directory)[source]

Initialize thumbnail generator.

Parameters:

thumbnails_directory (Path) – Directory to save generated thumbnails

get_thumbnail_path(file_id)[source]

Get the thumbnail path for a given file ID.

Parameters:

file_id (int) – Unique identifier for the file

Return Path:

Path to the thumbnail image

Return type:

Path

generate_thumbnail(filepath, mime_type, file_id, thumbnail_size)[source]

Generate thumbnail based on MIME type.

Parameters:
  • filepath (Path) – Path to source file

  • mime_type (str) – MIME type of the file

  • file_id (int) – Unique identifier for the file

  • thumbnail_size (tuple[int, int]) – Target thumbnail size (width, height)

Raises:
  • FileExistsError – If a thumbnail already exists for the file

  • ValueError – If the MIME type is unsupported for thumbnail generation

Return type:

None

synchronize_with_storage(storage_directory, files_metadata, thumbnail_size)[source]

Synchronize thumbnails with the storage directory by generating missing thumbnails and removing stale ones.

Parameters:
  • storage_directory (Path) – Path to the server storage directory

  • files_metadata (list[FileMetadata]) – File metadata in the database

  • thumbnail_size (tuple[int, int]) – Target thumbnail size (width, height)

Return type:

None