mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-10-05 02:15:15 -04:00
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.
44 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|