@@ -26,6 +26,7 @@ import (
2626 "io"
2727 "net/http"
2828 "net/url"
29+ "path"
2930 "path/filepath"
3031 "strconv"
3132 "strings"
@@ -45,6 +46,7 @@ import (
4546 "github.com/cs3org/reva/v3/pkg/rhttp/global"
4647 "github.com/cs3org/reva/v3/pkg/rhttp/router"
4748 "github.com/cs3org/reva/v3/pkg/sharedconf"
49+ "github.com/cs3org/reva/v3/pkg/spaces"
4850 "github.com/cs3org/reva/v3/pkg/storage/utils/downloader"
4951 "github.com/cs3org/reva/v3/pkg/utils/cfg"
5052 "github.com/pkg/errors"
@@ -143,22 +145,53 @@ func New(ctx context.Context, m map[string]interface{}) (global.Service, error)
143145 return s , nil
144146}
145147
148+ func (s * Thumbnails ) Handler () http.Handler {
149+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
150+ var head string
151+
152+ head , r .URL .Path = router .ShiftPath (r .URL .Path )
153+ switch head {
154+ case "files" :
155+ if ! checkMethods (r , http .MethodGet ) {
156+ w .WriteHeader (http .StatusNotFound )
157+ return
158+ }
159+ s .davUserContext (s .Thumbnail (w , r )).ServeHTTP (w , r )
160+ case "public-files" :
161+ if ! checkMethods (r , http .MethodGet , http .MethodHead ) {
162+ w .WriteHeader (http .StatusNotFound )
163+ return
164+ }
165+ s .davPublicContext (s .Thumbnail (w , r )).ServeHTTP (w , r )
166+ }
167+ })
168+ }
169+
146170func (s * Thumbnails ) davUserContext (next http.Handler ) http.Handler {
147171 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
148172 ctx := r .Context ()
173+ log := appctx .GetLogger (ctx )
149174
150- path := r .URL .Path
151- path , _ = url .PathUnescape (path )
175+ urlPath , _ := url .PathUnescape (r .URL .Path )
176+
177+ storageSpaceID , resourcePath := router .ShiftPath (urlPath )
178+ _ , spacePath , ok := spaces .DecodeStorageSpaceID (storageSpaceID )
179+ if ! ok {
180+ s .writeHTTPError (w , errtypes .NotFound ("" ))
181+ return
182+ }
183+ resourcePath = path .Join (spacePath , resourcePath )
152184
153185 res , err := s .statRes (ctx , & provider.Reference {
154- Path : path ,
186+ Path : resourcePath ,
155187 })
156188 if err != nil {
157189 s .writeHTTPError (w , err )
158190 return
159191 }
160192
161193 ctx = ContextSetResource (ctx , res )
194+ log .Info ().Msgf ("FindMe - set resource %s" , res .Path )
162195
163196 next .ServeHTTP (w , r .WithContext (ctx ))
164197 })
@@ -365,12 +398,16 @@ func parseDimension(d, name string, defaultValue int) (int, error) {
365398func (s * Thumbnails ) Thumbnail (w http.ResponseWriter , r * http.Request ) http.Handler {
366399 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
367400 thumbReq , err := s .parseThumbnailRequest (r )
401+ log := appctx .GetLogger (r .Context ())
402+ log .Info ().Msgf ("FindMe - Handling thumbnail request %s" , thumbReq .File )
368403 if err != nil {
369404 s .writeHTTPError (w , err )
370405 return
371406 }
372407
373408 data , mimetype , err := s .thumbnail .GetThumbnail (r .Context (), thumbReq .File , thumbReq .ETag , thumbReq .Width , thumbReq .Height , thumbReq .OutputType )
409+ log .Info ().Msgf ("FindMe - Got thumbnail for %s" , thumbReq .File )
410+
374411 if err != nil {
375412 s .writeHTTPError (w , err )
376413 return
@@ -402,29 +439,6 @@ func (s *Thumbnails) writeHTTPError(w http.ResponseWriter, err error) {
402439 _ , _ = w .Write ([]byte (err .Error ()))
403440}
404441
405- func (s * Thumbnails ) Handler () http.Handler {
406- return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
407- var head string
408-
409- head , r .URL .Path = router .ShiftPath (r .URL .Path )
410- switch head {
411- case "files" :
412- if ! checkMethods (r , http .MethodGet ) {
413- w .WriteHeader (http .StatusNotFound )
414- return
415- }
416- s .davUserContext (s .Thumbnail (w , r )).ServeHTTP (w , r )
417- return
418- case "public-files" :
419- if ! checkMethods (r , http .MethodGet , http .MethodHead ) {
420- w .WriteHeader (http .StatusNotFound )
421- return
422- }
423- s .davPublicContext (s .Thumbnail (w , r )).ServeHTTP (w , r )
424- }
425- })
426- }
427-
428442func checkMethods (r * http.Request , methods ... string ) bool {
429443 for _ , m := range methods {
430444 if r .Method == m {
0 commit comments