refactor(webdav): own the list of types a preview is announced for

The thumbnails service kept a single map of supported mime types that nothing in that service used any more, only webdav read it, and the comment still claimed reva reads it there. It is webdav's announcement, so DefaultSourceTypes lives next to SourceTypes now, the leftover package is gone, and no webdav file imports the thumbnails service any longer.
This commit is contained in:
Dominik Schmidt committed 2026-10-19 14:57:35 +02:00
1 parent 67856fdf6d
commit c5c5ec2e2c
3 files changed
+29 -37

No files matched your search

@@ -1,23 +0,0 @@
package thumbnail
// SupportedMimeTypes are the types a preview is announced and attempted for
// without further configuration. Both builds read all of them, webp included:
// the pure Go build decodes it through the imaging library and answers the JPEG
// the type mapping asks for. A generator that reads more than this is told so
// with OC_THUMBNAIL_SOURCE_TYPES.
var SupportedMimeTypes = map[string]struct{}{
"image/png": {},
"image/jpg": {},
"image/jpeg": {},
"image/gif": {},
"image/bmp": {},
"image/x-ms-bmp": {},
"image/tiff": {},
"image/webp": {},
"text/plain": {},
"audio/flac": {},
"audio/mpeg": {},
"audio/ogg": {},
"application/vnd.geogebra.slides": {},
"application/vnd.geogebra.pinboard": {},
}
+28 -13
View File
@@ -3,15 +3,33 @@ package thumbnail
import (
"mime"
"strings"
thumbnails "github.com/opencloud-eu/opencloud/services/thumbnails/pkg/thumbnail"
)
// SourceTypes are the types a preview is announced and attempted for. The
// defaults are the ones the thumbnails service compiles in, which is also where
// reva reads them for oc:has-preview, so a build with libvips brings its extra
// types along. Configured entries are merged on top here, per service: nobody
// writes into that package's map.
// DefaultSourceTypes are the types a preview is announced and attempted for
// without further configuration. The image types are what both resize backends
// read; the others are converted to an image here, by a preprocessor, before a
// generator ever sees them.
var DefaultSourceTypes = []string{
"image/png",
"image/jpg",
"image/jpeg",
"image/gif",
"image/bmp",
"image/x-ms-bmp",
"image/tiff",
"image/webp",
"text/plain",
"audio/flac",
"audio/mpeg",
"audio/ogg",
"application/vnd.geogebra.slides",
"application/vnd.geogebra.pinboard",
}
// SourceTypes are the types a preview is announced and attempted for: the
// defaults plus what a deployment configured, which is also the list the
// frontend hands to ocdav for oc:has-preview and graph answers its thumbnails
// relationship from.
//
// The list is a hint, not a verdict. The generator decides what it can really
// read, and a source it refuses answers 404.
@@ -19,13 +37,10 @@ type SourceTypes struct {
byType map[string]struct{}
}
// NewSourceTypes merges the configured types onto the compiled-in defaults.
// NewSourceTypes merges the configured types onto the defaults.
func NewSourceTypes(entries []string) SourceTypes {
t := SourceTypes{byType: make(map[string]struct{}, len(thumbnails.SupportedMimeTypes)+len(entries))}
for mimeType := range thumbnails.SupportedMimeTypes {
t.byType[mimeType] = struct{}{}
}
for _, entry := range entries {
t := SourceTypes{byType: make(map[string]struct{}, len(DefaultSourceTypes)+len(entries))}
for _, entry := range append(append([]string{}, DefaultSourceTypes...), entries...) {
if entry = strings.ToLower(strings.TrimSpace(entry)); entry != "" {
t.byType[entry] = struct{}{}
}
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"github.com/opencloud-eu/opencloud/services/webdav/pkg/generator"
)
// DefaultTypeMapping answers for every type in SupportedMimeTypes, so the
// DefaultTypeMapping answers for every type in DefaultSourceTypes, so the
// type a thumbnail is returned in can be read off here instead of being
// guessed from a file name. Types that carry alpha or animation keep their own
// format, everything else becomes a JPEG. An icon is the one type no generator