Fix command runners for upload
parent
e92dbb4bb8
commit
c9f6ccc55c
|
@ -131,6 +131,13 @@ func tusPatchHandler() handleFunc {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if uploadOffset == 0 {
|
||||||
|
err = d.RunBeforeHook("upload", r.URL.Path, "", d.user)
|
||||||
|
if err != nil {
|
||||||
|
return errToStatus(err), err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
openFile, err := d.user.Fs.OpenFile(r.URL.Path, os.O_WRONLY|os.O_APPEND, files.PermFile)
|
openFile, err := d.user.Fs.OpenFile(r.URL.Path, os.O_WRONLY|os.O_APPEND, files.PermFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, fmt.Errorf("could not open file: %w", err)
|
return http.StatusInternalServerError, fmt.Errorf("could not open file: %w", err)
|
||||||
|
@ -150,6 +157,14 @@ func tusPatchHandler() handleFunc {
|
||||||
|
|
||||||
w.Header().Set("Upload-Offset", strconv.FormatInt(uploadOffset+bytesWritten, 10))
|
w.Header().Set("Upload-Offset", strconv.FormatInt(uploadOffset+bytesWritten, 10))
|
||||||
|
|
||||||
|
if bytesWritten < int64(d.Settings.Tus.ChunkSize) {
|
||||||
|
fmt.Printf("Final chunk detected (size: %d). Running after hook\n", bytesWritten)
|
||||||
|
err = d.RunAfterHook("upload", r.URL.Path, "", d.user)
|
||||||
|
if err != nil {
|
||||||
|
return errToStatus(err), err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return http.StatusNoContent, nil
|
return http.StatusNoContent, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,39 @@ type Runner struct {
|
||||||
*settings.Settings
|
*settings.Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunBeforeHooks and RunAfterHooks is used for the chunked upload since it cannot use the standard RunHook
|
||||||
|
func (r *Runner) RunBeforeHook(evt, path, dst string, user *users.User) error {
|
||||||
|
path = user.FullPath(path)
|
||||||
|
dst = user.FullPath(dst)
|
||||||
|
if r.Enabled {
|
||||||
|
if val, ok := r.Commands["before_"+evt]; ok {
|
||||||
|
for _, command := range val {
|
||||||
|
err := r.exec(command, "before_"+evt, path, dst, user)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Runner) RunAfterHook(evt, path, dst string, user *users.User) error {
|
||||||
|
path = user.FullPath(path)
|
||||||
|
dst = user.FullPath(dst)
|
||||||
|
if r.Enabled {
|
||||||
|
if val, ok := r.Commands["after_"+evt]; ok {
|
||||||
|
for _, command := range val {
|
||||||
|
err := r.exec(command, "after_"+evt, path, dst, user)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// RunHook runs the hooks for the before and after event.
|
// RunHook runs the hooks for the before and after event.
|
||||||
func (r *Runner) RunHook(fn func() error, evt, path, dst string, user *users.User) error {
|
func (r *Runner) RunHook(fn func() error, evt, path, dst string, user *users.User) error {
|
||||||
path = user.FullPath(path)
|
path = user.FullPath(path)
|
||||||
|
|
Loading…
Reference in New Issue