Skip to content

Commit

Permalink
New Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JarcauCristian committed Apr 16, 2024
1 parent 5267885 commit 925d07c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
25 changes: 17 additions & 8 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,29 +650,38 @@ func (minioInstance *MinIO) uploadFile(reader io.Reader, tags map[string]string,
return results, nil
}

func (minioInstance *MinIO) getDirectObject(datasetPath string) (*minio.Object, error) {
func (minioInstance *MinIO) getDirectObject(datasetPaths []string) (*minio.Object, error) {
healthyInstances, err := minioInstance.Healths()

if err != nil {
return &minio.Object{}, err
}

targetSite := strings.Split(datasetPath, "/")[0] + "//" + strings.Split(datasetPath, "/")[2]
find := false
for k := range healthyInstances {
if k == targetSite {
find = true
targetIndex := -1
targetString := ""
for i := range datasetPaths {
if find {
break
}
for k := range healthyInstances {
if k == strings.Split(datasetPaths[i], "/")[0]+"//"+strings.Split(datasetPaths[i], "/")[2] {
find = true
targetIndex = 0
targetString = strings.Split(datasetPaths[i], "/")[0] + "//" + strings.Split(datasetPaths[i], "/")[2]
break
}
}
}

if !find {
return nil, errors.New("could not find the target minio instance inside the healthy ones")
}

bucketName := strings.Split(datasetPath, "/")[3]
objectPath := strings.Join(strings.Split(datasetPath, "/")[4:], "/")
bucketName := strings.Split(datasetPaths[targetIndex], "/")[3]
objectPath := strings.Join(strings.Split(datasetPaths[0], "/")[4:], "/")

reader, err := minioInstance.clients[targetSite].GetObject(
reader, err := minioInstance.clients[targetString].GetObject(
context.Background(),
bucketName,
objectPath,
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,15 @@ func main() {
"message": "dataset_path parameter is required!",
})
} else {
data, err := minio.getDirectObject(datasetPath)
datasetPath = strings.Replace(datasetPath, "'", "\"", -1)
var datasetPaths []string

if err := json.Unmarshal([]byte(datasetPath), &datasetPaths); err != nil {
c.JSON(500, gin.H{"message": err.Error()})
return
}

data, err := minio.getDirectObject(datasetPaths)

if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
Expand Down

0 comments on commit 925d07c

Please sign in to comment.