fix: full file path on share

pull/1321/head
Ramires Viana 2021-03-12 12:14:58 +00:00
parent f8df76f526
commit e017a19985
1 changed files with 24 additions and 15 deletions

View File

@ -16,7 +16,7 @@ import (
var withHashFile = func(fn handleFunc) handleFunc { var withHashFile = func(fn handleFunc) handleFunc {
return func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { 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) link, err := d.store.Share.GetByHash(id)
if err != nil { if err != nil {
return errToStatus(err), err return errToStatus(err), err
@ -47,13 +47,23 @@ var withHashFile = func(fn handleFunc) handleFunc {
return errToStatus(err), err return errToStatus(err), err
} }
// share base path
basePath := link.Path
// file relative path
filePath := ""
if file.IsDir { if file.IsDir {
// set fs root to the shared folder basePath = filepath.Dir(basePath)
d.user.Fs = afero.NewBasePathFs(d.user.Fs, filepath.Dir(link.Path)) 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{ file, err = files.NewFileInfo(files.FileOptions{
Fs: d.user.Fs, Fs: d.user.Fs,
Path: path, Path: filePath,
Modify: d.user.Perm.Modify, Modify: d.user.Perm.Modify,
Expand: true, Expand: true,
Checker: d, Checker: d,
@ -62,7 +72,6 @@ var withHashFile = func(fn handleFunc) handleFunc {
if err != nil { if err != nil {
return errToStatus(err), err return errToStatus(err), err
} }
}
d.raw = file d.raw = file
return fn(w, r, d) return fn(w, r, d)