Changer tous les minio.New -> media.NewMediaClientFromViper()
This commit is contained in:
parent
4f5b451042
commit
6352224b01
1 changed files with 25 additions and 41 deletions
|
@ -18,7 +18,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
@ -281,21 +280,18 @@ func handleV1Seed(c echo.Context) error {
|
||||||
|
|
||||||
// handleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent.
|
// handleV1BucketList affiche les buckets permis par server.documents.buckets, qui existent.
|
||||||
func handleV1BucketList(c echo.Context) error {
|
func handleV1BucketList(c echo.Context) error {
|
||||||
// Initialize minio client object
|
mediaClient, err := media.NewMediaClientFromViper()
|
||||||
client, err := minio.New(cfg.Server.Documents.Endpoint, &minio.Options{
|
|
||||||
Creds: credentials.NewStaticV4(cfg.Server.Documents.AccessKeyId, cfg.Server.Documents.SecretAccessKey, ""),
|
|
||||||
Secure: cfg.Server.Documents.UseSSL,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
"message": "Error during minio#New",
|
"message": "Error during media.NewMediaClientFromViper()",
|
||||||
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var buckets []string
|
var buckets []string
|
||||||
|
|
||||||
for _, bucket_name := range cfg.Server.Documents.Buckets {
|
for _, bucket_name := range cfg.Server.Documents.Buckets {
|
||||||
exists, err := client.BucketExists(context.Background(), bucket_name)
|
exists, err := mediaClient.MinioClient.BucketExists(context.Background(), bucket_name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
||||||
}
|
}
|
||||||
|
@ -331,18 +327,15 @@ func handleV1BucketRead(c echo.Context) error {
|
||||||
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Initialize minio client object
|
mediaClient, err := media.NewMediaClientFromViper()
|
||||||
client, err := minio.New(cfg.Server.Documents.Endpoint, &minio.Options{
|
|
||||||
Creds: credentials.NewStaticV4(cfg.Server.Documents.AccessKeyId, cfg.Server.Documents.SecretAccessKey, ""),
|
|
||||||
Secure: cfg.Server.Documents.UseSSL,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
"message": "Error during minio#New",
|
"message": "Error during media.NewMediaClientFromViper()",
|
||||||
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exists, err := client.BucketExists(ctx, bucket)
|
exists, err := mediaClient.MinioClient.BucketExists(ctx, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
||||||
}
|
}
|
||||||
|
@ -353,7 +346,7 @@ func handleV1BucketRead(c echo.Context) error {
|
||||||
|
|
||||||
var keys []string
|
var keys []string
|
||||||
|
|
||||||
objectCh := client.ListObjects(ctx, bucket, minio.ListObjectsOptions{})
|
objectCh := mediaClient.MinioClient.ListObjects(ctx, bucket, minio.ListObjectsOptions{})
|
||||||
for object := range objectCh {
|
for object := range objectCh {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
|
@ -394,14 +387,11 @@ func handleV1DocumentCreate(c echo.Context) error {
|
||||||
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Initialize minio client object
|
mediaClient, err := media.NewMediaClientFromViper()
|
||||||
client, err := minio.New(cfg.Server.Documents.Endpoint, &minio.Options{
|
|
||||||
Creds: credentials.NewStaticV4(cfg.Server.Documents.AccessKeyId, cfg.Server.Documents.SecretAccessKey, ""),
|
|
||||||
Secure: cfg.Server.Documents.UseSSL,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
"message": "Error during minio#New",
|
"message": "Error during media.NewMediaClientFromViper()",
|
||||||
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +408,7 @@ func handleV1DocumentCreate(c echo.Context) error {
|
||||||
|
|
||||||
filename_processed := reg.ReplaceAllString(form_file.Filename, "")
|
filename_processed := reg.ReplaceAllString(form_file.Filename, "")
|
||||||
|
|
||||||
info, err := client.PutObject(ctx, bucket, filename_processed, src, form_file.Size, minio.PutObjectOptions{
|
info, err := mediaClient.MinioClient.PutObject(ctx, bucket, filename_processed, src, form_file.Size, minio.PutObjectOptions{
|
||||||
ContentType: form_file.Header.Get("Content-Type"),
|
ContentType: form_file.Header.Get("Content-Type"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -462,18 +452,15 @@ func handleV1DocumentRead(c echo.Context) error {
|
||||||
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Initialize minio client object
|
mediaClient, err := media.NewMediaClientFromViper()
|
||||||
client, err := minio.New(cfg.Server.Documents.Endpoint, &minio.Options{
|
|
||||||
Creds: credentials.NewStaticV4(cfg.Server.Documents.AccessKeyId, cfg.Server.Documents.SecretAccessKey, ""),
|
|
||||||
Secure: cfg.Server.Documents.UseSSL,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
"message": "Error during minio#New",
|
"message": "Error during media.NewMediaClientFromViper()",
|
||||||
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket_exists, err := client.BucketExists(ctx, bucket)
|
bucket_exists, err := mediaClient.MinioClient.BucketExists(ctx, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
||||||
}
|
}
|
||||||
|
@ -482,7 +469,7 @@ func handleV1DocumentRead(c echo.Context) error {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
||||||
}
|
}
|
||||||
|
|
||||||
document_info, err := client.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "The specified key does not exist." {
|
if err.Error() == "The specified key does not exist." {
|
||||||
|
@ -497,7 +484,7 @@ func handleV1DocumentRead(c echo.Context) error {
|
||||||
|
|
||||||
_ = document_info
|
_ = document_info
|
||||||
|
|
||||||
document_object, err := client.GetObject(ctx, bucket, document, minio.GetObjectOptions{})
|
document_object, err := mediaClient.MinioClient.GetObject(ctx, bucket, document, minio.GetObjectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
"message": "Error during minio#GetObject",
|
"message": "Error during minio#GetObject",
|
||||||
|
@ -541,18 +528,15 @@ func handleV1DocumentDelete(c echo.Context) error {
|
||||||
|
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Initialize minio client object
|
mediaClient, err := media.NewMediaClientFromViper()
|
||||||
client, err := minio.New(cfg.Server.Documents.Endpoint, &minio.Options{
|
|
||||||
Creds: credentials.NewStaticV4(cfg.Server.Documents.AccessKeyId, cfg.Server.Documents.SecretAccessKey, ""),
|
|
||||||
Secure: cfg.Server.Documents.UseSSL,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
"message": "Error during minio#New",
|
"message": "Error during media.NewMediaClientFromViper()",
|
||||||
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket_exists, err := client.BucketExists(ctx, bucket)
|
bucket_exists, err := mediaClient.MinioClient.BucketExists(ctx, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
return c.JSON(http.StatusInternalServerError, "Error during minio#BucketExists")
|
||||||
}
|
}
|
||||||
|
@ -561,7 +545,7 @@ func handleV1DocumentDelete(c echo.Context) error {
|
||||||
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
|
||||||
}
|
}
|
||||||
|
|
||||||
document_info, err := client.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
document_info, err := mediaClient.MinioClient.StatObject(ctx, bucket, document, minio.StatObjectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "The specified key does not exist." {
|
if err.Error() == "The specified key does not exist." {
|
||||||
|
|
||||||
|
@ -576,7 +560,7 @@ func handleV1DocumentDelete(c echo.Context) error {
|
||||||
//TODO Add error validation
|
//TODO Add error validation
|
||||||
_ = document_info
|
_ = document_info
|
||||||
|
|
||||||
err = client.RemoveObject(ctx, bucket, document, minio.RemoveObjectOptions{})
|
err = mediaClient.MinioClient.RemoveObject(ctx, bucket, document, minio.RemoveObjectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{
|
return c.JSON(http.StatusInternalServerError, map[string]string{
|
||||||
"message": "Error during minio#RemoveObject",
|
"message": "Error during minio#RemoveObject",
|
||||||
|
|
Loading…
Reference in a new issue