summaryrefslogtreecommitdiff
path: root/system/admin/handlers.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-10-13 13:02:27 -0700
committerGitHub <noreply@github.com>2016-10-13 13:02:27 -0700
commit9c8ed5c6a88901bf139bf9bb7b884b222c6053ce (patch)
treea4aef6a41f4777ae037656820edefb80da62c03a /system/admin/handlers.go
parent7556e81dcf93c9f93c65aae46ceb871dd6f99812 (diff)
parent468d9fb3355bd7771af3592becb201b6e9b1e68b (diff)
Merge pull request #1 from bosssauce/ponzu-dev
[fundamental-feature] Delete Content
Diffstat (limited to 'system/admin/handlers.go')
-rw-r--r--system/admin/handlers.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index 2be8d8e..d492335 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -513,6 +513,37 @@ 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
+ }
+
+ err := req.ParseMultipartForm(1024 * 1024 * 4) // maxMemory 4MB
+ if err != nil {
+ res.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ id := req.FormValue("id")
+ t := req.FormValue("type")
+
+ if id == "" || t == "" {
+ res.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
+ err = db.DeleteContent(t + ":" + id)
+ if err != nil {
+ res.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ redir := strings.TrimSuffix(req.URL.Scheme+req.URL.Host+req.URL.Path, "/edit/delete")
+ redir = redir + "/posts?type=" + t
+ http.Redirect(res, req, redir, http.StatusFound)
+}
+
func editUploadHandler(res http.ResponseWriter, req *http.Request) {
if req.Method != http.MethodPost {
res.WriteHeader(http.StatusMethodNotAllowed)