libroadcast-cli 1.2.1 → 1.3.1

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 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
- setLCC <broadcastId> <sourceLCCUrl>
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
- setLCC bcast123 https://view.livechesscloud.com/#47c48351-034a-4860-9b94-087490742803
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
@@ -2,53 +2,49 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.delayCommand = void 0;
4
4
  const utils_1 = require("../utils");
5
- const setDelayRounds = (rounds, delay, onlyDelay, noDelay) => rounds.forEach((round) => {
6
- utils_1.client
7
- .POST("/broadcast/round/{broadcastRoundId}/edit", {
8
- params: {
9
- path: { broadcastRoundId: round.id },
10
- // @ts-ignore patch param is not yet documented
11
- query: { patch: 1 },
12
- },
13
- // @ts-ignore name of body properties due patch param is implicit
14
- body: {
15
- delay: noDelay ? undefined : delay,
16
- startsAt: round.startsAt && !onlyDelay
17
- ? round.startsAt + delay * 1000
18
- : undefined,
19
- },
20
- })
21
- .then((response) => {
22
- if (response.response.ok)
23
- console.log(`Successfully set delay for round ${round.id} to ${delay} seconds.`);
24
- else
25
- console.error(`Failed to set delay for round ${round.id}: ${response.response.statusText}`);
26
- })
27
- .catch((error) => {
28
- console.error(`Error setting delay for round ${round.id}:`, error);
29
- });
30
- });
5
+ const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
6
+ for (const round of rounds) {
7
+ await utils_1.client
8
+ .POST("/broadcast/round/{broadcastRoundId}/edit", {
9
+ params: {
10
+ path: { broadcastRoundId: round.id },
11
+ query: { patch: 1 },
12
+ },
13
+ body: {
14
+ delay: noDelay ? undefined : delay,
15
+ startsAt: round.startsAt && !onlyDelay
16
+ ? round.startsAt + delay * 1000
17
+ : undefined,
18
+ },
19
+ })
20
+ .then((response) => {
21
+ if (response.response.ok)
22
+ console.log(`Successfully set delay for round ${round.id} to ${delay} seconds.`);
23
+ else
24
+ console.error(`Failed to set delay for round ${round.id}: ${response.response.statusText}`);
25
+ })
26
+ .catch((error) => {
27
+ console.error(`Error setting delay for round ${round.id}:`, error);
28
+ });
29
+ await (0, utils_1.sleep)(200);
30
+ }
31
+ };
31
32
  const delayCommand = async (args) => {
32
33
  const [broadcastId, delay] = args.slice(0, 2);
33
- // check arg --help or -h
34
34
  if (args.includes("--help") || args.includes("-h")) {
35
35
  (0, utils_1.showHelp)(utils_1.Command.Delay);
36
36
  process.exit(0);
37
37
  }
38
- // Validate required args
39
38
  if (!broadcastId || !delay) {
40
39
  (0, utils_1.showHelp)(utils_1.Command.Delay);
41
40
  process.exit(1);
42
41
  }
43
42
  const delayNum = parseInt(delay, 10);
44
- // Validate delay is a number between 0s and 1h
45
43
  if (isNaN(delayNum) && delayNum >= 0 && delayNum <= 3600) {
46
44
  console.error("Delay must be a number between 0 and 3600 seconds.");
47
45
  process.exit(1);
48
46
  }
49
- // check arg --onlyDelay
50
47
  const onlyDelay = args.includes("--onlyDelay");
51
- // check arg --noDelay
52
48
  const noDelay = args.includes("--noDelay");
53
49
  if (onlyDelay && noDelay) {
54
50
  console.error("Cannot use --onlyDelay and --noDelay together.");
@@ -2,43 +2,41 @@
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) => {
6
- let rN = 1;
7
- rounds.forEach((round) => {
8
- utils_1.client
5
+ const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) => {
6
+ for (let rN = 1; rN <= rounds.length; rN++) {
7
+ const round = rounds[rN];
8
+ const url = urlRound(rN);
9
+ await 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: urlRound(rN),
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 ${urlRound(rN)}.`);
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
  })
28
28
  .catch((error) => {
29
29
  console.error(`Error setting source LCC for round ${round.id}:`, error);
30
30
  });
31
- rN += 1;
32
- });
31
+ await (0, utils_1.sleep)(200);
32
+ }
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(1));
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
- console.error('Invalid URL. Must be http/https with "{}" as round placeholder.');
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
- setPGN(bcast.rounds, urlRound);
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, setLCC_1.setLCCCommand],
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
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBroadcast = exports.showHelp = exports.Command = exports.client = exports.LICHESS_TOKEN = void 0;
6
+ exports.sleep = exports.getBroadcast = exports.showHelp = exports.Command = exports.client = exports.LICHESS_TOKEN = void 0;
7
7
  const process_1 = require("process");
8
8
  const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
9
  exports.LICHESS_TOKEN = process_1.env.LICHESS_TOKEN;
@@ -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
- " setLCC <broadcastId> <sourceLCCUrl>",
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
- " setLCC bcast123 https://view.livechesscloud.com/#47c48351-034a-4860-9b94-087490742803",
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.SetLCC]: [8, 10],
50
- [Command.SetPGN]: [10, 13],
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;
@@ -65,3 +67,5 @@ const getBroadcast = (broadcastId) => exports.client
65
67
  return null;
66
68
  });
67
69
  exports.getBroadcast = getBroadcast;
70
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
71
+ exports.sleep = sleep;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "CLI to help with broadcast maintenance on Lichess",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -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;