libroadcast-cli 1.1.1 → 1.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 +9 -0
- package/dist/cmd/setPGN.js +63 -0
- package/dist/index.js +17 -10
- package/dist/utils.js +17 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ libroadcast
|
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
Usage: <command> [options]
|
|
18
|
+
|
|
18
19
|
Commands:
|
|
19
20
|
delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]
|
|
20
21
|
Sets the delay for all rounds in the specified broadcast.
|
|
@@ -23,4 +24,12 @@ Commands:
|
|
|
23
24
|
--noDelay Remove the delay from the rounds.
|
|
24
25
|
setLCC <broadcastId> <sourceLCCUrl>
|
|
25
26
|
Sets the source LCC URL for all rounds in the specified broadcast.
|
|
27
|
+
setPGN <broadcastId> <sourcePGNUrl>
|
|
28
|
+
Sets the source PGN URL for all rounds in the specified broadcast.
|
|
29
|
+
(optional) Use '{}' in the URL as a placeholder for the round number.
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time
|
|
33
|
+
setLCC bcast123 https://view.livechesscloud.com/#47c48351-034a-4860-9b94-087490742803
|
|
34
|
+
setPGN bcast123 https://example.com/pgns/round-{}/game.pgn
|
|
26
35
|
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setPGNCommand = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const setPGN = (rounds, urlRound) => {
|
|
6
|
+
let rN = 1;
|
|
7
|
+
rounds.forEach((round) => {
|
|
8
|
+
utils_1.client
|
|
9
|
+
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
10
|
+
params: {
|
|
11
|
+
path: { broadcastRoundId: round.id },
|
|
12
|
+
// @ts-ignore patch param is not yet documented
|
|
13
|
+
query: { patch: 1 },
|
|
14
|
+
},
|
|
15
|
+
// @ts-ignore name of body properties due patch param is implicit
|
|
16
|
+
body: {
|
|
17
|
+
// @ts-ignore property is not yet documented
|
|
18
|
+
syncSource: "url",
|
|
19
|
+
syncUrl: urlRound(rN),
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
.then((response) => {
|
|
23
|
+
if (response.response.ok)
|
|
24
|
+
console.log(`Successfully set source LCC for round ${round.id} to ${urlRound(rN)}.`);
|
|
25
|
+
else
|
|
26
|
+
console.error(`Failed to set source LCC for round ${round.id}: ${response.response.statusText}`);
|
|
27
|
+
})
|
|
28
|
+
.catch((error) => {
|
|
29
|
+
console.error(`Error setting source LCC for round ${round.id}:`, error);
|
|
30
|
+
});
|
|
31
|
+
rN += 1;
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const setPGNCommand = async (args) => {
|
|
35
|
+
const [bId, sourcePGN] = args.slice(0, 2);
|
|
36
|
+
// check arg --help or -h
|
|
37
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
38
|
+
(0, utils_1.showHelp)(utils_1.Command.SetPGN);
|
|
39
|
+
process.exit(0);
|
|
40
|
+
}
|
|
41
|
+
// Validate required args
|
|
42
|
+
if (!bId || !sourcePGN) {
|
|
43
|
+
(0, utils_1.showHelp)(utils_1.Command.SetPGN);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const bcast = await (0, utils_1.getBroadcast)(bId);
|
|
47
|
+
if (!bcast?.rounds || bcast.rounds.length === 0) {
|
|
48
|
+
console.error("No rounds found for the specified broadcast.");
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const urlRound = (roundNum) => sourcePGN.replaceAll("{}", roundNum.toString());
|
|
52
|
+
try {
|
|
53
|
+
const url = new URL(urlRound(1));
|
|
54
|
+
if (!url.protocol.startsWith("http"))
|
|
55
|
+
throw new Error();
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
console.error('Invalid URL. Must be http/https with "{}" as round placeholder.');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
setPGN(bcast.rounds, urlRound);
|
|
62
|
+
};
|
|
63
|
+
exports.setPGNCommand = setPGNCommand;
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const process_1 = require("process");
|
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
const delay_1 = require("./cmd/delay");
|
|
7
7
|
const setLCC_1 = require("./cmd/setLCC");
|
|
8
|
+
const setPGN_1 = require("./cmd/setPGN");
|
|
8
9
|
// Ensure LICHESS_TOKEN is set
|
|
9
10
|
if (!utils_1.LICHESS_TOKEN) {
|
|
10
11
|
console.error("Error: LICHESS_TOKEN environment variable is not set.");
|
|
@@ -12,21 +13,27 @@ if (!utils_1.LICHESS_TOKEN) {
|
|
|
12
13
|
}
|
|
13
14
|
const args = process_1.argv.slice(2);
|
|
14
15
|
(async () => {
|
|
16
|
+
// show version for --version or -v
|
|
17
|
+
if (args.includes("--version") || args.includes("-v")) {
|
|
18
|
+
const { version } = require("../package.json");
|
|
19
|
+
console.log(`libroadcast-cli v${version}`);
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
15
22
|
// check args[0] is --help or -h
|
|
16
23
|
if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
|
|
17
24
|
(0, utils_1.showHelp)();
|
|
18
25
|
process.exit(0);
|
|
19
26
|
}
|
|
20
27
|
const command = args.shift();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
process.exit(1);
|
|
28
|
+
const commands = new Map([
|
|
29
|
+
[utils_1.Command.Delay, delay_1.delayCommand],
|
|
30
|
+
[utils_1.Command.SetLCC, setLCC_1.setLCCCommand],
|
|
31
|
+
[utils_1.Command.SetPGN, setPGN_1.setPGNCommand],
|
|
32
|
+
]);
|
|
33
|
+
const handler = commands.get(command);
|
|
34
|
+
if (!handler) {
|
|
35
|
+
console.error("Unknown command. Supported commands: delay, setLCC, setPGN");
|
|
36
|
+
process.exit(1);
|
|
31
37
|
}
|
|
38
|
+
await handler(args);
|
|
32
39
|
})();
|
package/dist/utils.js
CHANGED
|
@@ -20,11 +20,13 @@ var Command;
|
|
|
20
20
|
(function (Command) {
|
|
21
21
|
Command["Delay"] = "delay";
|
|
22
22
|
Command["SetLCC"] = "setLCC";
|
|
23
|
+
Command["SetPGN"] = "setPGN";
|
|
23
24
|
})(Command || (exports.Command = Command = {}));
|
|
24
25
|
// Function to show help messages
|
|
25
26
|
const showHelp = (cmd) => {
|
|
26
27
|
const msg = [
|
|
27
28
|
"Usage: <command> [options]",
|
|
29
|
+
"",
|
|
28
30
|
"Commands:",
|
|
29
31
|
" delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]",
|
|
30
32
|
" Sets the delay for all rounds in the specified broadcast.",
|
|
@@ -33,17 +35,22 @@ const showHelp = (cmd) => {
|
|
|
33
35
|
" --noDelay Remove the delay from the rounds.",
|
|
34
36
|
" setLCC <broadcastId> <sourceLCCUrl>",
|
|
35
37
|
" Sets the source LCC URL for all rounds in the specified broadcast.",
|
|
38
|
+
" setPGN <broadcastId> <sourcePGNUrl>",
|
|
39
|
+
" Sets the source PGN URL for all rounds in the specified broadcast.",
|
|
40
|
+
" (optional) Use '{}' in the URL as a placeholder for the round number.",
|
|
41
|
+
"",
|
|
42
|
+
"Examples:",
|
|
43
|
+
" delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time",
|
|
44
|
+
" setLCC bcast123 https://view.livechesscloud.com/#47c48351-034a-4860-9b94-087490742803",
|
|
45
|
+
" setPGN bcast123 https://example.com/pgns/round-{}/game.pgn",
|
|
36
46
|
];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
default:
|
|
45
|
-
console.info(msg.join("\n"));
|
|
46
|
-
}
|
|
47
|
+
const ranges = {
|
|
48
|
+
[Command.Delay]: [3, 8],
|
|
49
|
+
[Command.SetLCC]: [8, 10],
|
|
50
|
+
[Command.SetPGN]: [10, 13],
|
|
51
|
+
};
|
|
52
|
+
const range = cmd ? ranges[cmd] : undefined;
|
|
53
|
+
console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
|
|
47
54
|
};
|
|
48
55
|
exports.showHelp = showHelp;
|
|
49
56
|
const getBroadcast = (broadcastId) => exports.client
|