(fileCache FileCache)
| 82 | }) |
| 83 | |
| 84 | func 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 | |
| 125 | func resourcePostHandler(fileCache FileCache) handleFunc { |
| 126 | return withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { |
no test coverage detected