fix thumbnails for empty trailing paths

This commit is contained in:
Michael Barz
2022-05-12 18:32:39 +02:00
parent 2586682ae0
commit eb07e056e6
3 changed files with 14 additions and 8 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)