Retirer JSON de form création de document
Utiliser context#Render pour afficher une string Message à l'écran.
This commit is contained in:
parent
cc4ab5851d
commit
5d984ccacb
2 changed files with 29 additions and 23 deletions
|
@ -741,33 +741,39 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error {
|
|||
Password: viper.GetString("server.admin.password"),
|
||||
})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
||||
return c.Render(http.StatusInternalServerError, "admin-upload-html", struct{ Message string }{Message: fmt.Sprintf("handleAdminDocumentsUploadPOST#api.New: %s", err)})
|
||||
}
|
||||
|
||||
bucket := c.FormValue("bucket")
|
||||
|
||||
document, err := c.FormFile("document")
|
||||
if err != nil {
|
||||
//return c.JSON(http.StatusBadRequest, map[string]string{"message": "Error during file parse"})
|
||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Error during echo#Context.FormFile", "error": err.Error()})
|
||||
return c.Render(http.StatusBadRequest, "admin-upload-html", struct{ Message string }{Message: fmt.Sprintf("handleAdminDocumentsUploadPOST#c.FormFile: %s", err)})
|
||||
}
|
||||
|
||||
/*
|
||||
file, err := document.Open()
|
||||
if err != nil {
|
||||
//return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Error during file.Open()", "error": err.Error()})
|
||||
}
|
||||
defer file.Close()
|
||||
*/
|
||||
|
||||
response, err := client.UploadDocument(bucket, document)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Error duing api#client.UploadDocument", "error": err.Error()})
|
||||
//return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
||||
return c.Render(http.StatusInternalServerError, "admin-upload-html", struct{ Message string }{Message: fmt.Sprintf("handleAdminDocumentsUploadPOST#client.UploadDocument: %s", err)})
|
||||
}
|
||||
|
||||
return c.Render(http.StatusOK, "admin-upload-html", struct{ Message string }{Message: response})
|
||||
// Format response
|
||||
var message, info, status string
|
||||
|
||||
for key, value := range response {
|
||||
switch key {
|
||||
case "info":
|
||||
info_map, ok := value.(map[string]interface{})
|
||||
if ok {
|
||||
info = fmt.Sprintf("/public/documentation/%s/%s [%.2f]", info_map["bucket"], info_map["key"], info_map["size"])
|
||||
}
|
||||
case "message":
|
||||
status = fmt.Sprint(value)
|
||||
}
|
||||
}
|
||||
|
||||
message = fmt.Sprintf("%s - %s", status, info)
|
||||
|
||||
return c.Render(http.StatusOK, "admin-upload-html", struct{ Message string }{Message: message})
|
||||
}
|
||||
|
||||
// CSS Handlers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue