Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix base url for file public links #3324

Merged
merged 1 commit into from
Oct 10, 2022
Merged
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
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-public-link-baseurl.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions internal/http/services/owncloud/ocdav/publicfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")

Expand Down Expand Up @@ -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"))
Expand Down