Skip to content

Commit

Permalink
sytle: try to comment runhook
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehunter9 committed Feb 27, 2025
1 parent a9f3328 commit 26c4b5f
Show file tree
Hide file tree
Showing 7 changed files with 568 additions and 596 deletions.
5 changes: 2 additions & 3 deletions packages/backend/http/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/tomasen/realip"

"github.com/filebrowser/filebrowser/v2/rules"
"github.com/filebrowser/filebrowser/v2/runner"
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/storage"
"github.com/filebrowser/filebrowser/v2/users"
Expand All @@ -17,7 +16,7 @@ import (
type handleFunc func(w http.ResponseWriter, r *http.Request, d *data) (int, error)

type data struct {
*runner.Runner
//*runner.Runner
settings *settings.Settings
server *settings.Server
store *storage.Storage
Expand Down Expand Up @@ -58,7 +57,7 @@ func handle(fn handleFunc, prefix string, store *storage.Storage, server *settin
}

status, err := fn(w, r, &data{
Runner: &runner.Runner{Enabled: server.EnableExec, Settings: settings},
//Runner: &runner.Runner{Enabled: server.EnableExec, Settings: settings},
store: store,
settings: settings,
server: server,
Expand Down
87 changes: 39 additions & 48 deletions packages/backend/http/paste.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,31 +341,15 @@ func driveBufferToFile(bufferFilePath string, targetPath string, mode os.FileMod
}

//fmt.Println("Going to write file!")
err = d.RunHook(func() error {
//fmt.Println("Opening ", bufferFilePath)
//bufferFile, err := os.Open(bufferFilePath)
//if err != nil {
// return err
//}
//defer bufferFile.Close()
//fmt.Println("Opened ", bufferFilePath)

//_, writeErr := writeFile(d.user.Fs, targetPath, bufferFile)
//if writeErr != nil {
// fmt.Println(writeErr)
// return writeErr
//}
err := ioCopyFileWithBuffer(bufferFilePath, "/data"+targetPath, 8*1024*1024)
if err != nil {
fmt.Println(err)
return err
}
//fmt.Println("Writer File done!")

//etag := fmt.Sprintf(`"%x%x"`, info.ModTime().UnixNano(), info.Size())
//w.Header().Set("ETag", etag)
return nil
}, "upload", targetPath, "", d.user)
//err = d.RunHook(func() error {
// err := ioCopyFileWithBuffer(bufferFilePath, "/data"+targetPath, 8*1024*1024)
// if err != nil {
// fmt.Println(err)
// return err
// }
// return nil
//}, "upload", targetPath, "", d.user)
err = ioCopyFileWithBuffer(bufferFilePath, "/data"+targetPath, 8*1024*1024)

if err != nil {
_ = d.user.Fs.RemoveAll(targetPath)
Expand Down Expand Up @@ -399,9 +383,10 @@ func resourceDriveDelete(fileCache FileCache, path string, ctx context.Context,
return errToStatus(err), err
}

err = d.RunHook(func() error {
return d.user.Fs.RemoveAll(path)
}, "delete", path, "", d.user)
//err = d.RunHook(func() error {
// return d.user.Fs.RemoveAll(path)
//}, "delete", path, "", d.user)
err = d.user.Fs.RemoveAll(path)

if err != nil {
return errToStatus(err), err
Expand Down Expand Up @@ -575,14 +560,15 @@ func cacheBufferToFile(bufferFilePath string, targetPath string, mode os.FileMod
newTargetPath := strings.Replace(targetPath, "AppData/", "appcache/", 1)
//fmt.Println(newTargetPath)
//fmt.Println("Going to write file!")
err = d.RunHook(func() error {
err := ioCopyFileWithBuffer(bufferFilePath, newTargetPath, 8*1024*1024)
if err != nil {
fmt.Println(err)
return err
}
return nil
}, "upload", targetPath, "", d.user)
//err = d.RunHook(func() error {
// err := ioCopyFileWithBuffer(bufferFilePath, newTargetPath, 8*1024*1024)
// if err != nil {
// fmt.Println(err)
// return err
// }
// return nil
//}, "upload", targetPath, "", d.user)
err = ioCopyFileWithBuffer(bufferFilePath, newTargetPath, 8*1024*1024)

if err != nil {
//_ = d.user.Fs.RemoveAll(targetPath)
Expand Down Expand Up @@ -654,12 +640,15 @@ func resourceCacheDelete(fileCache FileCache, path string, ctx context.Context,
// return errToStatus(err), err
//}

err := d.RunHook(func() error {
newTargetPath := strings.Replace(path, "AppData/", "appcache/", 1)
//fmt.Println(newTargetPath)
return os.RemoveAll(newTargetPath)
//return d.user.Fs.RemoveAll(path)
}, "delete", path, "", d.user)
//err := d.RunHook(func() error {
// newTargetPath := strings.Replace(path, "AppData/", "appcache/", 1)
// //fmt.Println(newTargetPath)
// return os.RemoveAll(newTargetPath)
// //return d.user.Fs.RemoveAll(path)
//}, "delete", path, "", d.user)

newTargetPath := strings.Replace(path, "AppData/", "appcache/", 1)
err := os.RemoveAll(newTargetPath)

if err != nil {
return errToStatus(err), err
Expand Down Expand Up @@ -1391,13 +1380,15 @@ func resourcePasteHandler(fileCache FileCache) handleFunc {
}

if same {
err = d.RunHook(func() error {
return pasteActionSameArch(r.Context(), action, srcType, src, dstType, dst, d, fileCache, override, rename, w, r)
}, action, src, dst, d.user)
//err = d.RunHook(func() error {
// return pasteActionSameArch(r.Context(), action, srcType, src, dstType, dst, d, fileCache, override, rename, w, r)
//}, action, src, dst, d.user)
err = pasteActionSameArch(r.Context(), action, srcType, src, dstType, dst, d, fileCache, override, rename, w, r)
} else {
err = d.RunHook(func() error {
return pasteActionDiffArch(r.Context(), action, srcType, src, dstType, dst, d, fileCache, w, r)
}, action, src, dst, d.user)
//err = d.RunHook(func() error {
// return pasteActionDiffArch(r.Context(), action, srcType, src, dstType, dst, d, fileCache, w, r)
//}, action, src, dst, d.user)
err = pasteActionDiffArch(r.Context(), action, srcType, src, dstType, dst, d, fileCache, w, r)
}
if errToStatus(err) == http.StatusRequestEntityTooLarge {
fmt.Fprintln(w, err.Error())
Expand Down
59 changes: 34 additions & 25 deletions packages/backend/http/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,10 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc {
return errToStatus(err), err
}

err = d.RunHook(func() error {
return d.user.Fs.RemoveAll(r.URL.Path)
}, "delete", r.URL.Path, "", d.user)
//err = d.RunHook(func() error {
// return d.user.Fs.RemoveAll(r.URL.Path)
//}, "delete", r.URL.Path, "", d.user)
err = d.user.Fs.RemoveAll(r.URL.Path)

if err != nil {
return errToStatus(err), err
Expand Down Expand Up @@ -573,16 +574,19 @@ func resourcePostHandler(fileCache FileCache) handleFunc {
}
}

err = d.RunHook(func() error {
info, writeErr := writeFile(d.user.Fs, r.URL.Path, r.Body)
if writeErr != nil {
return writeErr
}

etag := fmt.Sprintf(`"%x%x"`, info.ModTime().UnixNano(), info.Size())
w.Header().Set("ETag", etag)
return nil
}, "upload", r.URL.Path, "", d.user)
//err = d.RunHook(func() error {
// info, writeErr := writeFile(d.user.Fs, r.URL.Path, r.Body)
// if writeErr != nil {
// return writeErr
// }
//
// etag := fmt.Sprintf(`"%x%x"`, info.ModTime().UnixNano(), info.Size())
// w.Header().Set("ETag", etag)
// return nil
//}, "upload", r.URL.Path, "", d.user)
info, err := writeFile(d.user.Fs, r.URL.Path, r.Body)
etag := fmt.Sprintf(`"%x%x"`, info.ModTime().UnixNano(), info.Size())
w.Header().Set("ETag", etag)

if err != nil {
_ = d.user.Fs.RemoveAll(r.URL.Path)
Expand Down Expand Up @@ -610,16 +614,20 @@ var resourcePutHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
return http.StatusNotFound, nil
}

err = d.RunHook(func() error {
info, writeErr := writeFile(d.user.Fs, r.URL.Path, r.Body)
if writeErr != nil {
return writeErr
}
//err = d.RunHook(func() error {
// info, writeErr := writeFile(d.user.Fs, r.URL.Path, r.Body)
// if writeErr != nil {
// return writeErr
// }
//
// etag := fmt.Sprintf(`"%x%x"`, info.ModTime().UnixNano(), info.Size())
// w.Header().Set("ETag", etag)
// return nil
//}, "save", r.URL.Path, "", d.user)

etag := fmt.Sprintf(`"%x%x"`, info.ModTime().UnixNano(), info.Size())
w.Header().Set("ETag", etag)
return nil
}, "save", r.URL.Path, "", d.user)
info, err := writeFile(d.user.Fs, r.URL.Path, r.Body)
etag := fmt.Sprintf(`"%x%x"`, info.ModTime().UnixNano(), info.Size())
w.Header().Set("ETag", etag)

return errToStatus(err), err
})
Expand Down Expand Up @@ -670,9 +678,10 @@ func resourcePatchHandler(fileCache FileCache) handleFunc {
}

fmt.Println("Before patch action:", src, dst, action, override, rename)
err = d.RunHook(func() error {
return patchAction(r.Context(), action, src, dst, d, fileCache)
}, action, src, dst, d.user)
//err = d.RunHook(func() error {
// return patchAction(r.Context(), action, src, dst, d, fileCache)
//}, action, src, dst, d.user)
err = patchAction(r.Context(), action, src, dst, d, fileCache)

return errToStatus(err), err
})
Expand Down
Loading

0 comments on commit 26c4b5f

Please sign in to comment.