diff --git a/internal/media_storage/minio/minio.go b/internal/media_storage/minio/minio.go index 9f74643..f02e88f 100644 --- a/internal/media_storage/minio/minio.go +++ b/internal/media_storage/minio/minio.go @@ -11,8 +11,8 @@ import ( ) // Bucket names -var ( - RecipeImg string = "recipeimg" +const ( + recipeImgBucket string = "recipeimg" ) const location string = "eu_ru" @@ -65,7 +65,7 @@ func New(ctx context.Context, addr, user, password string) (*ObjStorage, error) // } // Upload file to bucket -func (o *ObjStorage) UploadFile(ctx context.Context, bucketName string, objectName string, fileBuffer io.Reader, contentType string, fileSize int64) error { +func (o *ObjStorage) uploadFile(ctx context.Context, bucketName string, objectName string, fileBuffer io.Reader, contentType string, fileSize int64) error { const op = "minio.UploadFile" // Upload the zip file with PutObject info, err := o.minio.PutObject(ctx, bucketName, objectName, fileBuffer, fileSize, minio.PutObjectOptions{ContentType: contentType}) @@ -77,7 +77,7 @@ func (o *ObjStorage) UploadFile(ctx context.Context, bucketName string, objectNa } // Get file from bucket -func (o *ObjStorage) GetFile(ctx context.Context, bucketName string, objectName string) (*minio.Object, error) { +func (o *ObjStorage) getFile(ctx context.Context, bucketName string, objectName string) (*minio.Object, error) { const op = "minio.GetFile" // Get object from minio minio_obj, err := o.minio.GetObject(ctx, bucketName, objectName, minio.GetObjectOptions{Checksum: true}) @@ -88,7 +88,7 @@ func (o *ObjStorage) GetFile(ctx context.Context, bucketName string, objectName } // Delete file from bucket -func (o *ObjStorage) DelFile(ctx context.Context, bucketName string, objectName string) error { +func (o *ObjStorage) delFile(ctx context.Context, bucketName string, objectName string) error { const op = "minio.DelFile" err := o.minio.RemoveObject(ctx, bucketName, objectName, minio.RemoveObjectOptions{ForceDelete: true}) if err != nil { @@ -96,3 +96,7 @@ func (o *ObjStorage) DelFile(ctx context.Context, bucketName string, objectName } return nil } + +func (o *ObjStorage) SaveRecipeImage(ctx context.Context) error { + o.uploadFile(ctx, recipeImgBucket) +} diff --git a/internal/parser/parser.go b/internal/parser/parser.go index df5ca23..1df0814 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -205,7 +205,7 @@ func GetRecipe(r *models.Recipe) error { // fmt.Printf("%+v\n", r) // fmt.Println("-------------------") // check recipe exists - ex, err := postgres.DB.RecipeExists(r.Title) + ex, err := postgres.DB.RecipeExists(r.Title) // interface! if err != nil || ex { return fmt.Errorf("%s: %w", op, fmt.Errorf("recipe already exists")) }