diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-05-01 01:51:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-01 01:51:46 -0500 |
commit | 8319420935c223e432bc4c386bd7d26b03f01b47 (patch) | |
tree | 8ebe1e3f0780f66530b723ce9b48f69ae664d764 /system/api/handlers.go | |
parent | 7092fb8979869f3c09b364d454d8d8081bb7c0bc (diff) | |
parent | 8a1d091a0c6d55dbd6c713b2240bee8550541e7b (diff) |
Merge pull request #137 from ponzu-cms/ponzu-dev
[core] adding file upload metadata type and API
Diffstat (limited to 'system/api/handlers.go')
-rw-r--r-- | system/api/handlers.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/system/api/handlers.go b/system/api/handlers.go index 83bbe43..0a9c177 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -194,3 +194,44 @@ func contentHandlerBySlug(res http.ResponseWriter, req *http.Request) { sendData(res, req, j) } + +func uploadsHandler(res http.ResponseWriter, req *http.Request) { + if req.Method != http.MethodGet { + res.WriteHeader(http.StatusMethodNotAllowed) + return + } + + slug := req.URL.Query().Get("slug") + if slug == "" { + res.WriteHeader(http.StatusBadRequest) + return + } + + upload, err := db.UploadBySlug(slug) + if err != nil { + log.Println("Error finding upload by slug:", slug, err) + res.WriteHeader(http.StatusNotFound) + return + } + + it := func() interface{} { + return new(item.FileUpload) + } + + push(res, req, it, upload) + + j, err := fmtJSON(json.RawMessage(upload)) + if err != nil { + log.Println("Error fmtJSON on upload:", err) + res.WriteHeader(http.StatusInternalServerError) + return + } + + j, err = omit(it(), j) + if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + sendData(res, req, j) +} |