add(backend): support paste deletion
This commit is contained in:
parent
d85ca37d54
commit
61f6715be9
1 changed files with 21 additions and 0 deletions
21
main.go
21
main.go
|
@ -32,6 +32,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
if urlExist(clearPath) {
|
if urlExist(clearPath) {
|
||||||
if strings.HasSuffix(path, "/raw") {
|
if strings.HasSuffix(path, "/raw") {
|
||||||
pasteContent := db.HGet(ctx, clearPath, "content").Val()
|
pasteContent := db.HGet(ctx, clearPath, "content").Val()
|
||||||
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
_, err := io.WriteString(w, pasteContent)
|
_, err := io.WriteString(w, pasteContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -62,6 +63,26 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue