libroadcast-cli 1.3.3 → 1.4.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 +6 -1
- package/dist/cmd/delay.js +12 -14
- package/dist/cmd/setLichessGames.js +41 -0
- package/dist/cmd/setPGN.js +17 -20
- package/dist/index.js +22 -25
- package/dist/utils/commandHandler.js +41 -0
- package/dist/utils/getInfoBroadcast.js +32 -0
- package/dist/utils/help.js +46 -0
- package/package.json +1 -1
- package/dist/utils.js +0 -71
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Usage: <command> [options]
|
|
|
19
19
|
Commands:
|
|
20
20
|
delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]
|
|
21
21
|
Sets the delay for all rounds in the specified broadcast.
|
|
22
|
+
The delay is specified in seconds. (max 3600 seconds = 1 hour)
|
|
22
23
|
Options:
|
|
23
24
|
--onlyDelay Set only the delay without changing the start time.
|
|
24
25
|
--noDelay Remove the delay from the rounds.
|
|
@@ -29,8 +30,12 @@ Commands:
|
|
|
29
30
|
Options:
|
|
30
31
|
--withFilter Apply round number filtering based on round number.
|
|
31
32
|
--slice <sliceFilter> Apply slice filtering using the provided filter string.
|
|
33
|
+
setLichessGames <broadcastRoundId> <gameIds...>
|
|
34
|
+
Sets the games for the specified broadcast round using Lichess game IDs.
|
|
35
|
+
Note: Maximum of 64 game IDs can be provided.
|
|
32
36
|
|
|
33
37
|
Examples:
|
|
34
38
|
delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time
|
|
35
|
-
setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
|
|
39
|
+
setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
|
|
40
|
+
setLichessGames round456 gameId1 gameId2 gameId3 # Set specific games for the round
|
|
36
41
|
```
|
package/dist/cmd/delay.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.delayCommand = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_process_1 = require("node:process");
|
|
5
|
+
const commandHandler_1 = require("../utils/commandHandler");
|
|
6
|
+
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
5
7
|
const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
|
|
6
8
|
for (const round of rounds) {
|
|
7
|
-
await
|
|
9
|
+
await commandHandler_1.client
|
|
8
10
|
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
9
11
|
params: {
|
|
10
12
|
path: { broadcastRoundId: round.id },
|
|
@@ -26,34 +28,30 @@ const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
|
|
|
26
28
|
.catch((error) => {
|
|
27
29
|
console.error(`Error setting delay for round ${round.id}:`, error);
|
|
28
30
|
});
|
|
29
|
-
await (0,
|
|
31
|
+
await (0, commandHandler_1.sleep)(200);
|
|
30
32
|
}
|
|
31
33
|
};
|
|
32
34
|
const delayCommand = async (args) => {
|
|
33
35
|
const [broadcastId, delay] = args.slice(0, 2);
|
|
34
|
-
if (args.includes("--help") || args.includes("-h")) {
|
|
35
|
-
(0, utils_1.showHelp)(utils_1.Command.Delay);
|
|
36
|
-
process.exit(0);
|
|
37
|
-
}
|
|
38
36
|
if (!broadcastId || !delay) {
|
|
39
|
-
(0,
|
|
40
|
-
|
|
37
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and delay are required.");
|
|
38
|
+
(0, node_process_1.exit)(1);
|
|
41
39
|
}
|
|
42
40
|
const delayNum = parseInt(delay, 10);
|
|
43
41
|
if (isNaN(delayNum) && delayNum >= 0 && delayNum <= 3600) {
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Delay must be a number between 0 and 3600 seconds.");
|
|
43
|
+
(0, node_process_1.exit)(1);
|
|
46
44
|
}
|
|
47
45
|
const onlyDelay = args.includes("--onlyDelay");
|
|
48
46
|
const noDelay = args.includes("--noDelay");
|
|
49
47
|
if (onlyDelay && noDelay) {
|
|
50
48
|
console.error("Cannot use --onlyDelay and --noDelay together.");
|
|
51
|
-
|
|
49
|
+
(0, node_process_1.exit)(1);
|
|
52
50
|
}
|
|
53
|
-
const broadcast = await (0,
|
|
51
|
+
const broadcast = await (0, getInfoBroadcast_1.getBroadcast)(broadcastId);
|
|
54
52
|
if (!broadcast?.rounds || broadcast.rounds.length === 0) {
|
|
55
53
|
console.error("No rounds found for the specified broadcast.");
|
|
56
|
-
|
|
54
|
+
(0, node_process_1.exit)(1);
|
|
57
55
|
}
|
|
58
56
|
setDelayRounds(broadcast.rounds, parseInt(delay, 10), onlyDelay, noDelay);
|
|
59
57
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setLichessGamesCommand = void 0;
|
|
4
|
+
const node_process_1 = require("node:process");
|
|
5
|
+
const commandHandler_1 = require("../utils/commandHandler");
|
|
6
|
+
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
7
|
+
const setLichessGames = (round, games) => commandHandler_1.client
|
|
8
|
+
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
9
|
+
params: {
|
|
10
|
+
path: { broadcastRoundId: round.id },
|
|
11
|
+
query: { patch: 1 },
|
|
12
|
+
},
|
|
13
|
+
body: {
|
|
14
|
+
syncSource: "ids",
|
|
15
|
+
syncIds: games,
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
.then((response) => {
|
|
19
|
+
if (response.response.ok)
|
|
20
|
+
console.log(`Successfully set games for round ${round.id} to ${games}.`);
|
|
21
|
+
else
|
|
22
|
+
console.error(`Failed to set games for round ${round.id}: ${response.response.statusText}`);
|
|
23
|
+
})
|
|
24
|
+
.catch((error) => {
|
|
25
|
+
console.error(`Error setting games for round ${round.id}:`, error);
|
|
26
|
+
});
|
|
27
|
+
const setLichessGamesCommand = async (args) => {
|
|
28
|
+
const bId = args.shift();
|
|
29
|
+
const games = args.slice(0, 64).join(" ");
|
|
30
|
+
if (!bId || !games) {
|
|
31
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and games IDs are required.");
|
|
32
|
+
(0, node_process_1.exit)(1);
|
|
33
|
+
}
|
|
34
|
+
const round = await (0, getInfoBroadcast_1.getBroadcastRound)(bId);
|
|
35
|
+
if (!round) {
|
|
36
|
+
console.error(`Broadcast round with ID ${bId} not found or has no rounds.`);
|
|
37
|
+
(0, node_process_1.exit)(1);
|
|
38
|
+
}
|
|
39
|
+
setLichessGames(round, games);
|
|
40
|
+
};
|
|
41
|
+
exports.setLichessGamesCommand = setLichessGamesCommand;
|
package/dist/cmd/setPGN.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setPGNCommand = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_process_1 = require("node:process");
|
|
5
|
+
const commandHandler_1 = require("../utils/commandHandler");
|
|
6
|
+
const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
|
|
5
7
|
const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) => {
|
|
6
8
|
for (let rN = 1; rN <= rounds.length; rN++) {
|
|
7
9
|
const round = rounds[rN - 1];
|
|
8
10
|
const url = urlRound(rN);
|
|
9
|
-
await
|
|
11
|
+
await commandHandler_1.client
|
|
10
12
|
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
11
13
|
params: {
|
|
12
14
|
path: { broadcastRoundId: round.id },
|
|
@@ -21,30 +23,26 @@ const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) =
|
|
|
21
23
|
})
|
|
22
24
|
.then((response) => {
|
|
23
25
|
if (response.response.ok)
|
|
24
|
-
console.log(`Successfully set source
|
|
26
|
+
console.log(`Successfully set source for round ${round.id} to ${url}.`);
|
|
25
27
|
else
|
|
26
|
-
console.error(`Failed to set source
|
|
28
|
+
console.error(`Failed to set source for round ${round.id}: ${response.response.statusText}`);
|
|
27
29
|
})
|
|
28
30
|
.catch((error) => {
|
|
29
|
-
console.error(`Error setting source
|
|
31
|
+
console.error(`Error setting source for round ${round.id}:`, error);
|
|
30
32
|
});
|
|
31
|
-
await (0,
|
|
33
|
+
await (0, commandHandler_1.sleep)(200);
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
36
|
const setPGNCommand = async (args) => {
|
|
35
37
|
const [bId, sourcePGN] = args.slice(0, 2);
|
|
36
|
-
if (args.includes("--help") || args.includes("-h")) {
|
|
37
|
-
(0, utils_1.showHelp)(utils_1.Command.SetPGN);
|
|
38
|
-
process.exit(0);
|
|
39
|
-
}
|
|
40
38
|
if (!bId || !sourcePGN) {
|
|
41
|
-
(0,
|
|
42
|
-
|
|
39
|
+
(0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and source PGN URL are required.");
|
|
40
|
+
(0, node_process_1.exit)(1);
|
|
43
41
|
}
|
|
44
|
-
const bcast = await (0,
|
|
42
|
+
const bcast = await (0, getInfoBroadcast_1.getBroadcast)(bId);
|
|
45
43
|
if (!bcast?.rounds || bcast.rounds.length === 0) {
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
(0, commandHandler_1.msgCommonErrorHelp)("No rounds found for the specified broadcast.");
|
|
45
|
+
(0, node_process_1.exit)(1);
|
|
48
46
|
}
|
|
49
47
|
const urlRound = (roundNum) => roundNum ? sourcePGN.replaceAll("{}", roundNum.toString()) : sourcePGN;
|
|
50
48
|
let isLCC = false;
|
|
@@ -57,11 +55,10 @@ const setPGNCommand = async (args) => {
|
|
|
57
55
|
throw new Error();
|
|
58
56
|
}
|
|
59
57
|
catch {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
process.exit(1);
|
|
58
|
+
console.error(isLCC
|
|
59
|
+
? 'Invalid URL. For livechesscloud URLs, please ensure it ends with "/{}".'
|
|
60
|
+
: 'Invalid URL. Must be http/https with "{}" as round placeholder.');
|
|
61
|
+
(0, node_process_1.exit)(1);
|
|
65
62
|
}
|
|
66
63
|
const setRoundFilter = args.includes("--withFilter");
|
|
67
64
|
const sliceIndex = args.indexOf("--slice");
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const setPGN_1 = require("./cmd/setPGN");
|
|
8
|
-
if (!utils_1.LICHESS_TOKEN) {
|
|
9
|
-
console.error("Error: LICHESS_TOKEN environment variable is not set.");
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
const args = process_1.argv.slice(2);
|
|
4
|
+
const node_process_1 = require("node:process");
|
|
5
|
+
const commandHandler_1 = require("./utils/commandHandler");
|
|
6
|
+
const help_1 = require("./utils/help");
|
|
13
7
|
(async () => {
|
|
14
|
-
if (args.includes("--version") || args.includes("-v")) {
|
|
8
|
+
if (commandHandler_1.args.includes("--version") || commandHandler_1.args.includes("-v")) {
|
|
15
9
|
const { version } = require("../package.json");
|
|
16
10
|
console.log(`libroadcast-cli v${version}`);
|
|
17
|
-
|
|
11
|
+
(0, node_process_1.exit)(0);
|
|
18
12
|
}
|
|
19
|
-
if (args.length === 0 ||
|
|
20
|
-
(0,
|
|
21
|
-
|
|
13
|
+
if (commandHandler_1.args.length === 0 || (0, help_1.includeHelp)(commandHandler_1.args[0])) {
|
|
14
|
+
(0, help_1.showHelp)();
|
|
15
|
+
(0, node_process_1.exit)(0);
|
|
22
16
|
}
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
[utils_1.Command.SetLCC, setPGN_1.setPGNCommand],
|
|
27
|
-
[utils_1.Command.SetPGN, setPGN_1.setPGNCommand],
|
|
28
|
-
]);
|
|
29
|
-
const handler = commands.get(command);
|
|
30
|
-
if (command === utils_1.Command.SetLCC)
|
|
17
|
+
const cmd = commandHandler_1.args.shift();
|
|
18
|
+
const handler = commandHandler_1.commands.get(cmd);
|
|
19
|
+
if (cmd === commandHandler_1.Command.SetLCC)
|
|
31
20
|
console.warn("Warning: 'setLCC' command was removed. Will use 'setPGN' instead.");
|
|
21
|
+
if (commandHandler_1.args.find(help_1.includeHelp)) {
|
|
22
|
+
(0, help_1.showHelp)(cmd);
|
|
23
|
+
(0, node_process_1.exit)(0);
|
|
24
|
+
}
|
|
32
25
|
if (!handler) {
|
|
33
|
-
console.error("
|
|
34
|
-
|
|
26
|
+
console.error("Error: Command handler not found.");
|
|
27
|
+
(0, node_process_1.exit)(1);
|
|
28
|
+
}
|
|
29
|
+
if (!commandHandler_1.LICHESS_TOKEN) {
|
|
30
|
+
console.error("Error: LICHESS_TOKEN environment variable is not set.");
|
|
31
|
+
(0, node_process_1.exit)(1);
|
|
35
32
|
}
|
|
36
|
-
await handler(args);
|
|
33
|
+
await handler(commandHandler_1.args);
|
|
37
34
|
})();
|
|
@@ -0,0 +1,41 @@
|
|
|
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.msgCommonErrorHelp = exports.sleep = exports.client = exports.commands = exports.Command = exports.args = exports.LICHESS_TOKEN = void 0;
|
|
7
|
+
const node_process_1 = require("node:process");
|
|
8
|
+
const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
|
|
9
|
+
const delay_1 = require("../cmd/delay");
|
|
10
|
+
const setPGN_1 = require("../cmd/setPGN");
|
|
11
|
+
const setLichessGames_1 = require("../cmd/setLichessGames");
|
|
12
|
+
exports.LICHESS_TOKEN = node_process_1.env.LICHESS_TOKEN;
|
|
13
|
+
const LICHESS_DOMAIN = node_process_1.env.LICHESS_DOMAIN || "https://lichess.org/";
|
|
14
|
+
exports.args = node_process_1.argv.slice(2);
|
|
15
|
+
var Command;
|
|
16
|
+
(function (Command) {
|
|
17
|
+
Command["Delay"] = "delay";
|
|
18
|
+
Command["SetLCC"] = "setLCC";
|
|
19
|
+
Command["SetPGN"] = "setPGN";
|
|
20
|
+
Command["SetLichessGames"] = "setLichessGames";
|
|
21
|
+
})(Command || (exports.Command = Command = {}));
|
|
22
|
+
exports.commands = new Map([
|
|
23
|
+
[Command.Delay, delay_1.delayCommand],
|
|
24
|
+
[Command.SetLCC, setPGN_1.setPGNCommand],
|
|
25
|
+
[Command.SetPGN, setPGN_1.setPGNCommand],
|
|
26
|
+
[Command.SetLichessGames, setLichessGames_1.setLichessGamesCommand],
|
|
27
|
+
]);
|
|
28
|
+
exports.client = (0, openapi_fetch_1.default)({
|
|
29
|
+
baseUrl: LICHESS_DOMAIN,
|
|
30
|
+
headers: {
|
|
31
|
+
Authorization: `Bearer ${exports.LICHESS_TOKEN}`,
|
|
32
|
+
Accept: "application/json",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
36
|
+
exports.sleep = sleep;
|
|
37
|
+
const msgCommonErrorHelp = (msg) => {
|
|
38
|
+
console.error(msg);
|
|
39
|
+
console.info("Use --help to see usage.");
|
|
40
|
+
};
|
|
41
|
+
exports.msgCommonErrorHelp = msgCommonErrorHelp;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBroadcastRound = exports.getBroadcast = void 0;
|
|
4
|
+
const commandHandler_1 = require("./commandHandler");
|
|
5
|
+
const getBroadcast = (broadcastId) => commandHandler_1.client
|
|
6
|
+
.GET("/api/broadcast/{broadcastTournamentId}", {
|
|
7
|
+
params: {
|
|
8
|
+
path: { broadcastTournamentId: broadcastId },
|
|
9
|
+
},
|
|
10
|
+
})
|
|
11
|
+
.then((response) => response.data)
|
|
12
|
+
.catch((error) => {
|
|
13
|
+
console.error("Error fetching broadcast:", error);
|
|
14
|
+
return null;
|
|
15
|
+
});
|
|
16
|
+
exports.getBroadcast = getBroadcast;
|
|
17
|
+
const getBroadcastRound = (roundId) => commandHandler_1.client
|
|
18
|
+
.GET("/api/broadcast/{broadcastTournamentSlug}/{broadcastRoundSlug}/{broadcastRoundId}", {
|
|
19
|
+
params: {
|
|
20
|
+
path: {
|
|
21
|
+
broadcastTournamentSlug: "-",
|
|
22
|
+
broadcastRoundSlug: "-",
|
|
23
|
+
broadcastRoundId: roundId,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
.then((response) => response.data?.round)
|
|
28
|
+
.catch((error) => {
|
|
29
|
+
console.error("Error fetching broadcast round:", error);
|
|
30
|
+
return null;
|
|
31
|
+
});
|
|
32
|
+
exports.getBroadcastRound = getBroadcastRound;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.includeHelp = exports.showHelp = void 0;
|
|
4
|
+
const commandHandler_1 = require("./commandHandler");
|
|
5
|
+
const msg = [
|
|
6
|
+
"Usage: <command> [options]",
|
|
7
|
+
"",
|
|
8
|
+
"Commands:",
|
|
9
|
+
" delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]",
|
|
10
|
+
" Sets the delay for all rounds in the specified broadcast.",
|
|
11
|
+
" The delay is specified in seconds. (max 3600 seconds = 1 hour)",
|
|
12
|
+
" Options:",
|
|
13
|
+
" --onlyDelay Set only the delay without changing the start time.",
|
|
14
|
+
" --noDelay Remove the delay from the rounds.",
|
|
15
|
+
" setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]",
|
|
16
|
+
" Sets the source PGN URL for all rounds in the specified broadcast.",
|
|
17
|
+
" (optional) Use '{}' in the URL as a placeholder for the round number.",
|
|
18
|
+
' Note: For livechesscloud URLs, please ensure it ends with "/{}".',
|
|
19
|
+
" Options:",
|
|
20
|
+
" --withFilter Apply round number filtering based on round number.",
|
|
21
|
+
" --slice <sliceFilter> Apply slice filtering using the provided filter string.",
|
|
22
|
+
" setLichessGames <broadcastRoundId> <gameIds...>",
|
|
23
|
+
" Sets the games for the specified broadcast round using Lichess game IDs.",
|
|
24
|
+
" Note: Maximum of 64 game IDs can be provided.",
|
|
25
|
+
"",
|
|
26
|
+
"Examples:",
|
|
27
|
+
" delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time",
|
|
28
|
+
' setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"',
|
|
29
|
+
" setLichessGames round456 gameId1 gameId2 gameId3 # Set specific games for the round",
|
|
30
|
+
];
|
|
31
|
+
const showHelp = (cmd) => {
|
|
32
|
+
const ranges = {
|
|
33
|
+
[commandHandler_1.Command.Delay]: [3, 9],
|
|
34
|
+
[commandHandler_1.Command.SetPGN]: [9, 16],
|
|
35
|
+
[commandHandler_1.Command.SetLCC]: [9, 16],
|
|
36
|
+
[commandHandler_1.Command.SetLichessGames]: [16, 19],
|
|
37
|
+
};
|
|
38
|
+
const range = cmd ? ranges[cmd] : undefined;
|
|
39
|
+
if (cmd === commandHandler_1.Command.SetLCC) {
|
|
40
|
+
console.warn("Warning: 'setLCC' command was removed. Use 'setPGN' command instead.");
|
|
41
|
+
}
|
|
42
|
+
console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
|
|
43
|
+
};
|
|
44
|
+
exports.showHelp = showHelp;
|
|
45
|
+
const includeHelp = (str) => ["--help", "-h"].includes(str);
|
|
46
|
+
exports.includeHelp = includeHelp;
|
package/package.json
CHANGED
package/dist/utils.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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.sleep = exports.getBroadcast = exports.showHelp = exports.Command = exports.client = exports.LICHESS_TOKEN = void 0;
|
|
7
|
-
const process_1 = require("process");
|
|
8
|
-
const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
|
|
9
|
-
exports.LICHESS_TOKEN = process_1.env.LICHESS_TOKEN;
|
|
10
|
-
const LICHESS_DOMAIN = process_1.env.LICHESS_DOMAIN || "https://lichess.org/";
|
|
11
|
-
exports.client = (0, openapi_fetch_1.default)({
|
|
12
|
-
baseUrl: LICHESS_DOMAIN,
|
|
13
|
-
headers: {
|
|
14
|
-
Authorization: `Bearer ${exports.LICHESS_TOKEN}`,
|
|
15
|
-
Accept: "application/json",
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
var Command;
|
|
19
|
-
(function (Command) {
|
|
20
|
-
Command["Delay"] = "delay";
|
|
21
|
-
Command["SetLCC"] = "setLCC";
|
|
22
|
-
Command["SetPGN"] = "setPGN";
|
|
23
|
-
})(Command || (exports.Command = Command = {}));
|
|
24
|
-
const showHelp = (cmd) => {
|
|
25
|
-
const msg = [
|
|
26
|
-
"Usage: <command> [options]",
|
|
27
|
-
"",
|
|
28
|
-
"Commands:",
|
|
29
|
-
" delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]",
|
|
30
|
-
" Sets the delay for all rounds in the specified broadcast.",
|
|
31
|
-
" Options:",
|
|
32
|
-
" --onlyDelay Set only the delay without changing the start time.",
|
|
33
|
-
" --noDelay Remove the delay from the rounds.",
|
|
34
|
-
" setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]",
|
|
35
|
-
" Sets the source PGN URL for all rounds in the specified broadcast.",
|
|
36
|
-
" (optional) Use '{}' in the URL as a placeholder for the round number.",
|
|
37
|
-
" Note: For livechesscloud URLs, please ensure it ends with \"/{}\".",
|
|
38
|
-
" Options:",
|
|
39
|
-
" --withFilter Apply round number filtering based on round number.",
|
|
40
|
-
" --slice <sliceFilter> Apply slice filtering using the provided filter string.",
|
|
41
|
-
"",
|
|
42
|
-
"Examples:",
|
|
43
|
-
" delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time",
|
|
44
|
-
" setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice \"1-5,7,9-12\"",
|
|
45
|
-
];
|
|
46
|
-
const ranges = {
|
|
47
|
-
[Command.Delay]: [3, 8],
|
|
48
|
-
[Command.SetPGN]: [8, 15],
|
|
49
|
-
[Command.SetLCC]: [8, 15],
|
|
50
|
-
};
|
|
51
|
-
const range = cmd ? ranges[cmd] : undefined;
|
|
52
|
-
if (cmd === Command.SetLCC) {
|
|
53
|
-
console.warn("Warning: 'setLCC' command was removed. Use 'setPGN' command instead.");
|
|
54
|
-
}
|
|
55
|
-
console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
|
|
56
|
-
};
|
|
57
|
-
exports.showHelp = showHelp;
|
|
58
|
-
const getBroadcast = (broadcastId) => exports.client
|
|
59
|
-
.GET("/api/broadcast/{broadcastTournamentId}", {
|
|
60
|
-
params: {
|
|
61
|
-
path: { broadcastTournamentId: broadcastId },
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
.then((response) => response.data)
|
|
65
|
-
.catch((error) => {
|
|
66
|
-
console.error("Error fetching broadcast:", error);
|
|
67
|
-
return null;
|
|
68
|
-
});
|
|
69
|
-
exports.getBroadcast = getBroadcast;
|
|
70
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
71
|
-
exports.sleep = sleep;
|