diff options
| -rw-r--r-- | backend/handlers/logs.go | 14 | ||||
| -rw-r--r-- | backend/handlers/record.go | 11 |
2 files changed, 23 insertions, 2 deletions
diff --git a/backend/handlers/logs.go b/backend/handlers/logs.go index 0fef6a1..c971f79 100644 --- a/backend/handlers/logs.go +++ b/backend/handlers/logs.go | |||
| @@ -11,8 +11,9 @@ import ( | |||
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | const ( | 13 | const ( |
| 14 | LogTypeMod string = "Mod" | 14 | LogTypeMod string = "Mod" |
| 15 | LogTypeLogin string = "Login" | 15 | LogTypeLogin string = "Login" |
| 16 | LogTypeRecord string = "Record" | ||
| 16 | 17 | ||
| 17 | LogDescriptionLoginSuccess string = "Success" | 18 | LogDescriptionLoginSuccess string = "Success" |
| 18 | LogDescriptionLoginFailToken string = "TokenFail" | 19 | LogDescriptionLoginFailToken string = "TokenFail" |
| @@ -23,6 +24,15 @@ const ( | |||
| 23 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" | 24 | LogDescriptionMapSummaryEdit string = "MapSummaryEdit" |
| 24 | LogDescriptionMapSummaryEditImage string = "MapSummaryEditImage" | 25 | LogDescriptionMapSummaryEditImage string = "MapSummaryEditImage" |
| 25 | LogDescriptionMapSummaryDelete string = "MapSummaryDelete" | 26 | LogDescriptionMapSummaryDelete string = "MapSummaryDelete" |
| 27 | |||
| 28 | LogDescriptionRecordSuccess string = "Success" | ||
| 29 | LogDescriptionRecordFailInsertRecord string = "InsertRecordFail" | ||
| 30 | LogDescriptionRecordFailInsertDemo string = "InsertDemoFail" | ||
| 31 | LogDescriptionRecordFailProcessDemo string = "ProcessDemoFail" | ||
| 32 | LogDescriptionRecordFailCreateDemo string = "CreateDemoFail" | ||
| 33 | LogDescriptionRecordFailOpenDemo string = "OpenDemoFail" | ||
| 34 | LogDescriptionRecordFailSaveDemo string = "SaveDemoFail" | ||
| 35 | LogDescriptionRecordFailInvalidRequest string = "InvalidRequestFail" | ||
| 26 | ) | 36 | ) |
| 27 | 37 | ||
| 28 | type Log struct { | 38 | type Log struct { |
diff --git a/backend/handlers/record.go b/backend/handlers/record.go index 00c9b7d..3d29eb8 100644 --- a/backend/handlers/record.go +++ b/backend/handlers/record.go | |||
| @@ -66,6 +66,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 66 | return | 66 | return |
| 67 | } | 67 | } |
| 68 | if isDisabled { | 68 | if isDisabled { |
| 69 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | ||
| 69 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) | 70 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Map is not available for competitive boards.")) |
| 70 | return | 71 | return |
| 71 | } | 72 | } |
| @@ -75,10 +76,12 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 75 | // Get record request | 76 | // Get record request |
| 76 | var record RecordRequest | 77 | var record RecordRequest |
| 77 | if err := c.ShouldBind(&record); err != nil { | 78 | if err := c.ShouldBind(&record); err != nil { |
| 79 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | ||
| 78 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 80 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 79 | return | 81 | return |
| 80 | } | 82 | } |
| 81 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { | 83 | if isCoop && (record.PartnerDemo == nil || record.PartnerID == "") { |
| 84 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInvalidRequest) | ||
| 82 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid entry for coop record submission.")) | 85 | c.JSON(http.StatusBadRequest, models.ErrorResponse("Invalid entry for coop record submission.")) |
| 83 | return | 86 | return |
| 84 | } | 87 | } |
| @@ -108,23 +111,27 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 108 | // Upload & insert into demos | 111 | // Upload & insert into demos |
| 109 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") | 112 | err = c.SaveUploadedFile(header, "backend/parser/"+uuid+".dem") |
| 110 | if err != nil { | 113 | if err != nil { |
| 114 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailSaveDemo) | ||
| 111 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 115 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 112 | return | 116 | return |
| 113 | } | 117 | } |
| 114 | defer os.Remove("backend/parser/" + uuid + ".dem") | 118 | defer os.Remove("backend/parser/" + uuid + ".dem") |
| 115 | f, err := os.Open("backend/parser/" + uuid + ".dem") | 119 | f, err := os.Open("backend/parser/" + uuid + ".dem") |
| 116 | if err != nil { | 120 | if err != nil { |
| 121 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailOpenDemo) | ||
| 117 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 122 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 118 | return | 123 | return |
| 119 | } | 124 | } |
| 120 | defer f.Close() | 125 | defer f.Close() |
| 121 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) | 126 | file, err := createFile(srv, uuid+".dem", "application/octet-stream", f, os.Getenv("GOOGLE_FOLDER_ID")) |
| 122 | if err != nil { | 127 | if err != nil { |
| 128 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailCreateDemo) | ||
| 123 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 129 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 124 | return | 130 | return |
| 125 | } | 131 | } |
| 126 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") | 132 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + uuid + ".dem") |
| 127 | if err != nil { | 133 | if err != nil { |
| 134 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailProcessDemo) | ||
| 128 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 135 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 129 | return | 136 | return |
| 130 | } | 137 | } |
| @@ -138,6 +145,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 138 | _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) | 145 | _, err = tx.Exec(`INSERT INTO demos (id,location_id) VALUES ($1,$2)`, uuid, file.Id) |
| 139 | if err != nil { | 146 | if err != nil { |
| 140 | deleteFile(srv, file.Id) | 147 | deleteFile(srv, file.Id) |
| 148 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertDemo) | ||
| 141 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 149 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 142 | return | 150 | return |
| 143 | } | 151 | } |
| @@ -159,6 +167,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 159 | if err != nil { | 167 | if err != nil { |
| 160 | deleteFile(srv, hostDemoFileID) | 168 | deleteFile(srv, hostDemoFileID) |
| 161 | deleteFile(srv, partnerDemoFileID) | 169 | deleteFile(srv, partnerDemoFileID) |
| 170 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | ||
| 162 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 171 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 163 | return | 172 | return |
| 164 | } | 173 | } |
| @@ -176,6 +185,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 176 | _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, user.(models.User).SteamID, hostDemoUUID) | 185 | _, err := tx.Exec(sql, mapId, hostDemoScoreCount, hostDemoScoreTime, user.(models.User).SteamID, hostDemoUUID) |
| 177 | if err != nil { | 186 | if err != nil { |
| 178 | deleteFile(srv, hostDemoFileID) | 187 | deleteFile(srv, hostDemoFileID) |
| 188 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordFailInsertRecord) | ||
| 179 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 189 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 180 | return | 190 | return |
| 181 | } | 191 | } |
| @@ -192,6 +202,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 192 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) | 202 | c.JSON(http.StatusInternalServerError, models.ErrorResponse(err.Error())) |
| 193 | return | 203 | return |
| 194 | } | 204 | } |
| 205 | CreateLog(user.(models.User).SteamID, LogTypeRecord, LogDescriptionRecordSuccess) | ||
| 195 | c.JSON(http.StatusOK, models.Response{ | 206 | c.JSON(http.StatusOK, models.Response{ |
| 196 | Success: true, | 207 | Success: true, |
| 197 | Message: "Successfully created record.", | 208 | Message: "Successfully created record.", |