diff options
| -rw-r--r-- | backend/controllers/recordController.go | 13 | ||||
| -rw-r--r-- | backend/parser/parser.go | 13 |
2 files changed, 15 insertions, 11 deletions
diff --git a/backend/controllers/recordController.go b/backend/controllers/recordController.go index 28c55e0..1c0f3b2 100644 --- a/backend/controllers/recordController.go +++ b/backend/controllers/recordController.go | |||
| @@ -71,7 +71,10 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 71 | return | 71 | return |
| 72 | } | 72 | } |
| 73 | // Demo files | 73 | // Demo files |
| 74 | demoFiles := []*multipart.FileHeader{record.HostDemo, record.PartnerDemo} | 74 | demoFiles := []*multipart.FileHeader{record.HostDemo} |
| 75 | if isCoop { | ||
| 76 | demoFiles = append(demoFiles, record.PartnerDemo) | ||
| 77 | } | ||
| 75 | var hostDemoUUID, hostDemoFileID, partnerDemoUUID, partnerDemoFileID string | 78 | var hostDemoUUID, hostDemoFileID, partnerDemoUUID, partnerDemoFileID string |
| 76 | var hostDemoScoreCount, hostDemoScoreTime int | 79 | var hostDemoScoreCount, hostDemoScoreTime int |
| 77 | client := serviceAccount() | 80 | client := serviceAccount() |
| @@ -91,12 +94,12 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 91 | for i, header := range demoFiles { | 94 | for i, header := range demoFiles { |
| 92 | uuid := uuid.New().String() | 95 | uuid := uuid.New().String() |
| 93 | // Upload & insert into demos | 96 | // Upload & insert into demos |
| 94 | err = c.SaveUploadedFile(header, "backend/parser/demos/"+header.Filename) | 97 | err = c.SaveUploadedFile(header, "backend/parser/"+header.Filename) |
| 95 | if err != nil { | 98 | if err != nil { |
| 96 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 99 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 97 | return | 100 | return |
| 98 | } | 101 | } |
| 99 | f, err := os.Open("backend/parser/demos/" + header.Filename) | 102 | f, err := os.Open("backend/parser/" + header.Filename) |
| 100 | if err != nil { | 103 | if err != nil { |
| 101 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 104 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 102 | return | 105 | return |
| @@ -107,7 +110,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 107 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 110 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 108 | return | 111 | return |
| 109 | } | 112 | } |
| 110 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/demos/" + header.Filename) | 113 | hostDemoScoreCount, hostDemoScoreTime, err = parser.ProcessDemo("backend/parser/" + header.Filename) |
| 111 | if err != nil { | 114 | if err != nil { |
| 112 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 115 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 113 | return | 116 | return |
| @@ -125,7 +128,7 @@ func CreateRecordWithDemo(c *gin.Context) { | |||
| 125 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) | 128 | c.JSON(http.StatusBadRequest, models.ErrorResponse(err.Error())) |
| 126 | return | 129 | return |
| 127 | } | 130 | } |
| 128 | os.Remove("backend/parser/demos/" + header.Filename) | 131 | os.Remove("backend/parser/" + header.Filename) |
| 129 | } | 132 | } |
| 130 | // Insert into records | 133 | // Insert into records |
| 131 | if isCoop { | 134 | if isCoop { |
diff --git a/backend/parser/parser.go b/backend/parser/parser.go index 040b94a..562b8c0 100644 --- a/backend/parser/parser.go +++ b/backend/parser/parser.go | |||
| @@ -3,15 +3,17 @@ package parser | |||
| 3 | import ( | 3 | import ( |
| 4 | "bufio" | 4 | "bufio" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | "log" | ||
| 6 | "os/exec" | 7 | "os/exec" |
| 7 | "strconv" | 8 | "strconv" |
| 8 | "strings" | 9 | "strings" |
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | func ProcessDemo(demoPath string) (int, int, error) { | 12 | func ProcessDemo(demoPath string) (int, int, error) { |
| 12 | cmd := exec.Command("bash", "-c", fmt.Sprintf(`echo "FEXBash" && ./parser %s`, demoPath)) | 13 | cmd := exec.Command("bash", "-c", fmt.Sprintf(`echo "FEXBash" && ./backend/parser/parser %s`, demoPath)) |
| 13 | stdout, err := cmd.StdoutPipe() | 14 | stdout, err := cmd.StdoutPipe() |
| 14 | if err != nil { | 15 | if err != nil { |
| 16 | log.Println(err) | ||
| 15 | return 0, 0, err | 17 | return 0, 0, err |
| 16 | } | 18 | } |
| 17 | cmd.Start() | 19 | cmd.Start() |
| @@ -34,9 +36,8 @@ func ProcessDemo(demoPath string) (int, int, error) { | |||
| 34 | } | 36 | } |
| 35 | } | 37 | } |
| 36 | } | 38 | } |
| 37 | err = cmd.Wait() | 39 | cmd.Wait() |
| 38 | if err != nil { | 40 | // We don't check for error in wait, since FEXBash always gives segmentation fault |
| 39 | return 0, 0, err | 41 | // Wanted output is retrieved, so it's okay (i think) |
| 40 | } | 42 | return portalCount, cmTicks, nil |
| 41 | return cmTicks, portalCount, nil | ||
| 42 | } | 43 | } |