tering-serieuze-cli 1.2.0 → 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/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  import { Command } from "commander";
5
5
  import figlet from "figlet";
6
6
  import inquirer from "inquirer";
7
- import { TssApi, FilesystemCache, OnePasswordCache } from "tering-serieuze-sdk";
7
+ import { TssApi, FilesystemCache } from "tering-serieuze-sdk";
8
8
 
9
9
  // src/completion.ts
10
10
  import omelette from "omelette";
@@ -19,6 +19,7 @@ async function initCompletion(api2) {
19
19
  ["clearcache" /* clearcache */]: ["auth", "jingle", "all"],
20
20
  ["login" /* login */]: [],
21
21
  ["play" /* play */]: playCompletion,
22
+ ["recent" /* recent */]: [],
22
23
  ["jingles" /* jingles */]: [],
23
24
  ["p" /* playShort */]: [],
24
25
  ["version" /* version */]: []
@@ -29,7 +30,7 @@ async function initCompletion(api2) {
29
30
  }
30
31
 
31
32
  // package.json
32
- var version = "1.1.1";
33
+ var version = "1.3.0";
33
34
 
34
35
  // src/index.ts
35
36
  var Commands = /* @__PURE__ */ ((Commands2) => {
@@ -37,18 +38,20 @@ var Commands = /* @__PURE__ */ ((Commands2) => {
37
38
  Commands2["clearcache"] = "clearcache";
38
39
  Commands2["login"] = "login";
39
40
  Commands2["play"] = "play";
41
+ Commands2["recent"] = "recent";
40
42
  Commands2["jingles"] = "jingles";
41
43
  Commands2["playShort"] = "p";
42
44
  Commands2["version"] = "version";
43
45
  return Commands2;
44
46
  })(Commands || {});
47
+ var playWhichJingleString = "Which jingle do you want to play?";
45
48
  var api = new TssApi(
46
49
  {
47
50
  API_URL: process.env.API_URL ?? "https://tss.maxserv.dev:8081"
48
51
  },
49
52
  {
50
53
  jingle: new FilesystemCache("jingle"),
51
- auth: new OnePasswordCache("TSS-TOKEN")
54
+ auth: new FilesystemCache("TSS-TOKEN")
52
55
  }
53
56
  );
54
57
  var program = new Command();
@@ -85,7 +88,11 @@ program.command("login" /* login */).description("Authenticate yourself so you c
85
88
  const user = await api.user.get();
86
89
  console.log("Logged in as " + user.email);
87
90
  } catch (e) {
88
- console.error("Invalid token!");
91
+ if (e.status >= 500) {
92
+ console.error("Uit. Dit kan niet gebeuren want TSS geeft een status >= 500 terug");
93
+ } else {
94
+ console.error("Invalid token!");
95
+ }
89
96
  await api.auth.removeToken();
90
97
  }
91
98
  });
@@ -100,6 +107,8 @@ program.command("clearcache" /* clearcache */).description("Clear the cache").ar
100
107
  await api.auth.removeToken();
101
108
  await api.jingle.getCache().clear();
102
109
  console.log("Cleared all caches");
110
+ } else {
111
+ console.error("Invalid cache type");
103
112
  }
104
113
  });
105
114
  program.command("jingles" /* jingles */).description("Show all jingles").action(async () => {
@@ -119,6 +128,25 @@ program.command("play" /* play */).description("Play a jingle").argument("<folde
119
128
  console.error(`ERROR ${e.status}: ${e.message}`);
120
129
  }
121
130
  });
