libroadcast-cli 1.2.1 → 1.3.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 -5
- package/dist/cmd/delay.js +0 -7
- package/dist/cmd/setPGN.js +23 -12
- package/dist/index.js +3 -5
- package/dist/utils.js +11 -9
- package/package.json +1 -1
- package/dist/cmd/setLCC.js +0 -64
package/README.md
CHANGED
|
@@ -22,14 +22,15 @@ Commands:
|
|
|
22
22
|
Options:
|
|
23
23
|
--onlyDelay Set only the delay without changing the start time.
|
|
24
24
|
--noDelay Remove the delay from the rounds.
|
|
25
|
-
|
|
26
|
-
Sets the source LCC URL for all rounds in the specified broadcast.
|
|
27
|
-
setPGN <broadcastId> <sourcePGNUrl>
|
|
25
|
+
setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]
|
|
28
26
|
Sets the source PGN URL for all rounds in the specified broadcast.
|
|
29
27
|
(optional) Use '{}' in the URL as a placeholder for the round number.
|
|
28
|
+
Note: For livechesscloud URLs, please ensure it ends with "/{}".
|
|
29
|
+
Options:
|
|
30
|
+
--withFilter Apply round number filtering based on round number.
|
|
31
|
+
--slice <sliceFilter> Apply slice filtering using the provided filter string.
|
|
30
32
|
|
|
31
33
|
Examples:
|
|
32
34
|
delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time
|
|
33
|
-
|
|
34
|
-
setPGN bcast123 https://example.com/pgns/round-{}/game.pgn
|
|
35
|
+
setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
|
|
35
36
|
```
|
package/dist/cmd/delay.js
CHANGED
|
@@ -7,10 +7,8 @@ const setDelayRounds = (rounds, delay, onlyDelay, noDelay) => rounds.forEach((ro
|
|
|
7
7
|
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
8
8
|
params: {
|
|
9
9
|
path: { broadcastRoundId: round.id },
|
|
10
|
-
// @ts-ignore patch param is not yet documented
|
|
11
10
|
query: { patch: 1 },
|
|
12
11
|
},
|
|
13
|
-
// @ts-ignore name of body properties due patch param is implicit
|
|
14
12
|
body: {
|
|
15
13
|
delay: noDelay ? undefined : delay,
|
|
16
14
|
startsAt: round.startsAt && !onlyDelay
|
|
@@ -30,25 +28,20 @@ const setDelayRounds = (rounds, delay, onlyDelay, noDelay) => rounds.forEach((ro
|
|
|
30
28
|
});
|
|
31
29
|
const delayCommand = async (args) => {
|
|
32
30
|
const [broadcastId, delay] = args.slice(0, 2);
|
|
33
|
-
// check arg --help or -h
|
|
34
31
|
if (args.includes("--help") || args.includes("-h")) {
|
|
35
32
|
(0, utils_1.showHelp)(utils_1.Command.Delay);
|
|
36
33
|
process.exit(0);
|
|
37
34
|
}
|
|
38
|
-
// Validate required args
|
|
39
35
|
if (!broadcastId || !delay) {
|
|
40
36
|
(0, utils_1.showHelp)(utils_1.Command.Delay);
|
|
41
37
|
process.exit(1);
|
|
42
38
|
}
|
|
43
39
|
const delayNum = parseInt(delay, 10);
|
|
44
|
-
// Validate delay is a number between 0s and 1h
|
|
45
40
|
if (isNaN(delayNum) && delayNum >= 0 && delayNum <= 3600) {
|
|
46
41
|
console.error("Delay must be a number between 0 and 3600 seconds.");
|
|
47
42
|
process.exit(1);
|
|
48
43
|
}
|
|
49
|
-
// check arg --onlyDelay
|
|
50
44
|
const onlyDelay = args.includes("--onlyDelay");
|
|
51
|
-
// check arg --noDelay
|
|
52
45
|
const noDelay = args.includes("--noDelay");
|
|
53
46
|
if (onlyDelay && noDelay) {
|
|
54
47
|
console.error("Cannot use --onlyDelay and --noDelay together.");
|
package/dist/cmd/setPGN.js
CHANGED
|
@@ -2,26 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setPGNCommand = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const setPGN = (rounds, urlRound) => {
|
|
5
|
+
const setPGN = (rounds, urlRound, setRoundFilter, setSliceFilter = null) => {
|
|
6
6
|
let rN = 1;
|
|
7
7
|
rounds.forEach((round) => {
|
|
8
|
+
const url = urlRound(rN);
|
|
8
9
|
utils_1.client
|
|
9
10
|
.POST("/broadcast/round/{broadcastRoundId}/edit", {
|
|
10
11
|
params: {
|
|
11
12
|
path: { broadcastRoundId: round.id },
|
|
12
|
-
// @ts-ignore patch param is not yet documented
|
|
13
13
|
query: { patch: 1 },
|
|
14
14
|
},
|
|
15
|
-
// @ts-ignore name of body properties due patch param is implicit
|
|
16
15
|
body: {
|
|
17
|
-
// @ts-ignore property is not yet documented
|
|
18
16
|
syncSource: "url",
|
|
19
|
-
syncUrl:
|
|
17
|
+
syncUrl: url,
|
|
18
|
+
onlyRound: setRoundFilter ? rN : undefined,
|
|
19
|
+
slices: setSliceFilter ? setSliceFilter : undefined,
|
|
20
20
|
},
|
|
21
21
|
})
|
|
22
22
|
.then((response) => {
|
|
23
23
|
if (response.response.ok)
|
|
24
|
-
console.log(`Successfully set source LCC for round ${round.id} to ${
|
|
24
|
+
console.log(`Successfully set source LCC for round ${round.id} to ${url}.`);
|
|
25
25
|
else
|
|
26
26
|
console.error(`Failed to set source LCC for round ${round.id}: ${response.response.statusText}`);
|
|
27
27
|
})
|
|
@@ -33,12 +33,10 @@ const setPGN = (rounds, urlRound) => {
|
|
|
33
33
|
};
|
|
34
34
|
const setPGNCommand = async (args) => {
|
|
35
35
|
const [bId, sourcePGN] = args.slice(0, 2);
|
|
36
|
-
// check arg --help or -h
|
|
37
36
|
if (args.includes("--help") || args.includes("-h")) {
|
|
38
37
|
(0, utils_1.showHelp)(utils_1.Command.SetPGN);
|
|
39
38
|
process.exit(0);
|
|
40
39
|
}
|
|
41
|
-
// Validate required args
|
|
42
40
|
if (!bId || !sourcePGN) {
|
|
43
41
|
(0, utils_1.showHelp)(utils_1.Command.SetPGN);
|
|
44
42
|
process.exit(1);
|
|
@@ -48,16 +46,29 @@ const setPGNCommand = async (args) => {
|
|
|
48
46
|
console.error("No rounds found for the specified broadcast.");
|
|
49
47
|
process.exit(1);
|
|
50
48
|
}
|
|
51
|
-
const urlRound = (roundNum) => sourcePGN.replaceAll("{}", roundNum.toString());
|
|
49
|
+
const urlRound = (roundNum) => roundNum ? sourcePGN.replaceAll("{}", roundNum.toString()) : sourcePGN;
|
|
50
|
+
let isLCC = false;
|
|
52
51
|
try {
|
|
53
|
-
const url = new URL(urlRound(
|
|
52
|
+
const url = new URL(urlRound());
|
|
54
53
|
if (!url.protocol.startsWith("http"))
|
|
55
54
|
throw new Error();
|
|
55
|
+
isLCC = url.hostname === "view.livechesscloud.com";
|
|
56
|
+
if (isLCC && url.hash.length > 1 && !url.hash.endsWith("/{}"))
|
|
57
|
+
throw new Error();
|
|
56
58
|
}
|
|
57
59
|
catch {
|
|
58
|
-
|
|
60
|
+
if (isLCC)
|
|
61
|
+
console.error('Invalid URL. For livechesscloud URLs, please ensure it ends with "/{}".');
|
|
62
|
+
else
|
|
63
|
+
console.error('Invalid URL. Must be http/https with "{}" as round placeholder.');
|
|
59
64
|
process.exit(1);
|
|
60
65
|
}
|
|
61
|
-
|
|
66
|
+
const setRoundFilter = args.includes("--withFilter");
|
|
67
|
+
const sliceIndex = args.indexOf("--slice");
|
|
68
|
+
let setSliceFilter = null;
|
|
69
|
+
if (sliceIndex !== -1 && args.length > sliceIndex + 1) {
|
|
70
|
+
setSliceFilter = args[sliceIndex + 1];
|
|
71
|
+
}
|
|
72
|
+
setPGN(bcast.rounds, urlRound, setRoundFilter, setSliceFilter);
|
|
62
73
|
};
|
|
63
74
|
exports.setPGNCommand = setPGNCommand;
|
package/dist/index.js
CHANGED
|
@@ -4,22 +4,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const process_1 = require("process");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
const delay_1 = require("./cmd/delay");
|
|
7
|
-
const setLCC_1 = require("./cmd/setLCC");
|
|
8
7
|
const setPGN_1 = require("./cmd/setPGN");
|
|
9
|
-
// Ensure LICHESS_TOKEN is set
|
|
10
8
|
if (!utils_1.LICHESS_TOKEN) {
|
|
11
9
|
console.error("Error: LICHESS_TOKEN environment variable is not set.");
|
|
12
10
|
process.exit(1);
|
|
13
11
|
}
|
|
14
12
|
const args = process_1.argv.slice(2);
|
|
15
13
|
(async () => {
|
|
16
|
-
// show version for --version or -v
|
|
17
14
|
if (args.includes("--version") || args.includes("-v")) {
|
|
18
15
|
const { version } = require("../package.json");
|
|
19
16
|
console.log(`libroadcast-cli v${version}`);
|
|
20
17
|
process.exit(0);
|
|
21
18
|
}
|
|
22
|
-
// check args[0] is --help or -h
|
|
23
19
|
if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
|
|
24
20
|
(0, utils_1.showHelp)();
|
|
25
21
|
process.exit(0);
|
|
@@ -27,10 +23,12 @@ const args = process_1.argv.slice(2);
|
|
|
27
23
|
const command = args.shift();
|
|
28
24
|
const commands = new Map([
|
|
29
25
|
[utils_1.Command.Delay, delay_1.delayCommand],
|
|
30
|
-
[utils_1.Command.SetLCC,
|
|
26
|
+
[utils_1.Command.SetLCC, setPGN_1.setPGNCommand],
|
|
31
27
|
[utils_1.Command.SetPGN, setPGN_1.setPGNCommand],
|
|
32
28
|
]);
|
|
33
29
|
const handler = commands.get(command);
|
|
30
|
+
if (command === utils_1.Command.SetLCC)
|
|
31
|
+
console.warn("Warning: 'setLCC' command was removed. Will use 'setPGN' instead.");
|
|
34
32
|
if (!handler) {
|
|
35
33
|
console.error("Unknown command. Supported commands: delay, setLCC, setPGN");
|
|
36
34
|
process.exit(1);
|
package/dist/utils.js
CHANGED
|
@@ -15,14 +15,12 @@ exports.client = (0, openapi_fetch_1.default)({
|
|
|
15
15
|
Accept: "application/json",
|
|
16
16
|
},
|
|
17
17
|
});
|
|
18
|
-
// Commands names
|
|
19
18
|
var Command;
|
|
20
19
|
(function (Command) {
|
|
21
20
|
Command["Delay"] = "delay";
|
|
22
21
|
Command["SetLCC"] = "setLCC";
|
|
23
22
|
Command["SetPGN"] = "setPGN";
|
|
24
23
|
})(Command || (exports.Command = Command = {}));
|
|
25
|
-
// Function to show help messages
|
|
26
24
|
const showHelp = (cmd) => {
|
|
27
25
|
const msg = [
|
|
28
26
|
"Usage: <command> [options]",
|
|
@@ -33,23 +31,27 @@ const showHelp = (cmd) => {
|
|
|
33
31
|
" Options:",
|
|
34
32
|
" --onlyDelay Set only the delay without changing the start time.",
|
|
35
33
|
" --noDelay Remove the delay from the rounds.",
|
|
36
|
-
"
|
|
37
|
-
" Sets the source LCC URL for all rounds in the specified broadcast.",
|
|
38
|
-
" setPGN <broadcastId> <sourcePGNUrl>",
|
|
34
|
+
" setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]",
|
|
39
35
|
" Sets the source PGN URL for all rounds in the specified broadcast.",
|
|
40
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
41
|
"",
|
|
42
42
|
"Examples:",
|
|
43
43
|
" delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time",
|
|
44
|
-
"
|
|
45
|
-
" setPGN bcast123 https://example.com/pgns/round-{}/game.pgn",
|
|
44
|
+
" setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice \"1-5,7,9-12\"",
|
|
46
45
|
];
|
|
47
46
|
const ranges = {
|
|
48
47
|
[Command.Delay]: [3, 8],
|
|
49
|
-
[Command.
|
|
50
|
-
[Command.
|
|
48
|
+
[Command.SetPGN]: [8, 15],
|
|
49
|
+
[Command.SetLCC]: [8, 15],
|
|
51
50
|
};
|
|
52
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
|
+
}
|
|
53
55
|
console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
|
|
54
56
|
};
|
|
55
57
|
exports.showHelp = showHelp;
|
package/package.json
CHANGED
package/dist/cmd/setLCC.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setLCCCommand = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const setSourceLCC = (rounds, sourceLCC) => {
|
|
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: `${sourceLCC}/${rN}`,
|
|
20
|
-
},
|
|
21
|
-
})
|
|
22
|
-
.then((response) => {
|
|
23
|
-
if (response.response.ok)
|
|
24
|
-
console.log(`Successfully set source LCC for round ${round.id} to ${sourceLCC}/${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 setLCCCommand = async (args) => {
|
|
35
|
-
const [bId, sourceLCC] = 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.SetLCC);
|
|
39
|
-
process.exit(0);
|
|
40
|
-
}
|
|
41
|
-
// Validate required args
|
|
42
|
-
if (!bId || !sourceLCC) {
|
|
43
|
-
(0, utils_1.showHelp)(utils_1.Command.SetLCC);
|
|
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
|
-
// check sourceLCC is a valid URL
|
|
52
|
-
let url;
|
|
53
|
-
try {
|
|
54
|
-
url = new URL(sourceLCC.startsWith("http")
|
|
55
|
-
? sourceLCC
|
|
56
|
-
: `https://view.livechesscloud.com/${sourceLCC}`);
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
console.error("sourceLCC must be a valid URL or LCC ID.");
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
setSourceLCC(bcast.rounds, url.toString());
|
|
63
|
-
};
|
|
64
|
-
exports.setLCCCommand = setLCCCommand;
|