diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-04-25 13:23:37 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-04-25 13:23:37 -0700 |
commit | 099d000119447708d7d0d0482758d352438fa7e5 (patch) | |
tree | f4386ae2ff25a5b6b15c2e6442d4c56705e8271e /system/api/handlers.go | |
parent | 7092fb8979869f3c09b364d454d8d8081bb7c0bc (diff) |
adding support for file upload type and API handler to fetch file info
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..b8b90df 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.StatusInternalServerError) + 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) +} |