Files
opencloud/services/webdav/pkg/thumbnail/cache/cache.go
T
Jörn Friedrich Dreyer 5c3b7f8890 refactor(webdav): drive the thumbnail workflow via the push-based generator
webdav now owns the complete thumbnail pipeline: stat -> validate -> cache
check -> download -> preprocess -> generate -> cache -> respond. The
thumbnails service is used only as a stateless imagor-compatible image
resizer via its /unsafe push endpoint.

- New ThumbnailWorkflow drives the pipeline; space-scoped refs are anchored
  at the space ResourceId and downloads authenticate with the user's
  x-access-token.
- Preprocessing (audio/geogebra/text/gif) moves from the thumbnails service
  into webdav (services/webdav/pkg/preprocessor).
- Thumbnail caching moves to webdav (memory/file/s3 backends, file cache off
  by default); resolutions are snapped orientation-aware in webdav.
- Generator URL defaults to the local thumbnails service; new WEBDAV_* config
  for generator, cache and resolutions.
- Acceptance tests updated for the new sizing/processor behavior.
2026-09-04 23:05:11 +02:00

62 lines
1.5 KiB
Go

package cache
import (
"errors"
"path/filepath"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/opencloud-eu/opencloud/pkg/config/defaults"
)
var ErrCacheMiss = errors.New("thumbnail cache miss")
// DefaultFileCacheDir is the on-disk location of file-backend thumbnails,
// mirroring main's $OC_BASE_DATA_PATH/thumbnails/files layout.
func DefaultFileCacheDir() string {
return filepath.Join(defaults.BaseDataPath(), "thumbnails", "files")
}
// ThumbnailCache provides cached storage for generated thumbnails.
type ThumbnailCache interface {
Get(key string) ([]byte, error)
Put(key string, data []byte) error
}
// NewThumbnailCache creates a cache instance based on the configured backend.
func NewThumbnailCache(backend string, cacheDir string, s3cfg *S3CacheConfig) ThumbnailCache {
switch backend {
case "none":
return NoopCache{}
case "memory":
return NewInMemoryCache()
case "file":
dir := cacheDir
if dir == "" {
dir = DefaultFileCacheDir()
}
return NewFileCache(dir)
case "s3":
if s3cfg != nil && s3cfg.IsComplete() {
return NewS3Cache(*s3cfg)
}
return NoopCache{}
default:
return NoopCache{}
}
}
// BuildS3CacheConfig creates an S3CacheConfig from raw config fields.
func BuildS3CacheConfig(bucket, region, endpoint, accessKey, secretKey string) *S3CacheConfig {
cfg := &S3CacheConfig{
Bucket: bucket,
Region: region,
Endpoint: endpoint,
Secure: true,
}
if accessKey != "" && secretKey != "" {
cfg.Credentials = credentials.NewStaticV4(accessKey, secretKey, "")
}
return cfg
}