diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-07-03 20:47:07 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-07-03 20:47:07 +0300 |
| commit | e591e24c3299266eeb65b9de3efe89a2d0addbdc (patch) | |
| tree | 69b2850f75ac1b2227523814525bbc544a96f75b /backend/controllers | |
| parent | fix: parser actually works now (#42) (diff) | |
| download | lphub-e591e24c3299266eeb65b9de3efe89a2d0addbdc.tar.gz lphub-e591e24c3299266eeb65b9de3efe89a2d0addbdc.tar.bz2 lphub-e591e24c3299266eeb65b9de3efe89a2d0addbdc.zip | |
fix: cleanup post record, uuid file saving, defer file delete (#42)
Former-commit-id: b98bc4164983e6f78566f0a7dd296e7f9cfd9e3e
Diffstat (limited to 'backend/controllers')
| -rw-r--r-- | backend/controllers/recordController.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index 1c0f3b2..4673683 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go | |||
| @@ -94,12 +94,13 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 94 | for i, header := range demoFiles { | 94 | for i, header := range demoFiles { |
| 95 | uuid := uuid.New().String() | 95 | uuid := uuid.New().String() |
| 96 | // Upload & insert into demos | 96 | // Upload & insert into demos |
| 97 | err = c.SaveUploadedFile(header, "backend/parser/"+header.Filename) | 97 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid) |
| 98 | if err != nil { | 98 | if err != nil { |
| 99 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 99 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 100 | return | 100 | return |
| 101 | } | 101 | } |
| 102 | f, err := os.Open("backend/parser/" + header.Filename) | 102 | defer os.Remove("backend/parser/" + uuid) |
| 103 | f, err := os.Open("backend/parser/" + uuid) | ||
| 103 | if err != nil { | 104 | if err != nil { |
| 104 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 105 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 105 | return | 106 | return |
| @@ -110,7 +111,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 110 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 111 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 111 | return | 112 | return |
| 112 | } | 113 | } |
| 113 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + header.Filename) | 114 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid) |
| 114 | if err != nil { | 115 | if err != nil { |
| 115 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 116 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 116 | return | 117 | return |
| @@ -128,7 +129,6 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 128 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 129 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 129 | return | 130 | return |
| 130 | } | 131 | } |
| 131 | os.Remove("backend/parser/" + header.Filename) | ||
| 132 | } | 132 | } |
| 133 | // Insert into records | 133 | // Insert into records |
| 134 | if isCoop { | 134 | if isCoop { |