refactor(backend): remove /delete for DELETE request

This commit is contained in:
Ada 2023-10-20 03:37:22 +02:00
parent 5e8f82c329
commit edc278f585

23
main.go
View file

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