Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove metadata #26

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions db-connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
114 changes: 64 additions & 50 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@
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" {
Expand Down Expand Up @@ -337,75 +349,77 @@

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)

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
} else {
log.Printf("[DEBUG] Deleted file %s from Google cloud storage", fileId)

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
}

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)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}
*/
log.Printf("[INFO] Deleted file %s from database", fileId)

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
}

log.Printf("[INFO] Successfully deleted file %s for org %s", fileId, user.ActiveOrg.Id)
resp.WriteHeader(200)
Expand Down
Loading