WIP: Connecter /admin/documents/upload à handleV1DocumentCreate

This commit is contained in:
Victor Lacasse-Beaudoin 2023-04-28 15:57:09 -04:00
parent fd3eebb68c
commit 07005c8753
3 changed files with 188 additions and 8 deletions

View file

@ -388,7 +388,11 @@ func handleV1DocumentCreate(c echo.Context) error {
form_file, err := c.FormFile("file")
if err != nil {
return err
log.Println(err)
return c.JSON(http.StatusBadRequest, map[string]interface{}{
"message": "Error during handleV1DocumentCreate's echo#Context.FormFile",
"error": err,
})
}
allowed := false
@ -729,13 +733,41 @@ func handleAdminDocumentsUpload(c echo.Context) error {
}
func handleAdminDocumentsUploadPOST(c echo.Context) error {
data := struct {
Message string
}{
Message: "Pas implémenté",
client, err := api.New("http", "localhost", viper.GetInt("server.port"), api.APIOptions{
KeyAuth: viper.GetBool("server.api.auth"),
Key: viper.GetString("server.api.key"),
BasicAuth: viper.GetBool("server.admin.auth"),
Username: viper.GetString("server.admin.username"),
Password: viper.GetString("server.admin.password"),
})
if err != nil {
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
}
return c.Render(http.StatusOK, "admin-upload-html", data)
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()})
}
/*
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.StatusOK, "admin-upload-html", struct{ Message string }{Message: response})
}
// CSS Handlers