Skip to content

Commit

Permalink
Merge pull request #3791 from owncloud/thumnails-id
Browse files Browse the repository at this point in the history
fix thumbnails for empty trailing paths
  • Loading branch information
micbar authored May 13, 2022
2 parents 9ccde70 + eb07e05 commit 42c4abb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/share-jail-fixes.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions extensions/webdav/pkg/dav/requests/thumbnail.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package requests

import (
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions extensions/webdav/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 42c4abb

Please sign in to comment.