Skip to content

Commit

Permalink
Modified some endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
JarcauCristian committed Jan 5, 2024
1 parent 803e36d commit c8125a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
17 changes: 13 additions & 4 deletions instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (minioInstance *MinIO) listPath(path string) ([]string, error) {
return files, nil
}

func (minioInstance *MinIO) findObject(datasetPath string) (string, error) {
func (minioInstance *MinIO) findObject(datasetPath string, forever bool) (string, error) {
healthyInstances, err := minioInstance.Healths()

if err != nil {
Expand Down Expand Up @@ -269,7 +269,7 @@ func (minioInstance *MinIO) findObject(datasetPath string) (string, error) {

wg.Wait()

shareUrl, err := minioInstance.getObject(findDataset, datasetPath)
shareUrl, err := minioInstance.getObject(findDataset, datasetPath, forever)

if err != nil {
return "", err
Expand Down Expand Up @@ -656,9 +656,18 @@ func (minioInstance *MinIO) uploadFile(reader io.Reader, tags map[string]string,
return result, nil
}

func (minioInstance *MinIO) getObject(url string, datasetPath string) (string, error) {
func (minioInstance *MinIO) getObject(url string, datasetPath string, forever bool) (string, error) {
path := fmt.Sprintf("%s/%s", minioInstance.aliases[url], datasetPath)
cmdArgs := []string{"./mc", "share", "download", "--expire", "10m", "--json", path}

var expirationTime string

if forever {
expirationTime = "1000000h"
} else {
expirationTime = "10m"
}

cmdArgs := []string{"./mc", "share", "download", "--expire", expirationTime, "--json", path}

cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
var stdout bytes.Buffer
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,20 @@ func main() {
r.GET("/get_object", func(c *gin.Context) {

datasetPath, exists := c.GetQuery("dataset_path")
forever, foreverExists := c.GetQuery("forever")

if !exists {
c.JSON(400, gin.H{
"message": "dataset_path parameter is required!",
})
} else if !foreverExists {
c.JSON(400, gin.H{
"message": "forever parameter is required!",
})
} else {
data, err := minio.findObject(datasetPath)
foreverBool, _ := strconv.ParseBool(forever)

data, err := minio.findObject(datasetPath, foreverBool)

if err != nil {
fmt.Println(err)
Expand Down

0 comments on commit c8125a4

Please sign in to comment.