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

44 lines
1.1 KiB
Go

//go:build !enable_vips
package workflow
import (
"bytes"
"fmt"
"image"
"image/gif"
"image/jpeg"
"image/png"
"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.
func encodeForUpload(v any, mimeType string) ([]byte, string, error) {
switch data := v.(type) {
case []byte:
return data, generator.GuessExtension(mimeType), nil
case image.Image:
var (
buf bytes.Buffer
err error
)
if mimeType == "image/jpeg" || mimeType == "image/jpg" {
err = jpeg.Encode(&buf, data, &jpeg.Options{Quality: 85})
return buf.Bytes(), "jpg", err
}
err = png.Encode(&buf, data)
return buf.Bytes(), "png", err
case *gif.GIF:
var buf bytes.Buffer
if err := gif.EncodeAll(&buf, data); err != nil {
return nil, "", fmt.Errorf("encode gif: %w", err)
}
return buf.Bytes(), "gif", nil
default:
return nil, "", fmt.Errorf("unsupported converted type %T", v)
}
}