diff --git a/changelog/unreleased/fix-public-link-baseurl.md b/changelog/unreleased/fix-public-link-baseurl.md new file mode 100644 index 0000000000..d59e441424 --- /dev/null +++ b/changelog/unreleased/fix-public-link-baseurl.md @@ -0,0 +1,6 @@ +Bugfix: correct base URL for download URL and href when listing file public links + +We now build the correct base URL when listing file public links. + +https://github.com/cs3org/reva/pull/3324 +https://github.com/owncloud/ocis/issues/4758 \ No newline at end of file diff --git a/internal/http/services/owncloud/ocdav/publicfile.go b/internal/http/services/owncloud/ocdav/publicfile.go index 32b6477d0e..44e28a2779 100644 --- a/internal/http/services/owncloud/ocdav/publicfile.go +++ b/internal/http/services/owncloud/ocdav/publicfile.go @@ -19,9 +19,9 @@ package ocdav import ( + "context" "net/http" "path" - "path/filepath" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" @@ -44,8 +44,13 @@ func (h *PublicFileHandler) init(ns string) error { // Handler handles requests func (h *PublicFileHandler) Handler(s *svc) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - log := appctx.GetLogger(r.Context()) - _, relativePath := router.ShiftPath(r.URL.Path) + ctx := r.Context() + log := appctx.GetLogger(ctx) + token, relativePath := router.ShiftPath(r.URL.Path) + + base := path.Join(ctx.Value(net.CtxKeyBaseURI).(string), token) + ctx = context.WithValue(ctx, net.CtxKeyBaseURI, base) + r = r.WithContext(ctx) log.Debug().Str("relativePath", relativePath).Msg("PublicFileHandler func") @@ -106,9 +111,6 @@ func (s *svc) handlePropfindOnToken(w http.ResponseWriter, r *http.Request, ns s return } - // prefix tokenStatInfo.Path with token - tokenStatInfo.Path = filepath.Join(r.URL.Path, tokenStatInfo.Path) - infos := s.getPublicFileInfos(onContainer, depth == net.DepthZero, tokenStatInfo) prefer := net.ParsePrefer(r.Header.Get("prefer"))