Commit e8db339b authored by nanahira's avatar nanahira

fix formidable version and somehow rework tournament.js

parent 1d606a2c
Pipeline #11150 canceled with stages
in 2 minutes and 7 seconds
......@@ -14,7 +14,7 @@
"bunyan": "^1.8.14",
"challonge": "^2.2.0",
"deepmerge": "^4.2.2",
"formidable": "^2.0.1",
"formidable": "^1.2.6",
"geoip-country-lite": "^1.0.0",
"jszip": "^3.5.0",
"load-json-file": "^6.2.0",
......@@ -169,11 +169,6 @@
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
},
"node_modules/asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
},
"node_modules/asn1": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
......@@ -723,15 +718,6 @@
"node": ">=0.10"
}
},
"node_modules/dezalgo": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz",
"integrity": "sha1-f3Qt4Gb8dIvI24IFad3c5Jvw1FY=",
"dependencies": {
"asap": "^2.0.0",
"wrappy": "1"
}
},
"node_modules/dotenv": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
......@@ -892,30 +878,14 @@
}
},
"node_modules/formidable": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.0.1.tgz",
"integrity": "sha512-rjTMNbp2BpfQShhFbR3Ruk3qk2y9jKpvMW78nJgx8QKtxjDVrwbZG+wvDOmVbifHyOUOQJXxqEy6r0faRrPzTQ==",
"dependencies": {
"dezalgo": "1.0.3",
"hexoid": "1.0.0",
"once": "1.4.0",
"qs": "6.9.3"
},
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.6.tgz",
"integrity": "sha512-KcpbcpuLNOwrEjnbpMC0gS+X8ciDoZE1kkqzat4a8vrprf+s9pKNQ/QIwWfbfs4ltgmFl3MD177SNTkve3BwGQ==",
"deprecated": "Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau",
"funding": {
"url": "https://ko-fi.com/tunnckoCore/commissions"
}
},
"node_modules/formidable/node_modules/qs": {
"version": "6.9.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.3.tgz",
"integrity": "sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw==",
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/fs-minipass": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz",
......@@ -1118,14 +1088,6 @@
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
},
"node_modules/hexoid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",
"integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==",
"engines": {
"node": ">=8"
}
},
"node_modules/highlight.js": {
"version": "9.18.3",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.18.3.tgz",
......@@ -3188,11 +3150,6 @@
}
}
},
"asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
},
"asn1": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
......@@ -3594,15 +3551,6 @@
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
"integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups="
},
"dezalgo": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz",
"integrity": "sha1-f3Qt4Gb8dIvI24IFad3c5Jvw1FY=",
"requires": {
"asap": "^2.0.0",
"wrappy": "1"
}
},
"dotenv": {
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
......@@ -3727,22 +3675,9 @@
}
},
"formidable": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.0.1.tgz",
"integrity": "sha512-rjTMNbp2BpfQShhFbR3Ruk3qk2y9jKpvMW78nJgx8QKtxjDVrwbZG+wvDOmVbifHyOUOQJXxqEy6r0faRrPzTQ==",
"requires": {
"dezalgo": "1.0.3",
"hexoid": "1.0.0",
"once": "1.4.0",
"qs": "6.9.3"
},
"dependencies": {
"qs": {
"version": "6.9.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.9.3.tgz",
"integrity": "sha512-EbZYNarm6138UKKq46tdx08Yo/q9ZhFoAXAI1meAFd2GtbRDhbZY2WQSICskT0c5q99aFzLG1D4nvTk9tqfXIw=="
}
}
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.6.tgz",
"integrity": "sha512-KcpbcpuLNOwrEjnbpMC0gS+X8ciDoZE1kkqzat4a8vrprf+s9pKNQ/QIwWfbfs4ltgmFl3MD177SNTkve3BwGQ=="
},
"fs-minipass": {
"version": "1.2.7",
......@@ -3908,11 +3843,6 @@
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
},
"hexoid": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",
"integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g=="
},
"highlight.js": {
"version": "9.18.3",
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-9.18.3.tgz",
......
......@@ -6,34 +6,34 @@
不带参数运行时,会建立一个服务器,调用API执行对应操作
*/
var http = require('http');
var https = require('https');
var fs = require('fs');
var url = require('url');
var request = require('request');
var formidable = require('formidable');
var _ = require('underscore');
const http = require('http');
const https = require('https');
const fs = require('fs');
const url = require('url');
const request = require('request');
const formidable = require('formidable');
const _ = require('underscore');
_.str = require('underscore.string');
_.mixin(_.str.exports());
var loadJSON = require('load-json-file').sync;
const loadJSON = require('load-json-file').sync;
var auth = require('./ygopro-auth.js');
const auth = require('./ygopro-auth.js');
var settings = loadJSON('./config/config.json');
const settings = loadJSON('./config/config.json');
config = settings.modules.tournament_mode;
challonge_config = settings.modules.challonge;
ssl_config = settings.modules.http.ssl;
var challonge;
let challonge;
if (challonge_config.enabled) {
challonge = require('challonge').createClient(challonge_config.options);
}
let _async = require("async");
const _async = require("async");
const os = require("os");
const PROCESS_COUNT = os.cpus().length;
//http长连接
var responder;
let responder;
config.wallpapers=[""];
request({
......@@ -48,9 +48,9 @@ request({
}
else {
config.wallpapers=[];
for (var i in body.images) {
var wallpaper=body.images[i];
var img={
for (const i in body.images) {
const wallpaper=body.images[i];
const img={
"url": "http://s.cn.bing.net"+wallpaper.urlbase+"_768x1366.jpg",
"desc": wallpaper.copyright
}
......@@ -60,7 +60,7 @@ request({
});
//输出反馈信息,如有http长连接则输出到http,否则输出到控制台
var sendResponse = function(text) {
const sendResponse = function(text) {
text=""+text;
if (responder) {
text=text.replace(/\n/g,"<br>");
......@@ -72,10 +72,10 @@ var sendResponse = function(text) {
}
//读取指定卡组
var readDeck = function(deck_name, deck_full_path) {
var deck={};
const readDeck = async function(deck_name, deck_full_path) {
const deck={};
deck.name=deck_name;
deck_text = fs.readFileSync(deck_full_path, { encoding: "ASCII" });
deck_text = await fs.promises.readFile(deck_full_path, { encoding: "ASCII" });
deck_array = deck_text.split("\n");
deck.main = [];
deck.extra = [];
......@@ -98,20 +98,19 @@ var readDeck = function(deck_name, deck_full_path) {
}
//读取指定文件夹中所有卡组
var getDecks = function(callback) {
var decks=[];
const getDecks = function(callback) {
const decks=[];
_async.auto({
readDir: (done) => {
fs.readdir(config.deck_path, done);
},
handleDecks: ["readDir", (results, done) => {
const decks_list = results.readDir;
_async.each(decks_list, (deck_name, _done) => {
_async.each(decks_list, async(deck_name) => {
if (_.endsWith(deck_name, ".ydk")) {
var deck = readDeck(deck_name, config.deck_path + deck_name);
const deck = await readDeck(deck_name, config.deck_path + deck_name);
decks.push(deck);
}
_done();
}, done)
}]
}, (err) => {
......@@ -120,14 +119,14 @@ var getDecks = function(callback) {
}
var delDeck = function (deck_name, callback) {
const delDeck = function (deck_name, callback) {
if (deck_name.startsWith("../") || deck_name.match(/\/\.\.\//)) { //security issue
callback("Invalid deck");
}
fs.unlink(config.deck_path + deck_name, callback);
}
var clearDecks = function (callback) {
const clearDecks = function (callback) {
_async.auto({
deckList: (done) => {
fs.readdir(config.deck_path, done);
......@@ -139,16 +138,16 @@ var clearDecks = function (callback) {
}, callback);
}
var UploadToChallonge = function () {
const UploadToChallonge = function () {
if (!challonge) {
sendResponse("未开启Challonge模式。");
return false;
}
sendResponse("开始读取玩家列表。");
var decks_list = fs.readdirSync(config.deck_path);
var player_list = [];
for (var k in decks_list) {
var deck_name = decks_list[k];
const decks_list = fs.readdirSync(config.deck_path);
const player_list = [];
for (const k in decks_list) {
const deck_name = decks_list[k];
if (_.endsWith(deck_name, ".ydk")) {
player_list.push(deck_name.slice(0, deck_name.length - 4));
}
......@@ -185,11 +184,11 @@ var UploadToChallonge = function () {
return true;
}
var receiveDecks = function(files, callback) {
var result = [];
_async.eachSeries(files, (file, done) => {
const receiveDecks = function(files, callback) {
const result = [];
_async.eachSeries(files, async(file) => {
if (_.endsWith(file.name, ".ydk")) {
var deck = readDeck(file.name, file.path);
const deck = await readDeck(file.name, file.path);
if (deck.main.length >= 40) {
fs.createReadStream(file.path).pipe(fs.createWriteStream(config.deck_path + file.name));
result.push({
......@@ -210,7 +209,6 @@ var receiveDecks = function(files, callback) {
status: "不是卡组文件"
});
}
done();
}, (err) => {
callback(err, result);
});
......@@ -218,7 +216,7 @@ var receiveDecks = function(files, callback) {
//建立一个http服务器,接收API操作
async function requestListener(req, res) {
var u = url.parse(req.url, true);
const u = url.parse(req.url, true);
/*if (u.query.password !== config.password) {
res.writeHead(403);
......@@ -232,15 +230,17 @@ async function requestListener(req, res) {
res.end("Auth Failed.");
return;
}
var form = new formidable.IncomingForm();
const form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files) {
receiveDecks(files, (err, result) => {
if (err) {
res.writeHead(200, {
console.error(`Upload error: ${err}`);
res.writeHead(500, {
"Access-Control-Allow-origin": "*",
'content-type': 'text/plain'
});
res.end(err.toString());
res.end(JSON.stringify({error: err.toString()}));
return;
}
res.writeHead(200, {
"Access-Control-Allow-origin": "*",
......@@ -338,7 +338,7 @@ async function requestListener(req, res) {
return;
}
res.writeHead(200);
var result=UploadToChallonge();
const result = UploadToChallonge();
res.end(u.query.callback+'("操作完成。");');
}
else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment