From 6c82c50818d1ea3672700dc1c034f3b0e75ddda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 7 Oct 2022 14:15:20 +0000 Subject: [PATCH] fix base url for file public links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-public-link-baseurl.md | 6 ++++++ .../http/services/owncloud/ocdav/publicfile.go | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 changelog/unreleased/fix-public-link-baseurl.md 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"))