diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-10-13 12:45:33 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-10-13 12:45:33 -0700 |
commit | 8d569ebc74b932fab0e1a725febddf92d43d2892 (patch) | |
tree | c5067e7fb74dbb9317ab4e12748b28044a9945e2 /system/admin | |
parent | 4dceec07d9f34018f70b15f795e4af27ff753dc3 (diff) |
adding admin server handler for deleting content
Diffstat (limited to 'system/admin')
-rw-r--r-- | system/admin/handlers.go | 25 | ||||
-rw-r--r-- | system/admin/server.go | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 2be8d8e..f7c3cca 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -513,6 +513,31 @@ func editHandler(res http.ResponseWriter, req *http.Request) { } } +func deleteHandler(res http.ResponseWriter, req *http.Request) { + if req.Method != http.MethodPost { + res.WriteHeader(http.StatusMethodNotAllowed) + return + } + + q := req.URL.Query() + id := q.Get("id") + t := q.Get("type") + + if id == "" || t == "" { + res.WriteHeader(http.StatusBadRequest) + return + } + + err := db.DeleteContent(t + ":" + i) + if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + redir := strings.TrimSuffix(req.URL.Scheme+req.URL.Host+req.URL.Path, "/delete") + http.Redirect(res, req, redir, http.StatusFound) +} + func editUploadHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { res.WriteHeader(http.StatusMethodNotAllowed) diff --git a/system/admin/server.go b/system/admin/server.go index 6f4a96e..b3b128d 100644 --- a/system/admin/server.go +++ b/system/admin/server.go @@ -25,6 +25,7 @@ func Run() { http.HandleFunc("/admin/posts/search", user.Auth(searchHandler)) http.HandleFunc("/admin/edit", user.Auth(editHandler)) + http.HandleFunc("/admin/edit/delete", user.Auth(deleteHandler)) http.HandleFunc("/admin/edit/upload", user.Auth(editUploadHandler)) pwd, err := os.Getwd() |