fix (authorisation): add stats hook

This commit is contained in:
MickaelK
2026-02-19 11:10:01 +11:00
parent 0c2648f8f9
commit 32d8f64e0c
3 changed files with 14 additions and 4 deletions

View File

@@ -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

View File

@@ -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() {

View File

@@ -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,
},
{