Skip to content

Commit

Permalink
Added one more instance
Browse files Browse the repository at this point in the history
  • Loading branch information
JarcauCristian committed Dec 31, 2023
1 parent 0588959 commit 6d71608
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
7 changes: 7 additions & 0 deletions configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@
"alias": "minio1",
"access_key": "c3VwZXI=",
"secret_key": "ZG9vcGVyc2VjcmV0"
},
{
"site": "https://minio-pi.sedimark.work",
"token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJwcm9tZXRoZXVzIiwic3ViIjoic3VwZXIiLCJleHAiOjQ4NDY0NzE1Mzh9.UrPgoKiZpRcgcZMvEdxUjyV_9mJkOayjydxgaaYUlE-wkJvGCbR1JJefGMQBQFu6gX3U41OBcP0r7ZGyhuGHgQ",
"alias": "minio2",
"access_key": "c3VwZXI=",
"secret_key": "ZG9vcGVyc2VjcmV0"
}
]
13 changes: 11 additions & 2 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func (minioInstance *MinIO) putObject(content []byte, fileName string, tags map[
return targetSite + "=" + object.Bucket + "=" + fileName, nil
}

func (minioInstance *MinIO) uploadFile(reader io.Reader, tags map[string]string, fileSize float64, fileName string, contentType string) (map[string]string, error) {
func (minioInstance *MinIO) uploadFile(reader io.Reader, tags map[string]string, fileSize float64, fileName string, contentType string, temporary bool) (map[string]string, error) {
if minioInstance.robinIndex == minioInstance.currentIndex-1 {
minioInstance.robinIndex = 0
}
Expand Down Expand Up @@ -622,9 +622,18 @@ func (minioInstance *MinIO) uploadFile(reader io.Reader, tags map[string]string,
}
minioInstance.robinIndex++
}

var bucketName string

if temporary {
bucketName = "temp"
} else {
bucketName = "dataspace"
}

object, err := minioInstance.clients[targetSite].PutObject(
context.Background(),
"dataspace",
bucketName,
fileName,
reader,
int64(fileSize),
Expand Down
13 changes: 8 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"mime/multipart"
"net/http"
"strconv"
"strings"
)

Expand Down Expand Up @@ -431,28 +432,28 @@ func main() {

tags, tagsExists := c.GetPostForm("tags")
fileName, fileNameExists := c.GetPostForm("name")
temporary, temporaryExists := c.GetPostForm("temporary")

var tagData map[string]interface{}

marshalError := json.Unmarshal([]byte(tags), &tagData)

fileSize := file.Size
contentType := file.Header["Content-Type"][0]
contentType := "application/octet-stream"

content, err := file.Open()
defer func(content multipart.File) {
err := content.Close()
if err != nil {
fmt.Println("Here")
c.JSON(500, gin.H{
"message": "Error closing the file!",
})
}
}(content)

if err != nil && !tagsExists && marshalError != nil && !fileNameExists {
if err != nil && !tagsExists && !temporaryExists && marshalError != nil && !fileNameExists {
c.JSON(400, gin.H{
"message": "File is empty!",
"message": "Please provide all the fields!",
})
}
reader := io.Reader(content)
Expand All @@ -462,7 +463,9 @@ func main() {
mapTags[k] = v.(string)
}

result, err := minio.uploadFile(reader, mapTags, float64(fileSize), fileName, contentType)
boolTemporary, _ := strconv.ParseBool(temporary)

result, err := minio.uploadFile(reader, mapTags, float64(fileSize), fileName, contentType, boolTemporary)
fmt.Println(result)

if err != nil {
Expand Down

0 comments on commit 6d71608

Please sign in to comment.