Files stored as {files_path}/{id} (no extension). The ext parameter
is removed from Save/Read/Delete in both the port interface and
the implementation.
Thumbnail and Preview both use imaging.Thumbnail (fit within
configured max bounds, never upscale, never crop) — the config
values THUMB_WIDTH/HEIGHT and PREVIEW_WIDTH/HEIGHT are upper limits,
not forced dimensions.
Non-decodable files (video, etc.) receive a #444455 placeholder.
Cache writes use atomic temp→rename; on cache failure the generated
image is served from memory so the request still succeeds.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
1018 B
Go
32 lines
1018 B
Go
package port
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// FileStorage abstracts disk (or object-store) operations for file content,
|
|
// thumbnails, and previews.
|
|
type FileStorage interface {
|
|
// Save writes the reader's content to storage and returns the number of
|
|
// bytes written.
|
|
Save(ctx context.Context, id uuid.UUID, r io.Reader) (int64, error)
|
|
|
|
// Read opens the file content for reading. The caller must close the returned
|
|
// ReadCloser.
|
|
Read(ctx context.Context, id uuid.UUID) (io.ReadCloser, error)
|
|
|
|
// Delete removes the file content from storage.
|
|
Delete(ctx context.Context, id uuid.UUID) error
|
|
|
|
// Thumbnail opens the pre-generated thumbnail (JPEG). Returns ErrNotFound
|
|
// if the thumbnail has not been generated yet.
|
|
Thumbnail(ctx context.Context, id uuid.UUID) (io.ReadCloser, error)
|
|
|
|
// Preview opens the pre-generated preview image (JPEG). Returns ErrNotFound
|
|
// if the preview has not been generated yet.
|
|
Preview(ctx context.Context, id uuid.UUID) (io.ReadCloser, error)
|
|
}
|