diff --git a/services/webdav/pkg/thumbnail/cache/filecache.go b/services/webdav/pkg/thumbnail/cache/filecache.go index 4c70f7b95f..aef335ab3e 100644 --- a/services/webdav/pkg/thumbnail/cache/filecache.go +++ b/services/webdav/pkg/thumbnail/cache/filecache.go @@ -24,7 +24,6 @@ func NewFileCache(dir string) *FileCache { return &FileCache{dir: dir} } -// probe fails when the filesystem cannot keep the content type next to the bytes. func (c *FileCache) probe() error { if err := os.MkdirAll(c.dir, 0700); err != nil { return err diff --git a/services/webdav/pkg/thumbnail/image.go b/services/webdav/pkg/thumbnail/image.go index c9cffe29f1..355aebaaa3 100644 --- a/services/webdav/pkg/thumbnail/image.go +++ b/services/webdav/pkg/thumbnail/image.go @@ -1,7 +1,6 @@ package thumbnail -// Image is an image and the type it is in, as an extractor hands it on and as -// the cache keeps it. webdav does not decode it, the generator does. +// Image is an undecoded image and its type. type Image struct { ContentType string Data []byte diff --git a/services/webdav/pkg/thumbnail/typemapping.go b/services/webdav/pkg/thumbnail/typemapping.go index ea140fb58f..df57ce74d3 100644 --- a/services/webdav/pkg/thumbnail/typemapping.go +++ b/services/webdav/pkg/thumbnail/typemapping.go @@ -6,11 +6,9 @@ import ( "github.com/opencloud-eu/opencloud/services/webdav/pkg/generator" ) -// DefaultTypeMapping maps the type of the image a thumbnail is made from, the -// file itself or what an extractor found in it. Types that carry alpha or -// animation keep their own format, everything else becomes a JPEG. An icon is -// the one type no generator writes back: it has to become a PNG, or JPEG would -// flatten its transparent pixels onto black. +// DefaultTypeMapping maps the type of the image a thumbnail is made from, not +// the file's. Icons become PNG: no generator writes icons, and JPEG would +// flatten their transparency. var DefaultTypeMapping = []string{ "image/png:image/png", "image/gif:image/gif", diff --git a/services/webdav/pkg/thumbnail/workflow/workflow.go b/services/webdav/pkg/thumbnail/workflow/workflow.go index dbfc576857..e0c3286b06 100644 --- a/services/webdav/pkg/thumbnail/workflow/workflow.go +++ b/services/webdav/pkg/thumbnail/workflow/workflow.go @@ -123,9 +123,8 @@ func fileIsProcessing(info *providerv1beta1.ResourceInfo) bool { return utils.ReadPlainFromOpaque(info.GetOpaque(), "status") == "processing" } -// thumbnailStorageKey is /wxh-, with the snapped box as size. -// The output type depends on the extracted image, so it is stored with the -// entry, not part of the key. +// thumbnailStorageKey has no format: the output type depends on the extracted +// image and is stored with the entry. func thumbnailStorageKey(checksum, mimeType string, w, h int, operation string) string { return storageKeyPrefix(checksum, mimeType) + "/" + fmt.Sprintf("%dx%d-%s", w, h, operation) } @@ -460,7 +459,7 @@ func (w *ThumbnailWorkflow) generate(ctx context.Context, ref *providerv1beta1.R case err == nil && cached != nil && cached.ContentType != "": return Thumbnail{Data: cached.Data, ContentType: cached.ContentType}, nil case err == nil: - // written without a type, e.g. copied without its xattrs: made again + // no type, e.g. copied without xattrs: made again case !errors.Is(err, cache.ErrCacheMiss): // a miss is the normal answer; anything else is the cache itself // failing, and the thumbnail is made again without a word otherwise @@ -484,7 +483,6 @@ func (w *ThumbnailWorkflow) generate(ctx context.Context, ref *providerv1beta1.R } defer cleanup() - // the thumbnail keeps the type of the image it is made from, or what that maps to outputType, outputFormat := w.outputFor(srcType) // webdav snaps the requested size onto a configured resolution and lets the @@ -591,9 +589,7 @@ func (w *ThumbnailWorkflow) sourceImage(ctx context.Context, ref *providerv1beta // thumbnails it serves to make room for one source. const maxCachedSourceBytes = 8 << 20 -// rememberSource keeps what an extractor made of a file, or nil when it found -// nothing. An image too large to keep is simply not kept: -// the extraction runs again next time, which costs time, not correctness. +// rememberSource keeps an extractor's result; nil records that it found none. func (w *ThumbnailWorkflow) rememberSource(key string, img *thumbnail.Image) { if w.cache == nil || img != nil && len(img.Data) > maxCachedSourceBytes { return