From c8125a47be86efe5bf85632df3341f83803d97cb Mon Sep 17 00:00:00 2001 From: Jarcau Stefan-Cristian Date: Fri, 5 Jan 2024 19:40:43 +0200 Subject: [PATCH] Modified some endpoints --- instances.go | 17 +++++++++++++---- main.go | 9 ++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/instances.go b/instances.go index f7c077a..a1f2303 100644 --- a/instances.go +++ b/instances.go @@ -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 { @@ -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 @@ -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 diff --git a/main.go b/main.go index ae954b3..ef1287c 100644 --- a/main.go +++ b/main.go @@ -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)