From f0032620e7d456fed8f12d35b6b8bc011fb0900e Mon Sep 17 00:00:00 2001 From: David Christofas Date: Tue, 9 Mar 2021 23:56:52 +0100 Subject: [PATCH] fix jpeg thumbnails --- changelog/unreleased/fix-jpeg-thumbnails.md | 6 ++++++ webdav/pkg/dav/thumbnails/thumbnail.go | 4 ++-- webdav/pkg/service/v0/service.go | 14 ++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 changelog/unreleased/fix-jpeg-thumbnails.md diff --git a/changelog/unreleased/fix-jpeg-thumbnails.md b/changelog/unreleased/fix-jpeg-thumbnails.md new file mode 100644 index 00000000000..dfc8020708f --- /dev/null +++ b/changelog/unreleased/fix-jpeg-thumbnails.md @@ -0,0 +1,6 @@ +Bugfix: Fix thumbnail generation for jpegs + +Images with the extension `.jpeg` were not properly supported. + +https://github.com/owncloud/ocis/issues/1490 +https://github.com/owncloud/ocis/pull/1785 diff --git a/webdav/pkg/dav/thumbnails/thumbnail.go b/webdav/pkg/dav/thumbnails/thumbnail.go index a42082f951f..6184e7fadc3 100644 --- a/webdav/pkg/dav/thumbnails/thumbnail.go +++ b/webdav/pkg/dav/thumbnails/thumbnail.go @@ -20,7 +20,7 @@ const ( // Request combines all parameters provided when requesting a thumbnail type Request struct { Filepath string - Filetype string + Extension string Etag string Width int Height int @@ -50,7 +50,7 @@ func NewRequest(r *http.Request) (Request, error) { tr := Request{ Filepath: path, - Filetype: strings.Replace(filepath.Ext(path), ".", "", 1), + Extension: filepath.Ext(path), Etag: etag, Width: width, Height: height, diff --git a/webdav/pkg/service/v0/service.go b/webdav/pkg/service/v0/service.go index 1aaa5b52b27..86d45ccac00 100644 --- a/webdav/pkg/service/v0/service.go +++ b/webdav/pkg/service/v0/service.go @@ -65,7 +65,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { c := thumbnails.NewThumbnailService("com.owncloud.api.thumbnails", grpc.DefaultClient) rsp, err := c.GetThumbnail(r.Context(), &thumbnails.GetRequest{ Filepath: strings.TrimLeft(tr.Filepath, "/"), - Filetype: extensionToFiletype(tr.Filetype), + Filetype: extensionToFiletype(strings.TrimLeft(tr.Extension, ".")), Etag: tr.Etag, Width: int32(tr.Width), Height: int32(tr.Height), @@ -90,11 +90,17 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { } func extensionToFiletype(ext string) thumbnails.GetRequest_FileType { - val, ok := thumbnails.GetRequest_FileType_value[strings.ToUpper(ext)] - if !ok { + ext = strings.ToUpper(ext) + switch ext { + case "JPG", "PNG": + val := thumbnails.GetRequest_FileType_value[ext] + return thumbnails.GetRequest_FileType(val) + case "JPEG": + val := thumbnails.GetRequest_FileType_value["JPG"] + return thumbnails.GetRequest_FileType(val) + default: return thumbnails.GetRequest_FileType(-1) } - return thumbnails.GetRequest_FileType(val) } func mustWrite(logger log.Logger, w io.Writer, val []byte) {