131
+ program.command("recent" /* recent */).description("Show recently added jingles, select a jingle to play").action(async () => {
132
+ try {
133
+ const jingles = await api.jingle.getAll();
134
+ jingles.sort((a, b) => b.mtime - a.mtime);
135
+ const answers = await inquirer.prompt([
136
+ {
137
+ type: "list",
138
+ name: "jingle",
139
+ message: playWhichJingleString,
140
+ choices: jingles.slice(0, 30).map((jingle2) => jingle2.folder + "/" + jingle2.file)
141
+ }
142
+ ]);
143
+ const [folder, file] = answers.jingle.split("/");
144
+ const jingle = { folder, file };
145
+ await api.jingle.play(jingle);
146
+ } catch (e) {
147
+ console.error(e.status + ": " + e.message);
148
+ }
149
+ });
122
150
  program.command("p" /* playShort */).description("Play a jingle by typing (some) parts of the name").argument("<query...>", "The query to search for").action(async (query) => {
123
151
  let jingles;
124
152
  try {
@@ -144,7 +172,7 @@ program.command("p" /* playShort */).description("Play a jingle by typing (some)
144
172
  {
145
173
  type: "list",
146
174
  name: "jingle",
147
- message: "Which jingle do you want to play?",
175
+ message: playWhichJingleString,
148
176
  choices: sortedMatches.map((jingle2) => jingle2.folder + "/" + jingle2.file)
149
177
  }
150
178
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tering-serieuze-cli",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Teringserieuze CLI",
5
5
  "author": "Frank",
6
6
  "main": "dist/index.mjs",
@@ -27,8 +27,8 @@
27
27
  "figlet": "^1.5.2",
28
28
  "inquirer": "^9.1.4",
29
29
  "omelette": "^0.4.17",
30
- "tering-serieuze-sdk": "^2.0.0",
31
- "tering-serieuze-types": "^1.9.0"
30
+ "tering-serieuze-sdk": "^3.0.0",
31
+ "tering-serieuze-types": "^1.14.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/figlet": "^1.5.5",
package/src/completion.ts CHANGED
@@ -15,6 +15,7 @@ export async function initCompletion(api: TssApi) {
15
15
  [Commands.clearcache]: ["auth", "jingle", "all"],
16
16
  [Commands.login]: [],
17
17
  [Commands.play]: playCompletion,
18
+ [Commands.recent]: [],
18
19
  [Commands.jingles]: [],
19
20
  [Commands.playShort]: [],
20
21
  [Commands.version]: [],
package/src/index.ts CHANGED
@@ -13,18 +13,21 @@ export enum Commands {
13
13
  clearcache = "clearcache",
14
14
  login = "login",
15
15
  play = "play",
16
+ recent = "recent",
16
17
  jingles = "jingles",
17
18
  playShort = "p",
18
19
  version = "version",
19
20
  }
20
21
 
22
+ const playWhichJingleString = "Which jingle do you want to play?";
23
+
21
24
  const api = new TssApi(
22
25
  {
23
26
  API_URL: process.env.API_URL ?? "https://tss.maxserv.dev:8081",
24
27
  },
25
28
  {
26
29
  jingle: new FilesystemCache("jingle"),
27
- auth: new OnePasswordCache("TSS-TOKEN"),
30
+ auth: new FilesystemCache("TSS-TOKEN"),
28
31
  }
29
32
  );
30
33
 
@@ -76,8 +79,13 @@ program
76
79
  try {
77
80
  const user = await api.user.get();
78
81
  console.log("Logged in as " + user.email);
79
- } catch (e) {
80
- console.error("Invalid token!");
82
+ } catch (e: any) {
83
+ if (e.status >= 500) {
84
+ console.error("Uit. Dit kan niet gebeuren want TSS geeft een status >= 500 terug");
85
+ } else {
86
+ console.error("Invalid token!");
87
+ }
88
+
81
89
  await api.auth.removeToken();
82
90
  }
83
91
  });
@@ -97,6 +105,8 @@ program
97
105
  await api.auth.removeToken();
98
106
  await api.jingle.getCache().clear();
99
107
  console.log("Cleared all caches");
108
+ } else {
109
+ console.error("Invalid cache type");
100
110
  }
101
111
  });
102
112
 
@@ -127,6 +137,31 @@ program
127
137
  }
128
138
  });
129
139
 
140
+ program
141
+ .command(Commands.recent)
142
+ .description("Show recently added jingles, select a jingle to play")
143
+ .action(async () => {
144
+ try {
145
+ const jingles = await api.jingle.getAll();
146
+ jingles.sort((a, b) => b.mtime - a.mtime);
147
+
148
+ const answers = await inquirer.prompt([
149
+ {
150
+ type: "list",
151
+ name: "jingle",
152
+ message: playWhichJingleString,
153
+ choices: jingles.slice(0, 30).map((jingle) => jingle.folder + "/" + jingle.file),
154
+ },
155
+ ]);
156
+
157
+ const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
158
+ const jingle = { folder, file };
159
+ await api.jingle.play(jingle);
160
+ } catch (e: any) {
161
+ console.error(e.status + ": " + e.message);
162
+ }
163
+ });
164
+
130
165
  program
131
166
  .command(Commands.playShort)
132
167
  .description("Play a jingle by typing (some) parts of the name")
@@ -160,12 +195,12 @@ program
160
195
  {
161
196
  type: "list",
162
197
  name: "jingle",
163
- message: "Which jingle do you want to play?",
198
+ message: playWhichJingleString,
164
199
  choices: sortedMatches.map((jingle) => jingle.folder + "/" + jingle.file),
165
200
  },
166
201
  ]);
167
202
 
168
- const [folder, file] = answers.jingle.split("/");
203
+ const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
169
204
  jingle = { folder, file };
170
205
  }
171
206