This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapReviewAPI.Script.txt
294 lines (261 loc) · 9.33 KB
/
MapReviewAPI.Script.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/**
* Component : MapReviewAPI, API for the server review system
*/
#Const Version "2021-05-26"
#Const ScriptName "Libs/Nadeo/TMNext/TrackMania/API/MapReviewAPI.Script.txt"
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Libraries
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Include "Libs/Nadeo/MenuLibs/Common/Manialink/ManiaView2.Script.txt" as MV
#Include "Libs/Nadeo/CommonLibs/Common/Http.Script.txt" as Http
#Include "Libs/Nadeo/TMNext/TrackMania/Config.Script.txt" as Config
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Constants
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
#Const C_Name "lib-map-review-api" //< Component name
#Const P "LibMapReviewAPI_" //< Prefix use to differentiate functions/variables in the script
#Const C_MapReviewUid_TOTD "totd"
#Const C_MapReviewUid_Royal "royal"
#Const C_API_MapReview "/api/token/map-review"
#Const C_RouteParameter_MapUid "MapUid"
#Const C_RouteParameter_MapReviewUid "MapReviewUid"
#Const C_QueryParameter_Offset "offset"
#Const C_QueryParameter_Length "length"
#Const C_QueryParameter_WithFeedback "withFeedback"
#Const C_QueryParameter_WithMapInfo "withMapInfo"
#Const C_Route_GetConnect "/:MapReviewUid/connect"
#Const C_Route_GetWaitingTime "/:MapReviewUid/waiting-time"
#Const C_Route_PostAddMapQueue "/:MapReviewUid/add-map-queue"
#Const C_Route_GetSubmittedMaps "/:MapReviewUid/submitted-map"
#Const C_Route_PostRemoveSubmittedMap "/:MapReviewUid/submitted-map/:MapUid"
#Const C_Headers [
"Accept" => "application/json",
"Content-Type" => "application/json"
]
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the component
*
* @return The component id
*/
Text Component() {
return MV::Component(
C_Name,
"""
""",
"""
#Const {{{P}}}C_API_MapReview {{{dump(C_API_MapReview)}}}
#Const {{{P}}}C_RouteParameter_MapUid {{{dump(C_RouteParameter_MapUid)}}}
#Const {{{P}}}C_RouteParameter_MapReviewUid {{{dump(C_RouteParameter_MapReviewUid)}}}
#Const {{{P}}}C_QueryParameter_Offset {{{dump(C_QueryParameter_Offset)}}}
#Const {{{P}}}C_QueryParameter_Length {{{dump(C_QueryParameter_Length)}}}
#Const {{{P}}}C_QueryParameter_WithFeedback {{{dump(C_QueryParameter_WithFeedback)}}}
#Const {{{P}}}C_QueryParameter_WithMapInfo {{{dump(C_QueryParameter_WithMapInfo)}}}
#Const {{{P}}}C_Route_GetConnect {{{dump(C_Route_GetConnect)}}}
#Const {{{P}}}C_Route_GetWaitingTime {{{dump(C_Route_GetWaitingTime)}}}
#Const {{{P}}}C_Route_PostAddMapQueue {{{dump(C_Route_PostAddMapQueue)}}}
#Const {{{P}}}C_Route_GetSubmittedMaps {{{dump(C_Route_GetSubmittedMaps)}}}
#Const {{{P}}}C_Route_PostRemoveSubmittedMap {{{dump(C_Route_PostRemoveSubmittedMap)}}}
#Const {{{P}}}C_Headers {{{dump(C_Headers)}}}
#Struct {{{P}}}K_HttpJoinLink {
Text joinLink;
Boolean starting;
Boolean noMap;
Integer submissionWaitTimer;
}
#Struct {{{P}}}K_JoinLink {
Text JoinLink;
Boolean Starting;
Boolean NoMap;
Integer SubmissionWaitTimer;
}
#Struct {{{P}}}K_HttpMap {
Text mapUid;
}
#Struct {{{P}}}K_HttpWaitingTime {
Integer seconds;
}
#Struct {{{P}}}K_HttpNoteInfo {
Integer countTotal;
Real average;
Integer countStar1;
Integer countStar2;
Integer countStar3;
Integer countStar4;
Integer countStar5;
Integer countStarMax;
}
#Struct {{{P}}}K_HttpSubmittedMapInfo {
Text uid;
Text mapId;
Text name;
Text author;
Text submitter;
Integer authorTime;
Integer goldTime;
Integer silverTime;
Integer bronzeTime;
Integer nbLaps;
Boolean valid;
Text downloadUrl;
Text thumbnailUrl;
Integer uploadTimestamp;
Integer updateTimestamp;
}
#Struct {{{P}}}K_HttpSubmittedMap {
Text mapUid;
Integer feedbackCount;
Integer creationTimestamp;
Integer creationDate;
Integer latestSubmissionTimestamp;
Boolean nominated;
Integer nadeoNote;
{{{P}}}K_HttpSubmittedMapInfo map;
{{{P}}}K_HttpNoteInfo noteInfo;
}
#Struct {{{P}}}K_HttpSubmittedMaps {
{{{P}}}K_HttpSubmittedMap[] submittedMaps;
Integer itemCount;
}
#Struct {{{P}}}K_NoteInfo {
Integer CountTotal;
Real Average;
}
#Struct {{{P}}}K_SubmittedMap {
Text Uid;
Text Name;
Text AuthorAccountId;
Text AuthorDisplayName;
Text DownloadUrl;
Text ThumbnailUrl;
Integer FeedbackCount;
{{{P}}}K_NoteInfo NoteInfo;
}
#Struct {{{P}}}K_SubmittedMaps {
{{{P}}}K_SubmittedMap[] MapList;
Integer ItemCount;
}
""",
"""
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Start a request to get the waiting time
*
* @return The request
*/
{{{Http::P}}}K_Request {{{P}}}GetWaitingTime(Text _MapReviewUid) {
declare Text Route = {{{Http::P}}}InjectRouteParameters({{{P}}}C_Route_GetWaitingTime, [{{{P}}}C_RouteParameter_MapReviewUid => _MapReviewUid]);
return {{{Http::P}}}CreateGet({{{Config::P}}}Get().APIBaseUrl^{{{P}}}C_API_MapReview^Route, {{{P}}}C_Headers);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Parse the response to the GetWaitingTime request
Integer {{{P}}}GetResponseFromGetWaitingTime({{{Http::P}}}K_Request _Request) {
declare {{{P}}}K_HttpWaitingTime HttpWaitingTime;
HttpWaitingTime.fromjson({{{Http::P}}}GetResult(_Request));
return HttpWaitingTime.seconds;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Start a request to connect to the server review
*
* @return The request
*/
{{{Http::P}}}K_Request {{{P}}}GetConnect(Text _MapReviewUid) {
declare Text Route = {{{Http::P}}}InjectRouteParameters({{{P}}}C_Route_GetConnect, [{{{P}}}C_RouteParameter_MapReviewUid => _MapReviewUid]);
return {{{Http::P}}}CreateGet({{{Config::P}}}Get().APIBaseUrl^{{{P}}}C_API_MapReview^Route, {{{P}}}C_Headers);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Start a request to post the map to the server review map queue
*
* @param _MapUid The Uid of the map to add
* Must be registered to the NadeoServices first !
*
* @return The request
*/
{{{Http::P}}}K_Request {{{P}}}PostAddMapQueue(Text _MapReviewUid, Text _MapUid) {
declare Text Route = {{{Http::P}}}InjectRouteParameters({{{P}}}C_Route_PostAddMapQueue, [{{{P}}}C_RouteParameter_MapReviewUid => _MapReviewUid]);
declare {{{P}}}K_HttpMap HttpMap = {{{P}}}K_HttpMap {
mapUid = _MapUid
};
return {{{Http::P}}}CreatePost({{{Config::P}}}Get().APIBaseUrl^{{{P}}}C_API_MapReview^Route, HttpMap.tojson(), {{{P}}}C_Headers);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Parse the response to the GetConnect or PostAddMapQueue request
{{{P}}}K_JoinLink {{{P}}}GetJoinLinkResponse({{{Http::P}}}K_Request _Request) {
declare {{{P}}}K_HttpJoinLink HttpJoinLink;
HttpJoinLink.fromjson({{{Http::P}}}GetResult(_Request));
return {{{P}}}K_JoinLink {
JoinLink = HttpJoinLink.joinLink,
Starting = HttpJoinLink.starting,
NoMap = HttpJoinLink.noMap,
SubmissionWaitTimer = HttpJoinLink.submissionWaitTimer
};
}
{{{P}}}K_JoinLink {{{P}}}GetResponseFromGetConnect({{{Http::P}}}K_Request _Request) {
return {{{P}}}GetJoinLinkResponse(_Request);
}
{{{P}}}K_JoinLink {{{P}}}GetResponseFromPostAddMapQueue({{{Http::P}}}K_Request _Request) {
return {{{P}}}GetJoinLinkResponse(_Request);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Start a request to get the list of maps submitted by the player
*
* @param _Offset The offset of the list to get
* @param _Length The length of the list to get
*
* @return The request
*/
{{{Http::P}}}K_Request {{{P}}}GetSubmittedMaps(Text _MapReviewUid, Integer _Offset, Integer _Length) {
declare Text Route = {{{Http::P}}}InjectRouteParameters({{{P}}}C_Route_GetSubmittedMaps, [{{{P}}}C_RouteParameter_MapReviewUid => _MapReviewUid]);
declare Text QueryString = {{{Http::P}}}CreateQueryString([
{{{P}}}C_QueryParameter_Offset => ""^_Offset,
{{{P}}}C_QueryParameter_Length => ""^_Length,
{{{P}}}C_QueryParameter_WithFeedback => "true",
{{{P}}}C_QueryParameter_WithMapInfo => "true"
]);
return {{{Http::P}}}CreateGet({{{Config::P}}}Get().APIBaseUrl^{{{P}}}C_API_MapReview^Route^QueryString, {{{P}}}C_Headers);
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Parse the response to the GetSubmittedMaps request
{{{P}}}K_SubmittedMaps {{{P}}}GetResponseFromGetSubmittedMaps({{{Http::P}}}K_Request _Request) {
declare {{{P}}}K_HttpSubmittedMaps HttpSubmittedMaps;
HttpSubmittedMaps.fromjson({{{Http::P}}}GetResult(_Request));
declare {{{P}}}K_SubmittedMap[] SubmittedMaps;
foreach (HttpSubmittedMap in HttpSubmittedMaps.submittedMaps) {
SubmittedMaps.add({{{P}}}K_SubmittedMap {
Uid = HttpSubmittedMap.map.uid,
Name = HttpSubmittedMap.map.name,
AuthorAccountId = HttpSubmittedMap.map.author,
DownloadUrl = HttpSubmittedMap.map.downloadUrl,
ThumbnailUrl = HttpSubmittedMap.map.thumbnailUrl,
FeedbackCount = HttpSubmittedMap.feedbackCount,
NoteInfo = {{{P}}}K_NoteInfo {
CountTotal = HttpSubmittedMap.noteInfo.countTotal,
Average = HttpSubmittedMap.noteInfo.average
}
});
}
return {{{P}}}K_SubmittedMaps {
MapList = SubmittedMaps,
ItemCount = HttpSubmittedMaps.itemCount
};
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Start a request to remove a submitted map from the server review
*
* @param _MapUid The Uid of the map to remove
*
* @return The request
*/
{{{Http::P}}}K_Request {{{P}}}PostRemoveSubmittedMapRequest(Text _MapReviewUid, Text _MapUid) {
declare Text Route = {{{Http::P}}}InjectRouteParameters(
{{{P}}}C_Route_PostRemoveSubmittedMap,
[
{{{P}}}C_RouteParameter_MapUid => _MapUid,
{{{P}}}C_RouteParameter_MapReviewUid => _MapReviewUid
]
);
return {{{Http::P}}}CreatePost({{{Config::P}}}Get().APIBaseUrl^{{{P}}}C_API_MapReview^Route, "", {{{P}}}C_Headers);
}
""",
[Http::Component(), Config::Component()],
[]
);
}