Commit de15fb02 authored by nanahira's avatar nanahira

fixes

parent 028febf3
...@@ -14,6 +14,7 @@ config.user.bak ...@@ -14,6 +14,7 @@ config.user.bak
/windbot /windbot
/decks /decks
/decks_save* /decks_save*
/deck_log
/replays /replays
/node_modules /node_modules
/ssl /ssl
......
...@@ -14,6 +14,7 @@ config.user.bak ...@@ -14,6 +14,7 @@ config.user.bak
/windbot /windbot
/decks /decks
/decks_save* /decks_save*
/deck_log
/replays /replays
/node_modules /node_modules
/ssl /ssl
......
...@@ -117,7 +117,7 @@ class Replay ...@@ -117,7 +117,7 @@ class Replay
@header == null ? false : @header.isTag @header == null ? false : @header.isTag
@fromFile: (filePath) -> @fromFile: (filePath) ->
Replay.fromBuffer fs.readFileSync filePath Replay.fromBuffer await fs.promises.readFile filePath
@fromBuffer: (buffer) -> @fromBuffer: (buffer) ->
reader = new ReplayReader buffer reader = new ReplayReader buffer
......
...@@ -175,8 +175,8 @@ ...@@ -175,8 +175,8 @@
}; };
} }
static fromFile(filePath) { static async fromFile(filePath) {
return Replay.fromBuffer(fs.readFileSync(filePath)); return Replay.fromBuffer((await fs.promises.readFile(filePath)));
} }
static fromBuffer(buffer) { static fromBuffer(buffer) {
......
...@@ -232,14 +232,22 @@ class DataManager { ...@@ -232,14 +232,22 @@ class DataManager {
return allDuelLogs.map(duelLog => duelLog.replayFileName); return allDuelLogs.map(duelLog => duelLog.replayFileName);
} }
async clearDuelLog() { async clearDuelLog() {
const repo = this.db.getRepository(DuelLog_1.DuelLog); //await this.db.transaction(async (mdb) => {
const runner = this.db.createQueryRunner();
try { try {
await repo.clear(); await runner.connect();
await runner.startTransaction();
await runner.query("SET FOREIGN_KEY_CHECKS = 0; ");
await runner.clearTable("duel_log_player");
await runner.clearTable("duel_log");
await runner.query("SET FOREIGN_KEY_CHECKS = 1; ");
await runner.commitTransaction();
} }
catch (e) { catch (e) {
await runner.rollbackTransaction();
this.log.warn(`Failed to clear duel logs: ${e.toString()}`); this.log.warn(`Failed to clear duel logs: ${e.toString()}`);
return [];
} }
//});
} }
async saveDuelLog(name, roomId, cloudReplayId, replayFilename, roomMode, duelCount, playerInfos) { async saveDuelLog(name, roomId, cloudReplayId, replayFilename, roomMode, duelCount, playerInfos) {
const duelLog = new DuelLog_1.DuelLog(); const duelLog = new DuelLog_1.DuelLog();
......
...@@ -262,13 +262,21 @@ export class DataManager { ...@@ -262,13 +262,21 @@ export class DataManager {
return allDuelLogs.map(duelLog => duelLog.replayFileName); return allDuelLogs.map(duelLog => duelLog.replayFileName);
} }
async clearDuelLog() { async clearDuelLog() {
const repo = this.db.getRepository(DuelLog); //await this.db.transaction(async (mdb) => {
try { const runner = this.db.createQueryRunner();
await repo.clear(); try {
} catch (e) { await runner.connect();
this.log.warn(`Failed to clear duel logs: ${e.toString()}`); await runner.startTransaction();
return []; await runner.query("SET FOREIGN_KEY_CHECKS = 0; ");
} await runner.clearTable("duel_log_player");
await runner.clearTable("duel_log");
await runner.query("SET FOREIGN_KEY_CHECKS = 1; ");
await runner.commitTransaction();
} catch (e) {
await runner.rollbackTransaction();
this.log.warn(`Failed to clear duel logs: ${e.toString()}`);
}
//});
} }
async saveDuelLog(name: string, roomId: number, cloudReplayId: number, replayFilename: string, roomMode: number, duelCount: number, playerInfos: DuelLogPlayerInfo[]) { async saveDuelLog(name: string, roomId: number, cloudReplayId: number, replayFilename: string, roomMode: number, duelCount: number, playerInfos: DuelLogPlayerInfo[]) {
const duelLog = new DuelLog(); const duelLog = new DuelLog();
......
...@@ -27,7 +27,7 @@ let DuelLog = class DuelLog { ...@@ -27,7 +27,7 @@ let DuelLog = class DuelLog {
getViewJSON(tournamentModeSettings) { getViewJSON(tournamentModeSettings) {
const data = { const data = {
id: this.id, id: this.id,
time: moment_1.default(this.time).format("YYYY-MM-DD HH-mm-ss"), time: moment_1.default(this.time).format("YYYY-MM-DD HH:mm:ss"),
name: this.name + (tournamentModeSettings.show_info ? " (Duel:" + this.duelCount + ")" : ""), name: this.name + (tournamentModeSettings.show_info ? " (Duel:" + this.duelCount + ")" : ""),
roomid: this.roomId, roomid: this.roomId,
cloud_replay_id: "R#" + this.cloudReplayId, cloud_replay_id: "R#" + this.cloudReplayId,
...@@ -42,6 +42,7 @@ let DuelLog = class DuelLog { ...@@ -42,6 +42,7 @@ let DuelLog = class DuelLog {
}; };
}) })
}; };
return data;
} }
}; };
__decorate([ __decorate([
......
...@@ -44,7 +44,7 @@ export class DuelLog { ...@@ -44,7 +44,7 @@ export class DuelLog {
getViewJSON(tournamentModeSettings: any) { getViewJSON(tournamentModeSettings: any) {
const data = { const data = {
id: this.id, id: this.id,
time: moment(this.time).format("YYYY-MM-DD HH-mm-ss"), time: moment(this.time).format("YYYY-MM-DD HH:mm:ss"),
name: this.name + (tournamentModeSettings.show_info ? " (Duel:" + this.duelCount + ")" : ""), name: this.name + (tournamentModeSettings.show_info ? " (Duel:" + this.duelCount + ")" : ""),
roomid: this.roomId, roomid: this.roomId,
cloud_replay_id: "R#" + this.cloudReplayId, cloud_replay_id: "R#" + this.cloudReplayId,
...@@ -59,5 +59,6 @@ export class DuelLog { ...@@ -59,5 +59,6 @@ export class DuelLog {
} }
}) })
} }
return data;
} }
} }
\ No newline at end of file
...@@ -426,6 +426,11 @@ ...@@ -426,6 +426,11 @@
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c="
}, },
"coffeescript": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.5.1.tgz",
"integrity": "sha512-J2jRPX0eeFh5VKyVnoLrfVFgLZtnnmp96WQSLAS8OrLm2wtQLcnikYKe1gViJKDH7vucjuhHvBKKBP3rKcD1tQ=="
},
"color-convert": { "color-convert": {
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
...@@ -1988,6 +1993,11 @@ ...@@ -1988,6 +1993,11 @@
} }
} }
}, },
"typescript": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz",
"integrity": "sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ=="
},
"ultron": { "ultron": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz",
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"axios": "^0.19.2", "axios": "^0.19.2",
"bunyan": "^1.8.14", "bunyan": "^1.8.14",
"challonge": "latest", "challonge": "latest",
"coffeescript": "^2.5.1",
"deepmerge": "latest", "deepmerge": "latest",
"formidable": "latest", "formidable": "latest",
"geoip-country-lite": "latest", "geoip-country-lite": "latest",
...@@ -32,12 +33,14 @@ ...@@ -32,12 +33,14 @@
"request": "latest", "request": "latest",
"sqlite3": "latest", "sqlite3": "latest",
"typeorm": "^0.2.29", "typeorm": "^0.2.29",
"typescript": "^4.0.5",
"underscore": "latest", "underscore": "latest",
"underscore.string": "latest", "underscore.string": "latest",
"ws": "^1.1.1" "ws": "^1.1.1"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
"scripts": { "scripts": {
"build": "coffee -c *.coffee && tsc",
"start": "node ygopro-server.js", "start": "node ygopro-server.js",
"tournament": "node ygopro-tournament.js", "tournament": "node ygopro-tournament.js",
"pre": "node ygopro-pre.js", "pre": "node ygopro-pre.js",
......
This diff is collapsed.
This diff is collapsed.
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