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,21 +47,30 @@ var withHashFile = func(fn handleFunc) handleFunc {
return errToStatus(err), err return errToStatus(err), err
} }
if file.IsDir { // share base path
// set fs root to the shared folder basePath := link.Path
d.user.Fs = afero.NewBasePathFs(d.user.Fs, filepath.Dir(link.Path))
file, err = files.NewFileInfo(files.FileOptions{ // file relative path
Fs: d.user.Fs, filePath := ""
Path: path,
Modify: d.user.Perm.Modify, if file.IsDir {
Expand: true, basePath = filepath.Dir(basePath)
Checker: d, filePath = ifPath
Token: link.Token, }
})
if err != nil { // set fs root to the shared file/folder
return errToStatus(err), err 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 d.raw = file