From c5c5ec2e2c2ed05de428eb53b2950d9675f427aa Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 17 Oct 2026 19:11:18 +0200 Subject: [PATCH] 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. --- .../thumbnails/pkg/thumbnail/mimetypes.go | 23 ----------- services/webdav/pkg/thumbnail/sourcetypes.go | 41 +++++++++++++------ services/webdav/pkg/thumbnail/typemapping.go | 2 +- 3 files changed, 29 insertions(+), 37 deletions(-) delete mode 100644 services/thumbnails/pkg/thumbnail/mimetypes.go diff --git a/services/thumbnails/pkg/thumbnail/mimetypes.go b/services/thumbnails/pkg/thumbnail/mimetypes.go deleted file mode 100644 index aff72a1d6b..0000000000 --- a/services/thumbnails/pkg/thumbnail/mimetypes.go +++ /dev/null @@ -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": {}, -} diff --git a/services/webdav/pkg/thumbnail/sourcetypes.go b/services/webdav/pkg/thumbnail/sourcetypes.go index 461c96ef28..6c4f275cf2 100644 --- a/services/webdav/pkg/thumbnail/sourcetypes.go +++ b/services/webdav/pkg/thumbnail/sourcetypes.go @@ -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{}{} } diff --git a/services/webdav/pkg/thumbnail/typemapping.go b/services/webdav/pkg/thumbnail/typemapping.go index 335b83f87e..dc7eefbd1a 100644 --- a/services/webdav/pkg/thumbnail/typemapping.go +++ b/services/webdav/pkg/thumbnail/typemapping.go @@ -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