Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions internal/http/services/owncloud/ocdav/dav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -51,7 +52,7 @@ type DavHandler struct {
MetaHandler *MetaHandler
TrashbinHandler *TrashbinHandler
SpacesHandler *SpacesHandler
PublicFolderHandler *WebDavHandler
PublicFolderHandler *SpacesHandler
PublicFileHandler *PublicFileHandler
SharesHandler *WebDavHandler
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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:
Expand Down
18 changes: 14 additions & 4 deletions internal/http/services/owncloud/ocdav/publicfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down