From 6632e15816a8b651c353e7118a35b7add8027839 Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Sat, 29 Jul 2023 06:30:26 +0530 Subject: [PATCH 1/3] fix: fixing opensearch imports for comments https://github.com/Shuffle/Shuffle/issues/1016 --- db-connector.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/db-connector.go b/db-connector.go index 041e9fb..0b06912 100755 --- a/db-connector.go +++ b/db-connector.go @@ -5456,6 +5456,16 @@ func SetWorkflow(ctx context.Context, workflow Workflow, id string, optionalEdit workflow.Created = timeNow } + for actionIndex, _ := range workflow.Comments { + workflow.Comments[actionIndex].Position.X = float64(workflow.Comments[actionIndex].Position.X) + workflow.Comments[actionIndex].Position.Y = float64(workflow.Comments[actionIndex].Position.Y) + } + + for actionIndex, _ := range workflow.Actions { + workflow.Actions[actionIndex].Position.X = float64(workflow.Actions[actionIndex].Position.X) + workflow.Actions[actionIndex].Position.Y = float64(workflow.Actions[actionIndex].Position.Y) + } + if len(optionalEditedSecondsOffset) > 0 { workflow.Edited += int64(optionalEditedSecondsOffset[0]) } From 7a5471a483d3f8ba43d66723cfb37f30f7f664ff Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Tue, 1 Aug 2023 17:31:38 +0530 Subject: [PATCH 2/3] feat: remove metadata --- files.go | 114 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/files.go b/files.go index e54ff16..8427940 100755 --- a/files.go +++ b/files.go @@ -254,6 +254,18 @@ func HandleDeleteFile(resp http.ResponseWriter, request *http.Request) { return } + // read query parameter "remove_metadata" + removeMetadata := false + + removeMetadataQuery, ok := request.URL.Query()["remove_metadata"] + if ok && len(removeMetadataQuery) > 0 { + if removeMetadataQuery[0] == "true" { + log.Printf("[INFO] Remove metadata is true") + removeMetadata = true + } + } + + var fileId string location := strings.Split(request.URL.String(), "/") if location[1] == "api" { @@ -337,67 +349,68 @@ func HandleDeleteFile(resp http.ResponseWriter, request *http.Request) { if file.Status == "deleted" { log.Printf("[INFO] File with ID %s is already deleted.", fileId) - resp.WriteHeader(401) - resp.Write([]byte(`{"success": false}`)) - return - } - - if project.Environment == "cloud" || file.StorageArea == "google_storage" { - bucket := project.StorageClient.Bucket(orgFileBucket) - obj := bucket.Object(file.DownloadPath) - err := obj.Delete(ctx) - if err != nil { - log.Printf("[ERROR] FAILED to delete file %s from Google cloud storage. Removing frontend reference anyway. Err: %s", fileId, err) - } else { - log.Printf("[DEBUG] Deleted file %s from Google cloud storage", fileId) + if !(removeMetadata) { + resp.WriteHeader(401) + resp.Write([]byte(`{"success": false}`)) + return } - } else { - if fileExists(file.DownloadPath) { - err = os.Remove(file.DownloadPath) + if project.Environment == "cloud" || file.StorageArea == "google_storage" { + bucket := project.StorageClient.Bucket(orgFileBucket) + obj := bucket.Object(file.DownloadPath) + err := obj.Delete(ctx) if err != nil { - log.Printf("[ERROR] Failed deleting file locally: %s", err) - resp.WriteHeader(401) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed deleting filein path %s"}`, file.DownloadPath))) - return + log.Printf("[ERROR] FAILED to delete file %s from Google cloud storage. Removing frontend reference anyway. Err: %s", fileId, err) + } else { + log.Printf("[DEBUG] Deleted file %s from Google cloud storage", fileId) } - log.Printf("[INFO] Deleted file %s locally. Next is database.", file.DownloadPath) } else { - log.Printf("[ERROR] File doesn't exist. Can't delete. Should maybe delete file anyway?") - resp.WriteHeader(200) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "File in location %s doesn't exist"}`, file.DownloadPath))) + if fileExists(file.DownloadPath) { + err = os.Remove(file.DownloadPath) + if err != nil { + log.Printf("[ERROR] Failed deleting file locally: %s", err) + resp.WriteHeader(401) + resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed deleting filein path %s"}`, file.DownloadPath))) + return + } + + log.Printf("[INFO] Deleted file %s locally. Next is database.", file.DownloadPath) + } else { + log.Printf("[ERROR] File doesn't exist. Can't delete. Should maybe delete file anyway?") + resp.WriteHeader(200) + resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "File in location %s doesn't exist"}`, file.DownloadPath))) + return + } + } + file.Status = "deleted" + err = SetFile(ctx, *file) + if err != nil { + log.Printf("[ERROR] Failed setting file to deleted") + resp.WriteHeader(500) + resp.Write([]byte(`{"success": false, "reason": "Failed setting file to deleted"}`)) return } - } - - file.Status = "deleted" - err = SetFile(ctx, *file) - if err != nil { - log.Printf("[ERROR] Failed setting file to deleted") - resp.WriteHeader(500) - resp.Write([]byte(`{"success": false, "reason": "Failed setting file to deleted"}`)) - return - } - - outputFiles, err := FindSimilarFile(ctx, file.Md5sum, file.OrgId) - log.Printf("[INFO] Found %d similar files", len(outputFiles)) - if len(outputFiles) > 0 { - for _, item := range outputFiles { - item.Status = "deleted" - err = SetFile(ctx, item) - if err != nil { - log.Printf("[ERROR] Failed setting duplicate file %s to deleted", item.Id) + + outputFiles, err := FindSimilarFile(ctx, file.Md5sum, file.OrgId) + log.Printf("[INFO] Found %d similar files", len(outputFiles)) + if len(outputFiles) > 0 { + for _, item := range outputFiles { + item.Status = "deleted" + err = SetFile(ctx, item) + if err != nil { + log.Printf("[ERROR] Failed setting duplicate file %s to deleted", item.Id) + } } } + + nameKey := "Files" + DeleteCache(ctx, fmt.Sprintf("%s_%s_%s", nameKey, file.OrgId, file.Md5sum)) + DeleteCache(ctx, fmt.Sprintf("%s_%s", nameKey, file.OrgId)) } - nameKey := "Files" - DeleteCache(ctx, fmt.Sprintf("%s_%s_%s", nameKey, file.OrgId, file.Md5sum)) - DeleteCache(ctx, fmt.Sprintf("%s_%s", nameKey, file.OrgId)) - - /* - //Actually delete it? + if removeMetadata { + //Actually delete it err = DeleteKey(ctx, "files", fileId) if err != nil { log.Printf("Failed deleting file with ID %s: %s", fileId, err) @@ -405,7 +418,8 @@ func HandleDeleteFile(resp http.ResponseWriter, request *http.Request) { resp.Write([]byte(`{"success": false}`)) return } - */ + log.Printf("[INFO] Deleted file %s from database", fileId) + } log.Printf("[INFO] Successfully deleted file %s for org %s", fileId, user.ActiveOrg.Id) resp.WriteHeader(200) From a6b4db18a3f2f6a240f3a781b88568f2063b367b Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Tue, 1 Aug 2023 17:37:33 +0530 Subject: [PATCH 3/3] feat: remove unnecessary commit --- db-connector.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/db-connector.go b/db-connector.go index 0b06912..041e9fb 100755 --- a/db-connector.go +++ b/db-connector.go @@ -5456,16 +5456,6 @@ func SetWorkflow(ctx context.Context, workflow Workflow, id string, optionalEdit workflow.Created = timeNow } - for actionIndex, _ := range workflow.Comments { - workflow.Comments[actionIndex].Position.X = float64(workflow.Comments[actionIndex].Position.X) - workflow.Comments[actionIndex].Position.Y = float64(workflow.Comments[actionIndex].Position.Y) - } - - for actionIndex, _ := range workflow.Actions { - workflow.Actions[actionIndex].Position.X = float64(workflow.Actions[actionIndex].Position.X) - workflow.Actions[actionIndex].Position.Y = float64(workflow.Actions[actionIndex].Position.Y) - } - if len(optionalEditedSecondsOffset) > 0 { workflow.Edited += int64(optionalEditedSecondsOffset[0]) }