From e017a199850e19dd51b960ba59402c215fd8f1af Mon Sep 17 00:00:00 2001 From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com> Date: Fri, 12 Mar 2021 12:14:58 +0000 Subject: [PATCH] fix: full file path on share --- http/public.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/http/public.go b/http/public.go index c24be0d9..8dc400d3 100644 --- a/http/public.go +++ b/http/public.go @@ -16,7 +16,7 @@ import ( var withHashFile = func(fn handleFunc) handleFunc { return func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { - id, path := ifPathWithName(r) + id, ifPath := ifPathWithName(r) link, err := d.store.Share.GetByHash(id) if err != nil { return errToStatus(err), err @@ -47,21 +47,30 @@ var withHashFile = func(fn handleFunc) handleFunc { return errToStatus(err), err } - if file.IsDir { - // set fs root to the shared folder - d.user.Fs = afero.NewBasePathFs(d.user.Fs, filepath.Dir(link.Path)) + // share base path + basePath := link.Path - file, err = files.NewFileInfo(files.FileOptions{ - Fs: d.user.Fs, - Path: path, - Modify: d.user.Perm.Modify, - Expand: true, - Checker: d, - Token: link.Token, - }) - if err != nil { - return errToStatus(err), err - } + // file relative path + filePath := "" + + if file.IsDir { + basePath = filepath.Dir(basePath) + filePath = ifPath + } + + // set fs root to the shared file/folder + d.user.Fs = afero.NewBasePathFs(d.user.Fs, basePath) + + file, err = files.NewFileInfo(files.FileOptions{ + Fs: d.user.Fs, + Path: filePath, + Modify: d.user.Perm.Modify, + Expand: true, + Checker: d, + Token: link.Token, + }) + if err != nil { + return errToStatus(err), err } d.raw = file