mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2024-04-21 12:32:08 +00:00
fix (home): user would redirect to the homepath without considering the path in the config
This commit is contained in:
@@ -23,7 +23,7 @@ func SessionGet(ctx App, res http.ResponseWriter, req *http.Request) {
|
||||
SendSuccessResult(res, r)
|
||||
return
|
||||
}
|
||||
home, err := model.GetHome(ctx.Backend)
|
||||
home, err := model.GetHome(ctx.Backend, ctx.Session["path"])
|
||||
if err != nil {
|
||||
SendSuccessResult(res, r)
|
||||
return
|
||||
@@ -58,7 +58,7 @@ func SessionAuthenticate(ctx App, res http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
home, err := model.GetHome(backend)
|
||||
home, err := model.GetHome(backend, ctx.Session["path"])
|
||||
if err != nil {
|
||||
SendErrorResult(res, err)
|
||||
return
|
||||
|
||||
+11
-4
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
. "github.com/mickael-kerjean/nuage/server/common"
|
||||
_ "github.com/mickael-kerjean/nuage/server/model/backend"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
|
||||
@@ -36,13 +37,19 @@ func NewBackend(ctx *App, conn map[string]string) (IBackend, error) {
|
||||
return Backend.Get(conn["type"]).Init(conn, ctx)
|
||||
}
|
||||
|
||||
func GetHome(b IBackend) (string, error) {
|
||||
func GetHome(b IBackend, base string) (string, error) {
|
||||
if obj, ok := b.(interface{ Home() (string, error) }); ok {
|
||||
return obj.Home()
|
||||
absolute, err := obj.Home()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if strings.HasPrefix(absolute, base) == false {
|
||||
return "", nil
|
||||
}
|
||||
return absolute[len(base):], nil
|
||||
}
|
||||
|
||||
_, err := b.Ls("/")
|
||||
return "", err
|
||||
return base, err
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user