feat: middle save
This commit is contained in:
parent
e1d0c5bc88
commit
8389114526
1 changed files with 0 additions and 73 deletions
|
@ -6,71 +6,9 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkAuth(ctx *gin.Context) (bool, error) {
|
|
||||||
privdir := service.NewPrivDirService(nil)
|
|
||||||
dirs, err := privdir.Query()
|
|
||||||
if err != nil {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, dir := range dirs {
|
|
||||||
if !strings.HasPrefix(ctx.Request.URL.Path, dir.DirName) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
auth := service.NewAuthService()
|
|
||||||
username, password, ok := ctx.Request.BasicAuth()
|
|
||||||
if !ok {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
ok, err = auth.VerifyToken(username, password)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var acc *service.Account
|
|
||||||
acc, err = auth.Read(username)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var path *service.PrivDir
|
|
||||||
privdir = service.NewPrivDirService(acc)
|
|
||||||
path, err = privdir.Read(dir.DirName)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if path == dir {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func readPath(ctx *gin.Context) {
|
func readPath(ctx *gin.Context) {
|
||||||
ok, err := checkAuth(ctx)
|
|
||||||
if err != nil {
|
|
||||||
ctx.Status(401)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
ctx.Status(401)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
worker := service.NewWorkerService()
|
worker := service.NewWorkerService()
|
||||||
path := ctx.Param("path")
|
path := ctx.Param("path")
|
||||||
|
|
||||||
|
@ -127,17 +65,6 @@ func readPath(ctx *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadPath(ctx *gin.Context) {
|
func downloadPath(ctx *gin.Context) {
|
||||||
ok, err := checkAuth(ctx)
|
|
||||||
if err != nil {
|
|
||||||
ctx.Status(401)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
ctx.Status(401)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
worker := service.NewWorkerService()
|
worker := service.NewWorkerService()
|
||||||
path := ctx.Param("path")
|
path := ctx.Param("path")
|
||||||
data, err := worker.Read(path)
|
data, err := worker.Read(path)
|
||||||
|
|
Loading…
Reference in a new issue