Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
srvpro
Commits
86fffcae
Commit
86fffcae
authored
May 28, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remake challonge upload
parent
7fe9cd70
Pipeline
#13262
passed with stages
in 18 minutes and 3 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
28 deletions
+20
-28
ygopro-tournament.js
ygopro-tournament.js
+20
-28
No files found.
ygopro-tournament.js
View file @
86fffcae
...
@@ -16,6 +16,7 @@ const _ = require('underscore');
...
@@ -16,6 +16,7 @@ const _ = require('underscore');
_
.
str
=
require
(
'
underscore.string
'
);
_
.
str
=
require
(
'
underscore.string
'
);
_
.
mixin
(
_
.
str
.
exports
());
_
.
mixin
(
_
.
str
.
exports
());
const
loadJSON
=
require
(
'
load-json-file
'
).
sync
;
const
loadJSON
=
require
(
'
load-json-file
'
).
sync
;
const
axios
=
require
(
'
axios
'
);
const
auth
=
require
(
'
./ygopro-auth.js
'
);
const
auth
=
require
(
'
./ygopro-auth.js
'
);
...
@@ -24,10 +25,6 @@ config = settings.modules.tournament_mode;
...
@@ -24,10 +25,6 @@ config = settings.modules.tournament_mode;
challonge_config
=
settings
.
modules
.
challonge
;
challonge_config
=
settings
.
modules
.
challonge
;
ssl_config
=
settings
.
modules
.
http
.
ssl
;
ssl_config
=
settings
.
modules
.
http
.
ssl
;
let
challonge
;
if
(
challonge_config
.
enabled
)
{
challonge
=
require
(
'
challonge
'
).
createClient
(
challonge_config
.
options
);
}
const
_async
=
require
(
"
async
"
);
const
_async
=
require
(
"
async
"
);
const
os
=
require
(
"
os
"
);
const
os
=
require
(
"
os
"
);
const
PROCESS_COUNT
=
os
.
cpus
().
length
;
const
PROCESS_COUNT
=
os
.
cpus
().
length
;
...
@@ -138,8 +135,8 @@ const clearDecks = function (callback) {
...
@@ -138,8 +135,8 @@ const clearDecks = function (callback) {
},
callback
);
},
callback
);
}
}
const
UploadToChallonge
=
function
()
{
const
UploadToChallonge
=
async
function
()
{
if
(
!
challonge
)
{
if
(
!
challonge
_config
.
enabled
)
{
sendResponse
(
"
未开启Challonge模式。
"
);
sendResponse
(
"
未开启Challonge模式。
"
);
return
false
;
return
false
;
}
}
...
@@ -157,30 +154,25 @@ const UploadToChallonge = function () {
...
@@ -157,30 +154,25 @@ const UploadToChallonge = function () {
return
false
;
return
false
;
}
}
sendResponse
(
"
读取玩家列表完毕,共有
"
+
player_list
.
length
+
"
名玩家。
"
);
sendResponse
(
"
读取玩家列表完毕,共有
"
+
player_list
.
length
+
"
名玩家。
"
);
sendResponse
(
"
开始上传玩家列表至Challonge。
"
);
try
{
_async
.
each
(
player_list
,
(
player_name
,
done
)
=>
{
sendResponse
(
"
开始清空 Challonge 玩家列表。
"
);
sendResponse
(
"
正在上传玩家
"
+
player_name
+
"
至Challonge。
"
);
await
axios
.
delete
(
`https://api.challonge.com/v1/tournaments/
${
challonge_config
.
tournament_id
}
/participants/clear.json`
,
{
challonge
.
participants
.
create
({
params
:
{
id
:
challonge_config
.
tournament_id
,
api_key
:
challonge_config
.
options
.
apiKey
participant
:
{
name
:
player_name
},
callback
:
(
err
,
data
)
=>
{
if
(
err
)
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传失败:
"
+
err
.
text
);
}
else
{
if
(
data
.
participant
)
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传完毕,其Challonge ID是
"
+
data
.
participant
.
id
+
"
。
"
);
}
else
{
sendResponse
(
"
玩家
"
+
player_name
+
"
上传完毕。
"
);
}
}
done
();
}
}
});
});
},
(
err
)
=>
{
sendResponse
(
"
开始上传玩家列表至 Challonge。
"
);
for
(
const
chunk
of
_
.
chunk
(
player_list
,
10
))
{
sendResponse
(
`开始上传玩家
${
chunk
.
join
(
'
,
'
)}
至 Challonge。`
);
await
axios
.
post
(
`https://api.challonge.com/v1/tournaments/
${
challonge_config
.
tournament_id
}
/participants/bulk_add.json`
,
{
api_key
:
challonge_config
.
options
.
apiKey
,
participants
:
chunk
.
map
(
name
=>
({
name
})),
},
axiosPostConfig
);
}
sendResponse
(
"
玩家列表上传完成。
"
);
sendResponse
(
"
玩家列表上传完成。
"
);
});
}
catch
(
e
)
{
sendResponse
(
"
Challonge 上传失败:
"
+
e
.
message
);
}
return
true
;
return
true
;
}
}
...
@@ -338,7 +330,7 @@ async function requestListener(req, res) {
...
@@ -338,7 +330,7 @@ async function requestListener(req, res) {
return
;
return
;
}
}
res
.
writeHead
(
200
);
res
.
writeHead
(
200
);
const
result
=
UploadToChallonge
();
const
result
=
await
UploadToChallonge
();
res
.
end
(
u
.
query
.
callback
+
'
("操作完成。");
'
);
res
.
end
(
u
.
query
.
callback
+
'
("操作完成。");
'
);
}
}
else
{
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment