mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-03-13 10:12:40 +08:00
fix (authorisation): add stats hook
This commit is contained in:
@@ -30,6 +30,7 @@ type IAuthentication interface {
|
||||
type IAuthorisation interface {
|
||||
Ls(ctx *App, path string) error
|
||||
Cat(ctx *App, path string) error
|
||||
Stat(ctx *App, path string) error
|
||||
Mkdir(ctx *App, path string) error
|
||||
Rm(ctx *App, path string) error
|
||||
Mv(ctx *App, from string, to string) error
|
||||
|
||||
@@ -216,8 +216,12 @@ func FileCat(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
for _, auth := range Hooks.Get.AuthorisationMiddleware() {
|
||||
if err = auth.Cat(ctx, path); err != nil {
|
||||
Log.Info("cat::auth '%s'", err.Error())
|
||||
if req.Method == http.MethodHead {
|
||||
if err = auth.Stat(ctx, path); err != nil {
|
||||
SendErrorResult(res, ErrNotAuthorized)
|
||||
return
|
||||
}
|
||||
} else if err = auth.Cat(ctx, path); err != nil {
|
||||
SendErrorResult(res, ErrNotAuthorized)
|
||||
return
|
||||
}
|
||||
@@ -405,7 +409,7 @@ func FileCat(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
header.Set("Accept-Ranges", "bytes")
|
||||
|
||||
if req.Method != "HEAD" {
|
||||
if req.Method != http.MethodHead {
|
||||
size := 32
|
||||
if thumb != "true" {
|
||||
switch Config.Get("general.buffer_size").String() {
|
||||
|
||||
@@ -44,6 +44,11 @@ func (this hookAuthorisation) Mv(ctx *App, from string, to string) error {
|
||||
}
|
||||
|
||||
func (this hookAuthorisation) Save(ctx *App, path string) error {
|
||||
processFileAction(ctx, map[string]string{"event": "stat", "path": path})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this hookAuthorisation) Stat(ctx *App, path string) error {
|
||||
processFileAction(ctx, map[string]string{"event": "save", "path": path})
|
||||
return nil
|
||||
}
|
||||
@@ -65,7 +70,7 @@ func (this *FileEventTrigger) Manifest() WorkflowSpecs {
|
||||
{
|
||||
Name: "event",
|
||||
Type: "text",
|
||||
Datalist: []string{"ls", "cat", "mkdir", "mv", "rm", "touch", "save"},
|
||||
Datalist: []string{"ls", "cat", "mkdir", "mv", "rm", "touch", "save", "stat"},
|
||||
MultiValue: true,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user