tAdd support for DELETE method - partage - File upload system
(HTM) git clone git://git.z3bra.org/partage.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 4185f727c86a012f0af6fbd236a84d7d5f3d1b85
(DIR) parent 8b1ccbbe8b147f2eaa1ada97913bc43f494aa121
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Mon, 28 Nov 2022 10:49:13 +0100
Add support for DELETE method
Diffstat:
M partage.go | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/partage.go b/partage.go
t@@ -243,12 +243,35 @@ func uploaderGet(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, conf.rootdir+filename)
}
+func uploaderDelete(w http.ResponseWriter, r *http.Request) {
+ // r.URL.Path is sanitized regarding "." and ".."
+ filename := r.URL.Path
+ filepath := conf.filepath + filename
+
+ if verbose {
+ log.Printf("Deleting file %s", filepath)
+ }
+
+ f, err := os.Open(filepath)
+ if err != nil {
+ http.NotFound(w, r)
+ return
+ }
+ f.Close()
+
+ // Force file expiration
+ writemeta(filepath, 0)
+ w.WriteHeader(http.StatusNoContent)
+}
+
func uploader(w http.ResponseWriter, r *http.Request) {
if verbose {
log.Printf("%s: <%s> %s %s %s", r.Host, r.RemoteAddr, r.Method, r.RequestURI, r.Proto)
}
switch r.Method {
+ case "DELETE":
+ uploaderDelete(w, r)
case "POST":
uploaderPost(w, r)
case "PUT":