Files
opencloud/services/webdav/pkg/thumbnail/workflow/encode_vips.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

51 lines
1.4 KiB
Go

//go:build enable_vips
package workflow
import (
"fmt"
"image"
"image/gif"
vips "github.com/davidbyttow/govips/v2/vips"
"github.com/opencloud-eu/opencloud/services/webdav/pkg/generator"
)
// encodeForUpload turns the value produced by the preprocessing step into
// bytes for upload to the generator. Raw image bytes pass through unchanged;
// converted values are encoded in-process via libvips.
func encodeForUpload(v any, mimeType string) ([]byte, string, error) {
switch data := v.(type) {
case []byte:
return data, generator.GuessExtension(mimeType), nil
case image.Image:
img, err := vips.NewImageFromGoImage(data)
if err != nil {
return nil, "", fmt.Errorf("create vips image: %w", err)
}
defer img.Close()
if mimeType == "image/jpeg" || mimeType == "image/jpg" {
buf, _, err := img.ExportJpeg(&vips.JpegExportParams{Quality: 85})
return buf, "jpg", err
}
buf, _, err := img.ExportPng(&vips.PngExportParams{})
return buf, "png", err
case *gif.GIF:
if len(data.Image) == 0 {
return nil, "", fmt.Errorf("gif has no frames")
}
img, err := vips.NewImageFromGoImage(data.Image[0])
if err != nil {
return nil, "", fmt.Errorf("create vips image: %w", err)
}
defer img.Close()
buf, _, err := img.ExportGIF(&vips.GifExportParams{})
return buf, "gif", err
default:
return nil, "", fmt.Errorf("unsupported converted type %T", v)
}
}