Skip to content
Snippets Groups Projects
Commit f860ea7f authored by Dean's avatar Dean
Browse files

add /upload/simple routes

parent 450e6e26
No related branches found
No related tags found
No related merge requests found
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.go]
indent_style = tab
indent_size = 8
tab_width = 8
......@@ -6,6 +6,7 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
......@@ -76,7 +77,7 @@ type fileWebhookRequest struct {
}
// UploadPomf handles Pomf multipart/form-data upload requests.
func UploadPomf(associateObjectsWithUser bool) func(http.ResponseWriter, *http.Request) {
func UploadPomf(associateObjectsWithUser bool, simpleResponse bool) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
// Only authorized users can use this route
user := middleware.GetAuthorizedUser(r)
......@@ -351,6 +352,15 @@ func UploadPomf(associateObjectsWithUser bool) func(http.ResponseWriter, *http.R
// Return response
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
render.JSON(w, r, fullResponse{Success: true, Files: fileResponses})
// Simple response
if simpleResponse {
for _, fResponse := range fileResponses {
w.Write([]byte(fmt.Sprintf("%s\n", fResponse.URL)))
}
} else {
render.JSON(w, r, fullResponse{Success: true, Files: fileResponses})
}
}
}
......@@ -174,8 +174,10 @@ func main() {
// Route handlers
r.Get("/shorten/polr", routes.ShortenPolr(false))
r.Get("/shorten/polr/associated", routes.ShortenPolr(true))
r.Post("/upload/pomf", routes.UploadPomf(false))
r.Post("/upload/pomf/associated", routes.UploadPomf(true))
r.Post("/upload/pomf", routes.UploadPomf(false, false))
r.Post("/upload/pomf/associated", routes.UploadPomf(true, false))
r.Post("/upload/simple", routes.UploadPomf(false, true))
r.Post("/upload/simple/associated", routes.UploadPomf(true, true))
r.Post("/users", routes.CreateUser)
r.Get("/users/me", routes.Me)
r.Get("/objects", routes.ListObjects)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment