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