From 7e1d72f4b4f210d4da94cda23e0e47d0b58da1d8 Mon Sep 17 00:00:00 2001 From: JarcauCristian Date: Tue, 16 Jan 2024 15:45:38 +0200 Subject: [PATCH] Modified new Endpoint --- instances.go | 11 +++++++++-- main.go | 12 +++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/instances.go b/instances.go index f976244..9de5ee3 100644 --- a/instances.go +++ b/instances.go @@ -548,7 +548,7 @@ func (minioInstance *MinIO) putObject(content []byte, fileName string, tags map[ return targetSite + "=" + object.Bucket + "=" + fileName, nil } -func (minioInstance *MinIO) deleteFile(datasetPath string) error { +func (minioInstance *MinIO) deleteFile(datasetPath string, temp bool) error { var mp map[string]interface{} healthyInstances, err := minioInstance.Healths() @@ -558,8 +558,15 @@ func (minioInstance *MinIO) deleteFile(datasetPath string) error { errorCounter := 0 + path := "" + if temp { + path = "temp/" + datasetPath + } else { + path = "dataspace/" + datasetPath + } + for _, v := range healthyInstances { - cmdArgs := []string{"./mc", "rm", "--recursive", v + "/" + datasetPath, "--json"} + cmdArgs := []string{"./mc", "rm", "--recursive", v + "/" + path, "--json"} cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) var stdout bytes.Buffer diff --git a/main.go b/main.go index fc0b71c..76c279a 100644 --- a/main.go +++ b/main.go @@ -566,13 +566,23 @@ func main() { }) } else { path, exists := c.GetQuery("path") + temporary, tempExists := c.GetQuery("temp") if !exists { c.JSON(400, gin.H{ "message": "Required parameter path not provided!", }) + return + } + + if !tempExists { + c.JSON(400, gin.H{ + "message": "Required parameter temp not provided!", + }) + return } else { - err := minio.deleteFile(path) + boolTemp, _ := strconv.ParseBool(temporary) + err := minio.deleteFile(path, boolTemp) if err != nil { c.JSON(500, gin.H{