Compare commits

..

2 commits

Author SHA1 Message Date
Akinimaginable
d28013ae89 Merge pull request 'add(backend): support paste deletion' (#7) from delete-paste into main
Reviewed-on: #7
2023-10-14 23:17:49 +00:00
Ada
61f6715be9 add(backend): support paste deletion 2023-10-12 21:46:30 +02:00

20
main.go
View file

@ -63,6 +63,26 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
} else {
w.WriteHeader(http.StatusMethodNotAllowed)
}
case "DELETE":
if strings.HasPrefix(path, "/delete") {
urlItem := strings.Split(path, "/")
if urlExist("/" + urlItem[2]) {
secret := r.URL.Query().Get("secret")
if secret == db.HGet(ctx, "/"+urlItem[2], "secret").Val() {
err := db.Del(ctx, "/"+urlItem[2])
if err != nil {
log.Println(err)
}
w.WriteHeader(http.StatusNoContent)
} else {
w.WriteHeader(http.StatusForbidden)
}
} else {
w.WriteHeader(http.StatusNotFound)
}
} else {
w.WriteHeader(http.StatusMethodNotAllowed)
}
}
}