From eb07e056e6ec51fb0b766904d435306d90fc026d Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Thu, 12 May 2022 18:32:39 +0200 Subject: [PATCH] fix thumbnails for empty trailing paths --- changelog/unreleased/share-jail-fixes.md | 5 +++++ extensions/webdav/pkg/dav/requests/thumbnail.go | 4 ---- extensions/webdav/pkg/service/v0/service.go | 13 +++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 changelog/unreleased/share-jail-fixes.md diff --git a/changelog/unreleased/share-jail-fixes.md b/changelog/unreleased/share-jail-fixes.md new file mode 100644 index 0000000000..6feeae42e3 --- /dev/null +++ b/changelog/unreleased/share-jail-fixes.md @@ -0,0 +1,5 @@ +Bugfix: Fix Thumbnails for IDs without a trailing path + +The routes in the chi router were not matching thumbnail requests without a trailing path. + +https://github.com/owncloud/ocis/pull/3791 diff --git a/extensions/webdav/pkg/dav/requests/thumbnail.go b/extensions/webdav/pkg/dav/requests/thumbnail.go index c34da24666..134034cd3a 100644 --- a/extensions/webdav/pkg/dav/requests/thumbnail.go +++ b/extensions/webdav/pkg/dav/requests/thumbnail.go @@ -1,7 +1,6 @@ package requests import ( - "errors" "fmt" "net/http" "net/url" @@ -43,9 +42,6 @@ func ParseThumbnailRequest(r *http.Request) (*ThumbnailRequest, error) { ctx := r.Context() fp := ctx.Value(constants.ContextKeyPath).(string) - if fp == "" { - return nil, errors.New("invalid file path") - } id := "" v := ctx.Value(constants.ContextKeyID) diff --git a/extensions/webdav/pkg/service/v0/service.go b/extensions/webdav/pkg/service/v0/service.go index 0b2bd0bb93..a914169d93 100644 --- a/extensions/webdav/pkg/service/v0/service.go +++ b/extensions/webdav/pkg/service/v0/service.go @@ -79,10 +79,14 @@ func NewService(opts ...Option) (Service, error) { r.Group(func(r chi.Router) { r.Use(svc.DavUserContext()) + r.Get("/remote.php/dav/spaces/{id}", svc.SpacesThumbnail) r.Get("/remote.php/dav/spaces/{id}/*", svc.SpacesThumbnail) + r.Get("/dav/spaces/{id}", svc.SpacesThumbnail) r.Get("/dav/spaces/{id}/*", svc.SpacesThumbnail) + r.Get("/remote.php/dav/files/{id}", svc.Thumbnail) r.Get("/remote.php/dav/files/{id}/*", svc.Thumbnail) + r.Get("/dav/files/{id}", svc.Thumbnail) r.Get("/dav/files/{id}/*", svc.Thumbnail) }) @@ -151,11 +155,12 @@ func (g Webdav) DavUserContext() func(next http.Handler) http.Handler { } if id != "" { - filePath = strings.TrimPrefix(filePath, path.Join("/remote.php/dav/spaces", id)+"/") - filePath = strings.TrimPrefix(filePath, path.Join("/dav/spaces", id)+"/") + filePath = strings.TrimPrefix(filePath, path.Join("/remote.php/dav/spaces", id)) + filePath = strings.TrimPrefix(filePath, path.Join("/dav/spaces", id)) - filePath = strings.TrimPrefix(filePath, path.Join("/remote.php/dav/files", id)+"/") - filePath = strings.TrimPrefix(filePath, path.Join("/dav/files", id)+"/") + filePath = strings.TrimPrefix(filePath, path.Join("/remote.php/dav/files", id)) + filePath = strings.TrimPrefix(filePath, path.Join("/dav/files", id)) + filePath = strings.TrimPrefix(filePath, "/") } ctx = context.WithValue(ctx, constants.ContextKeyPath, filePath)