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

11
main.go
View file

@ -64,12 +64,10 @@ 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, "/")
if urlExist("/" + urlItem[2]) {
secret := r.URL.Query().Get("secret") secret := r.URL.Query().Get("secret")
if secret == db.HGet(ctx, "/"+urlItem[2], "secret").Val() { if secret == db.HGet(ctx, path, "secret").Val() {
err := db.Del(ctx, "/"+urlItem[2]) err := db.Del(ctx, path)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
@ -80,9 +78,6 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
} else { } else {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
} else {
w.WriteHeader(http.StatusMethodNotAllowed)
}
} }
} }