thumbnails

package
v0.0.0-...-dd6561b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(imageData []byte, cfg *Config) ([]byte, int64, error)

Generate creates a thumbnail from the provided image data. It resizes the image to fit within maxWidth x maxHeight while preserving aspect ratio, and returns the thumbnail as PNG bytes.

func IsSupportedFormat

func IsSupportedFormat(ext string) bool

IsSupportedFormat checks if the given file extension supports thumbnail generation

func ProcessAsync

func ProcessAsync(task *ThumbnailUploadTask, uploadFunc UploadFunc)

ProcessAsync processes a thumbnail upload task asynchronously. The uploadFunc parameter should contain the logic to upload the thumbnail and register it with the API.

Types

type Config

type Config struct {
	MaxWidth  int
	MaxHeight int
	Quality   int
	Format    string
}

Config holds thumbnail generation settings

func DefaultConfig

func DefaultConfig() *Config

func GenerateAndPrepare

func GenerateAndPrepare(fileType string, originalData []byte) (io.Reader, int64, *Config, error)

GenerateAndPrepare generates a thumbnail and prepares it for upload. Returns the thumbnail data as a reader, the size, and any error.

type CreateThumbnailRequest

type CreateThumbnailRequest struct {
	FileUUID       string `json:"fileUuid"`
	MaxWidth       int    `json:"maxWidth"`
	MaxHeight      int    `json:"maxHeight"`
	Type           string `json:"type"`
	Size           int64  `json:"size"`
	BucketID       string `json:"bucketId"`
	BucketFile     string `json:"bucketFile"`
	EncryptVersion string `json:"encryptVersion"`
}

CreateThumbnailRequest matches the API payload structure for POST /drive/files/thumbnail

func CreateThumbnailMetadata

func CreateThumbnailMetadata(fileUUID, bucketID, bucketFile, encryptVersion string, size int64, cfg *Config) CreateThumbnailRequest

CreateThumbnailMetadata creates the metadata struct for registering a thumbnail.

type ThumbnailUploadTask

type ThumbnailUploadTask struct {
	Ctx          context.Context
	FileUUID     string
	FileType     string
	OriginalData []byte
}

ThumbnailUploadTask represents a task to upload a thumbnail asynchronously.

type UploadFunc

type UploadFunc func(ctx context.Context, task *ThumbnailUploadTask) error

UploadFunc is a function type that handles the actual upload of a thumbnail. This allows dependency injection to avoid circular imports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL