libroadcast-cli 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/cmd/push.js +102 -0
- package/dist/utils/commandHandler.js +3 -0
- package/dist/utils/help.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,6 +76,12 @@ Commands:
|
|
|
76
76
|
Options:
|
|
77
77
|
--rounds <roundsToFix> Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.
|
|
78
78
|
|
|
79
|
+
push <roundId> <PGNFromPathOrUrl> [--loop <intervalInSeconds>]
|
|
80
|
+
Upload a PGN file from a local path or URL to the specified broadcast round.
|
|
81
|
+
Note: The PGN file must be accessible from the provided path or URL.
|
|
82
|
+
Options:
|
|
83
|
+
--loop <intervalInSeconds> Continuously push the PGN file at the specified interval in seconds.
|
|
84
|
+
|
|
79
85
|
|
|
80
86
|
Examples:
|
|
81
87
|
# Login with your Lichess token (interactive)
|
|
@@ -100,4 +106,6 @@ Examples:
|
|
|
100
106
|
$ period bcast123 10
|
|
101
107
|
# Set custom scoring for all rounds in a broadcast
|
|
102
108
|
$ score bcast123 1.0 0.5 1.0 0.5
|
|
109
|
+
# Push a PGN file in loop mode every 60 seconds
|
|
110
|
+
$ push round456 /path/to/localfile.pgn --loop 60
|
|
103
111
|
```
|
package/dist/cmd/push.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pushCommand = void 0;
|
|
7
|
+
const node_process_1 = require("node:process");
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const commandHandler_1 = require("../utils/commandHandler");
|
|
11
|
+
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
12
|
+
const colors_1 = __importDefault(require("../utils/colors"));
|
|
13
|
+
const pushPGN = async (round, pgn) => {
|
|
14
|
+
try {
|
|
15
|
+
const res = await commandHandler_1.client
|
|
16
|
+
.POST("/api/broadcast/round/{broadcastRoundId}/push", {
|
|
17
|
+
params: {
|
|
18
|
+
path: { broadcastRoundId: round.id },
|
|
19
|
+
},
|
|
20
|
+
body: pgn,
|
|
21
|
+
bodySerializer: (body) => body,
|
|
22
|
+
})
|
|
23
|
+
.then((response) => response.data);
|
|
24
|
+
console.log(colors_1.default.green(`✓ Successfully pushed PGN for round ${colors_1.default.whiteBold(round.id)}.`));
|
|
25
|
+
console.table(res?.games.map((game, i) => {
|
|
26
|
+
return {
|
|
27
|
+
"Game #": i + 1,
|
|
28
|
+
"White Player": game.tags["White"] || "Unknown",
|
|
29
|
+
"Black Player": game.tags["Black"] || "Unknown",
|
|
30
|
+
Result: game.tags["Result"] || "Unknown",
|
|
31
|
+
"Ply Count": game.moves || "Unknown",
|
|
32
|
+
Error: game.error || "None",
|
|
33
|
+
};
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error(colors_1.default.red(`Error pushing PGN for round ${colors_1.default.whiteBold(round.id)}:`), error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const readPGNFromURL = async (pgnURL) => {
|
|
41
|
+
if (pgnURL.startsWith("http://") || pgnURL.startsWith("https://")) {
|
|
42
|
+
const response = await fetch(pgnURL);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
console.error(colors_1.default.red(`Failed to fetch PGN from URL: ${response.statusText}`));
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const pgnText = await response.text();
|
|
48
|
+
return pgnText;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const resolvedPath = node_path_1.default.resolve(pgnURL);
|
|
52
|
+
const stats = await (0, promises_1.readFile)(resolvedPath, { encoding: "utf-8" }).catch((err) => {
|
|
53
|
+
console.error(colors_1.default.red(`Failed to read PGN file: ${err.message}`));
|
|
54
|
+
return undefined;
|
|
55
|
+
});
|
|
56
|
+
if (!stats)
|
|
57
|
+
return undefined;
|
|
58
|
+
return stats.toString();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const loop = async (roundInfo, pgnPath, loopTimer) => {
|
|
62
|
+
while (true) {
|
|
63
|
+
const pgnContent = await readPGNFromURL(pgnPath);
|
|
64
|
+
if (pgnContent)
|
|
65
|
+
await pushPGN(roundInfo, pgnContent);
|
|
66
|
+
await (0, commandHandler_1.sleep)(loopTimer * 1000);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const pushCommand = async (args) => {
|
|
70
|
+
await (0, commandHandler_1.checkTokenScopes)();
|
|
71
|
+
const [roundId, pgnPath] = args.slice(0, 2);
|
|
72
|
+
if (!roundId || !pgnPath) {
|
|
73
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Round ID and PGN are required.");
|
|
74
|
+
(0, node_process_1.exit)(1);
|
|
75
|
+
}
|
|
76
|
+
const roundInfo = await (0, getInfoBroadcast_1.getBroadcastRound)(roundId);
|
|
77
|
+
if (!roundInfo) {
|
|
78
|
+
console.error(colors_1.default.red("Round not found."));
|
|
79
|
+
(0, node_process_1.exit)(1);
|
|
80
|
+
}
|
|
81
|
+
const loopArgIndex = args.findIndex((arg) => arg === "--loop");
|
|
82
|
+
let loopTimer = undefined;
|
|
83
|
+
if (loopArgIndex !== -1 && loopArgIndex + 1 < args.length) {
|
|
84
|
+
const loopTimerStr = args[loopArgIndex + 1];
|
|
85
|
+
loopTimer = parseInt(loopTimerStr, 10);
|
|
86
|
+
if (isNaN(loopTimer) || loopTimer <= 0) {
|
|
87
|
+
console.error(colors_1.default.red("Loop timer must be a positive integer."));
|
|
88
|
+
(0, node_process_1.exit)(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (loopTimer) {
|
|
92
|
+
console.log(colors_1.default.green(`Starting loop to push PGN every ${colors_1.default.whiteBold(loopTimer.toString())} seconds...`));
|
|
93
|
+
console.log(colors_1.default.blue("Press Ctrl+C to stop."));
|
|
94
|
+
await loop(roundInfo, pgnPath, loopTimer);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const pgnContent = await readPGNFromURL(pgnPath);
|
|
98
|
+
if (pgnContent)
|
|
99
|
+
await pushPGN(roundInfo, pgnContent);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.pushCommand = pushCommand;
|
|
@@ -15,6 +15,7 @@ const fixSchedule_1 = require("../cmd/fixSchedule");
|
|
|
15
15
|
const startsPrevious_1 = require("../cmd/startsPrevious");
|
|
16
16
|
const period_1 = require("../cmd/period");
|
|
17
17
|
const score_1 = require("../cmd/score");
|
|
18
|
+
const push_1 = require("../cmd/push");
|
|
18
19
|
const login_1 = require("../cmd/login");
|
|
19
20
|
const credentials_1 = require("./credentials");
|
|
20
21
|
const getToken = () => {
|
|
@@ -42,6 +43,7 @@ var Command;
|
|
|
42
43
|
Command["StartsPrevious"] = "startsPrevious";
|
|
43
44
|
Command["Period"] = "period";
|
|
44
45
|
Command["Score"] = "score";
|
|
46
|
+
Command["Push"] = "push";
|
|
45
47
|
})(Command || (exports.Command = Command = {}));
|
|
46
48
|
exports.commands = new Map([
|
|
47
49
|
[Command.Login, login_1.loginCommand],
|
|
@@ -53,6 +55,7 @@ exports.commands = new Map([
|
|
|
53
55
|
[Command.StartsPrevious, startsPrevious_1.startsPreviousCommand],
|
|
54
56
|
[Command.Period, period_1.periodCommand],
|
|
55
57
|
[Command.Score, score_1.scoreCommand],
|
|
58
|
+
[Command.Push, push_1.pushCommand],
|
|
56
59
|
]);
|
|
57
60
|
exports.client = (0, openapi_fetch_1.default)({
|
|
58
61
|
baseUrl: LICHESS_DOMAIN,
|
package/dist/utils/help.js
CHANGED
|
@@ -74,6 +74,13 @@ const helpScore = [
|
|
|
74
74
|
` ${colors_1.default.bold("Options:")}`,
|
|
75
75
|
` --rounds <roundsToFix> ${colors_1.default.gray("Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.")}`,
|
|
76
76
|
].join("\n");
|
|
77
|
+
const helpPush = [
|
|
78
|
+
` ${colors_1.default.underItalic("push <roundId> <PGNFromPathOrUrl> [--loop <intervalInSeconds>]")}`,
|
|
79
|
+
` ${colors_1.default.gray("Upload a PGN file from a local path or URL to the specified broadcast round.")}`,
|
|
80
|
+
` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("The PGN file must be accessible from the provided path or URL.")}`,
|
|
81
|
+
` ${colors_1.default.bold("Options:")}`,
|
|
82
|
+
` --loop <intervalInSeconds> ${colors_1.default.gray("Continuously push the PGN file at the specified interval in seconds.")}`,
|
|
83
|
+
].join("\n");
|
|
77
84
|
const msg = [
|
|
78
85
|
`${colors_1.default.boldYellow("Usage:")} ${colors_1.default.underItalic("<command> [options]")}`,
|
|
79
86
|
``,
|
|
@@ -97,6 +104,8 @@ const msg = [
|
|
|
97
104
|
``,
|
|
98
105
|
helpScore,
|
|
99
106
|
``,
|
|
107
|
+
helpPush,
|
|
108
|
+
``,
|
|
100
109
|
``,
|
|
101
110
|
`${colors_1.default.boldYellow("Examples:")}`,
|
|
102
111
|
` ${colors_1.default.gray("# Login with your Lichess token (interactive)")}`,
|
|
@@ -121,6 +130,8 @@ const msg = [
|
|
|
121
130
|
` $ ${colors_1.default.underItalic("period")} ${colors_1.default.italic("bcast123 10")}`,
|
|
122
131
|
` ${colors_1.default.gray("# Set custom scoring for all rounds in a broadcast")}`,
|
|
123
132
|
` $ ${colors_1.default.underItalic("score")} ${colors_1.default.italic("bcast123 1.0 0.5 1.0 0.5")}`,
|
|
133
|
+
` ${colors_1.default.gray("# Push a PGN file in loop mode every 60 seconds")}`,
|
|
134
|
+
` $ ${colors_1.default.underItalic("push")} ${colors_1.default.italic("round456 /path/to/localfile.pgn --loop 60")}`,
|
|
124
135
|
];
|
|
125
136
|
const showHelp = (cmd) => {
|
|
126
137
|
const ranges = {
|
|
@@ -133,6 +144,7 @@ const showHelp = (cmd) => {
|
|
|
133
144
|
[commandHandler_1.Command.StartsPrevious]: helpStartsPrevious,
|
|
134
145
|
[commandHandler_1.Command.Period]: helpSetPeriod,
|
|
135
146
|
[commandHandler_1.Command.Score]: helpScore,
|
|
147
|
+
[commandHandler_1.Command.Push]: helpPush,
|
|
136
148
|
};
|
|
137
149
|
const range = cmd ? ranges[cmd] : undefined;
|
|
138
150
|
console.info(range ? range : msg.join("\n"));
|