MCPcopy
hub / github.com/filebrowser/filebrowser / resourceDeleteHandler

Function resourceDeleteHandler

http/resource.go:84–123  ·  view source on GitHub ↗
(fileCache FileCache)

Source from the content-addressed store, hash-verified

82})
83
84func resourceDeleteHandler(fileCache FileCache) handleFunc {
85 return withUser(func(_ http.ResponseWriter, r *http.Request, d *data) (int, error) {
86 if r.URL.Path == "/" || !d.user.Perm.Delete {
87 return http.StatusForbidden, nil
88 }
89
90 file, err := files.NewFileInfo(&files.FileOptions{
91 Fs: d.user.Fs,
92 Path: r.URL.Path,
93 Modify: d.user.Perm.Modify,
94 Expand: false,
95 ReadHeader: d.server.TypeDetectionByHeader,
96 Checker: d,
97 })
98 if err != nil {
99 return errToStatus(err), err
100 }
101
102 err = d.store.Share.DeleteWithPathPrefix(file.Path, d.user.ID)
103 if err != nil {
104 log.Printf("WARNING: Error(s) occurred while deleting associated shares with file: %s", err)
105 }
106
107 // delete thumbnails
108 err = delThumbs(r.Context(), fileCache, file)
109 if err != nil {
110 return errToStatus(err), err
111 }
112
113 err = d.RunHook(func() error {
114 return d.user.Fs.RemoveAll(r.URL.Path)
115 }, "delete", r.URL.Path, "", d.user)
116
117 if err != nil {
118 return errToStatus(err), err
119 }
120
121 return http.StatusNoContent, nil
122 })
123}
124
125func resourcePostHandler(fileCache FileCache) handleFunc {
126 return withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {

Callers 1

NewHandlerFunction · 0.85

Calls 7

NewFileInfoFunction · 0.92
withUserFunction · 0.85
errToStatusFunction · 0.85
delThumbsFunction · 0.85
RunHookMethod · 0.80
RemoveAllMethod · 0.80
DeleteWithPathPrefixMethod · 0.65

Tested by

no test coverage detected