@@ -5,10 +5,14 @@ import (
5
5
"github.com/Quaver/api2/config"
6
6
"github.com/Quaver/api2/db"
7
7
"github.com/Quaver/api2/enums"
8
+ "github.com/Quaver/api2/files"
9
+ "github.com/Quaver/api2/tools"
8
10
"github.com/Quaver/api2/webhooks"
9
11
"github.com/gin-gonic/gin"
10
12
"gorm.io/gorm"
11
13
"net/http"
14
+ "os"
15
+ "path/filepath"
12
16
"strconv"
13
17
"time"
14
18
)
@@ -120,13 +124,51 @@ func SubmitMapsetToRankingQueue(c *gin.Context) *APIError {
120
124
return APIErrorForbidden ("You cannot submit any more mapsets to the queue at this time." )
121
125
}
122
126
127
+ automodOk , err := downloadAndRunAutomod (mapset )
128
+
129
+ if err != nil {
130
+ return APIErrorServerError ("Error running automod" , err )
131
+ }
132
+
133
+ if ! automodOk {
134
+ return APIErrorBadRequest ("Your mapset has Auto Mod issues. Please fix them, then try again." )
135
+ }
136
+
123
137
if existingQueueMapset == nil {
124
138
return addMapsetToRankingQueue (c , mapset )
125
139
} else {
126
140
return resubmitMapsetToRankingQueue (c , existingQueueMapset )
127
141
}
128
142
}
129
143
144
+ // Runs the automod and returns an error if the mapset is good
145
+ func downloadAndRunAutomod (mapset * db.Mapset ) (bool , error ) {
146
+ archivePath , err := files .CacheMapset (mapset )
147
+
148
+ if err != nil {
149
+ return false , err
150
+ }
151
+
152
+ output , _ := filepath .Abs (fmt .Sprintf ("%v/%v" , files .GetTempDirectory (), time .Now ().UnixMilli ()))
153
+
154
+ if err := files .UnzipArchive (archivePath , output ); err != nil {
155
+ return false , err
156
+ }
157
+
158
+ automod , err := tools .RunAutoMod (output )
159
+
160
+ if err != nil {
161
+ return false , err
162
+ }
163
+
164
+ if automod .HasIssues {
165
+ return false , nil
166
+ }
167
+
168
+ _ = os .Remove (output )
169
+ return true , nil
170
+ }
171
+
130
172
// RemoveFromRankingQueue Allows a user to remove their mapset from the ranking queue (self deny)
131
173
// Endpoint: POST /v2/ranking/queue/:id/remove
132
174
func RemoveFromRankingQueue (c * gin.Context ) * APIError {
0 commit comments