Mettre à jour utilisation de models.Bucket et V1SeedResponse

This commit is contained in:
Victor Lacasse-Beaudoin 2023-08-19 19:58:09 -04:00
parent ab5ba6708c
commit 8dd0049fba
2 changed files with 21 additions and 17 deletions

View file

@ -444,7 +444,7 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error {
}
for bucketName, displayName := range buckets {
data.Buckets = append(data.Buckets, Bucket{
data.Buckets = append(data.Buckets, models.Bucket{
Name: bucketName,
DisplayName: displayName,
})
@ -467,7 +467,7 @@ func handleAdminDocumentsUploadPOST(c echo.Context) error {
// Format response
var info, status string
info = fmt.Sprintf("[%.0f] /public/documentation/%s/%s", response.Info.Size, response.Info.Bucket, response.Info.Object)
info = fmt.Sprintf("[%.0f] /public/documentation/%s/%s", response.Data.Size, response.Data.Bucket, response.Data.Object)
status = response.Message

View file

@ -7,6 +7,7 @@ import (
"git.agecem.com/agecem/agecem-org/config"
"git.agecem.com/agecem/agecem-org/media"
"git.agecem.com/agecem/agecem-org/models"
"github.com/labstack/echo/v4"
"github.com/minio/minio-go/v7"
"github.com/spf13/viper"
@ -25,34 +26,37 @@ func HandleV1(c echo.Context) error {
// HandleV1Seed créé des buckets dans minio selon la liste de buckets dans server.documents.buckets
// Les buckets sont créés avec paramètres par défaut, et sont ensuite visible dans /v1/bucket.
func HandleV1Seed(c echo.Context) error {
var response models.V1SeedResponse
mediaClient, err := media.NewMediaClientFromViper()
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Error during media.NewMediaClientFromViper()",
"error": err.Error(),
})
response.StatusCode = http.StatusInternalServerError
response.Message = "Error during media.NewMediaClientFromViper()"
response.Error = err.Error()
return c.JSON(response.StatusCode, response)
}
new_buckets, err := mediaClient.Seed()
response.Data.Buckets = new_buckets
if err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Error during mediaClient.Seed()",
"error": err.Error(),
})
response.StatusCode = http.StatusInternalServerError
response.Message = "Error during mediaClient.Seed()"
response.Error = err.Error()
return c.JSON(response.StatusCode, response)
}
var message string
if len(new_buckets) == 0 {
message = "All buckets already exist"
response.Message = "All buckets already exist"
} else {
message = "Buckets successfully created"
response.Message = "Buckets successfully created"
}
return c.JSON(http.StatusOK, map[string]interface{}{
"message": message,
"buckets": new_buckets,
})
response.StatusCode = http.StatusOK
return c.JSON(response.StatusCode, response)
}
// HandleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent.