diff --git a/internal/http/services/owncloud/ocdav/dav.go b/internal/http/services/owncloud/ocdav/dav.go index 2795346529a..d2582cde4b0 100644 --- a/internal/http/services/owncloud/ocdav/dav.go +++ b/internal/http/services/owncloud/ocdav/dav.go @@ -33,6 +33,7 @@ import ( "github.com/cs3org/reva/v2/pkg/appctx" ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/rhttp/router" + "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" "google.golang.org/grpc/metadata" ) @@ -51,7 +52,7 @@ type DavHandler struct { MetaHandler *MetaHandler TrashbinHandler *TrashbinHandler SpacesHandler *SpacesHandler - PublicFolderHandler *WebDavHandler + PublicFolderHandler *SpacesHandler PublicFileHandler *PublicFileHandler SharesHandler *WebDavHandler } @@ -83,8 +84,8 @@ func (h *DavHandler) init(c *Config) error { return err } - h.PublicFolderHandler = new(WebDavHandler) - if err := h.PublicFolderHandler.init("public", true); err != nil { // jail public file requests to /public/ prefix + h.PublicFolderHandler = new(SpacesHandler) + if err := h.PublicFolderHandler.init(c); err != nil { // jail public file requests to /public/ prefix return err } @@ -260,7 +261,18 @@ func (h *DavHandler) Handler(s *svc) http.Handler { r = r.WithContext(ctx) h.PublicFileHandler.Handler(s).ServeHTTP(w, r) } else { - h.PublicFolderHandler.Handler(s).ServeHTTP(w, r) + // rewrite path for spaces handler + token, r.URL.Path = router.ShiftPath(r.URL.Path) + r.URL.Path, _ = storagespace.FormatReference( + &provider.Reference{ + ResourceId: &provider.ResourceId{ + StorageId: utils.PublicStorageProviderID, + SpaceId: utils.PublicStorageSpaceID, + OpaqueId: token, + }, + Path: r.URL.Path, + }) + h.PublicFolderHandler.Handler(s, nil).ServeHTTP(w, r) } default: diff --git a/internal/http/services/owncloud/ocdav/publicfile.go b/internal/http/services/owncloud/ocdav/publicfile.go index 44e28a27793..d7af1451d05 100644 --- a/internal/http/services/owncloud/ocdav/publicfile.go +++ b/internal/http/services/owncloud/ocdav/publicfile.go @@ -29,6 +29,8 @@ import ( "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/propfind" "github.com/cs3org/reva/v2/pkg/appctx" "github.com/cs3org/reva/v2/pkg/rhttp/router" + "github.com/cs3org/reva/v2/pkg/storagespace" + "github.com/cs3org/reva/v2/pkg/utils" ) // PublicFileHandler handles requests on a shared file. it needs to be wrapped in a collection @@ -53,6 +55,14 @@ func (h *PublicFileHandler) Handler(s *svc) http.Handler { r = r.WithContext(ctx) log.Debug().Str("relativePath", relativePath).Msg("PublicFileHandler func") + spaceid, _ := storagespace.FormatReference( + &provider.Reference{ + ResourceId: &provider.ResourceId{ + StorageId: utils.PublicStorageProviderID, + SpaceId: utils.PublicStorageSpaceID, + OpaqueId: token, + }, + }) if relativePath != "" && relativePath != "/" { // accessing the file @@ -61,13 +71,13 @@ func (h *PublicFileHandler) Handler(s *svc) http.Handler { case MethodPropfind: s.handlePropfindOnToken(w, r, h.namespace, false) case http.MethodGet: - s.handlePathGet(w, r, h.namespace) + s.handleSpacesGet(w, r, spaceid) case http.MethodOptions: s.handleOptions(w, r) case http.MethodHead: - s.handlePathHead(w, r, h.namespace) + s.handleSpacesHead(w, r, spaceid) case http.MethodPut: - s.handlePathPut(w, r, h.namespace) + s.handleSpacesPut(w, r, spaceid) default: w.WriteHeader(http.StatusMethodNotAllowed) } @@ -79,7 +89,7 @@ func (h *PublicFileHandler) Handler(s *svc) http.Handler { case http.MethodOptions: s.handleOptions(w, r) case http.MethodHead: - s.handlePathHead(w, r, h.namespace) + s.handleSpacesHead(w, r, spaceid) default: w.WriteHeader(http.StatusMethodNotAllowed) }