@aronnaxlin/bgm-cli 1.0.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/LICENSE +660 -0
- package/README.en.md +122 -0
- package/README.md +127 -0
- package/README.zh-TW.md +122 -0
- package/package.json +41 -0
- package/src/cli.js +993 -0
- package/src/commands/blog.js +213 -0
- package/src/commands/calendar.js +32 -0
- package/src/commands/character.js +291 -0
- package/src/commands/collection.js +418 -0
- package/src/commands/episode.js +379 -0
- package/src/commands/group.js +488 -0
- package/src/commands/index.js +362 -0
- package/src/commands/notify.js +74 -0
- package/src/commands/person.js +297 -0
- package/src/commands/status.js +74 -0
- package/src/commands/subject.js +537 -0
- package/src/commands/timeline.js +288 -0
- package/src/commands/trending.js +58 -0
- package/src/commands/tui.js +1537 -0
- package/src/commands/user.js +83 -0
- package/src/core/client.js +2065 -0
- package/src/core/config.js +450 -0
- package/src/core/http.js +144 -0
- package/src/core/output.js +3888 -0
- package/src/core/proxy.js +47 -0
- package/src/core/reactions.js +62 -0
- package/src/core/turnstile.js +526 -0
- package/src/data/bangumi-emotes.json +311 -0
- package/src/utils/args.js +113 -0
- package/src/utils/auth-flow.js +373 -0
- package/src/utils/auth.js +90 -0
- package/src/utils/calendar.js +23 -0
- package/src/utils/collection-ops.js +333 -0
- package/src/utils/collection.js +240 -0
- package/src/utils/formatters.js +157 -0
- package/src/utils/helpers.js +283 -0
- package/src/utils/hot.js +182 -0
- package/src/utils/install.js +40 -0
- package/src/utils/prompts.js +87 -0
- package/src/utils/relay.js +74 -0
- package/src/utils/status.js +68 -0
- package/src/utils/tui-interactive.js +197 -0
- package/src/utils/tui-render.js +86 -0
- package/src/utils/turnstile-flow.js +154 -0
- package/src/utils/validators.js +412 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input validation and normalization utilities.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { splitFilterValues } from "./args.js";
|
|
6
|
+
import {
|
|
7
|
+
normalizeNonNegativeInteger,
|
|
8
|
+
normalizePositiveInteger,
|
|
9
|
+
parseOptionalInteger,
|
|
10
|
+
} from "./helpers.js";
|
|
11
|
+
import { CommandError } from "../core/output.js";
|
|
12
|
+
|
|
13
|
+
export const SUBJECT_TYPE_MAP = {
|
|
14
|
+
book: 1,
|
|
15
|
+
anime: 2,
|
|
16
|
+
music: 3,
|
|
17
|
+
game: 4,
|
|
18
|
+
real: 6,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const COLLECTION_STATUS_MAP = {
|
|
22
|
+
wish: 1,
|
|
23
|
+
collect: 2,
|
|
24
|
+
done: 2,
|
|
25
|
+
doing: 3,
|
|
26
|
+
do: 3,
|
|
27
|
+
on_hold: 4,
|
|
28
|
+
onhold: 4,
|
|
29
|
+
hold: 4,
|
|
30
|
+
dropped: 5,
|
|
31
|
+
drop: 5,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const EPISODE_COLLECTION_STATUS_MAP = {
|
|
35
|
+
queue: 1,
|
|
36
|
+
wish: 1,
|
|
37
|
+
watched: 2,
|
|
38
|
+
watch: 2,
|
|
39
|
+
done: 2,
|
|
40
|
+
collect: 2,
|
|
41
|
+
drop: 3,
|
|
42
|
+
dropped: 3,
|
|
43
|
+
remove: 0,
|
|
44
|
+
clear: 0,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const EPISODE_TYPE_MAP = {
|
|
48
|
+
main: 0,
|
|
49
|
+
sp: 1,
|
|
50
|
+
op: 2,
|
|
51
|
+
ed: 3,
|
|
52
|
+
trailer: 4,
|
|
53
|
+
pv: 4,
|
|
54
|
+
mad: 5,
|
|
55
|
+
other: 6,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const GROUP_SORT_VALUES = new Set(["posts", "topics", "members", "created", "updated"]);
|
|
59
|
+
export const GROUP_LIST_MODE_VALUES = new Set(["all", "joined", "managed"]);
|
|
60
|
+
export const GROUP_TOPIC_MODE_VALUES = new Set(["all", "joined", "created", "replied"]);
|
|
61
|
+
export const TIMELINE_MODE_VALUES = new Set(["all", "friends"]);
|
|
62
|
+
|
|
63
|
+
export const GROUP_HOT_WINDOWS = {
|
|
64
|
+
day: {
|
|
65
|
+
hours: 24,
|
|
66
|
+
gravity: 1.8,
|
|
67
|
+
groupDecayHours: 6,
|
|
68
|
+
},
|
|
69
|
+
week: {
|
|
70
|
+
hours: 24 * 7,
|
|
71
|
+
gravity: 1.4,
|
|
72
|
+
groupDecayHours: 24,
|
|
73
|
+
},
|
|
74
|
+
month: {
|
|
75
|
+
hours: 24 * 30,
|
|
76
|
+
gravity: 1.1,
|
|
77
|
+
groupDecayHours: 72,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const GROUP_MEMBER_ROLE_MAP = {
|
|
82
|
+
visitor: -2,
|
|
83
|
+
guest: -1,
|
|
84
|
+
member: 0,
|
|
85
|
+
creator: 1,
|
|
86
|
+
owner: 1,
|
|
87
|
+
moderator: 2,
|
|
88
|
+
admin: 2,
|
|
89
|
+
blocked: 3,
|
|
90
|
+
ban: 3,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const INDEX_RELATED_CATEGORY_MAP = {
|
|
94
|
+
subject: 0,
|
|
95
|
+
character: 1,
|
|
96
|
+
person: 2,
|
|
97
|
+
ep: 3,
|
|
98
|
+
episode: 3,
|
|
99
|
+
blog: 4,
|
|
100
|
+
group_topic: 5,
|
|
101
|
+
grouptopic: 5,
|
|
102
|
+
subject_topic: 6,
|
|
103
|
+
subjecttopic: 6,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export function normalizeSubjectType(value) {
|
|
107
|
+
if (value === undefined || value === null || value === "") {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (/^\d+$/.test(String(value))) {
|
|
112
|
+
return Number(value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const normalized = SUBJECT_TYPE_MAP[String(value).toLowerCase()];
|
|
116
|
+
if (!normalized) {
|
|
117
|
+
throw new CommandError(`Unsupported subject type: ${value}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return normalized;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function normalizeSubjectTypeFilter(value) {
|
|
124
|
+
if (value === undefined || value === null || value === "") {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return splitFilterValues(value).map((entry) => normalizeSubjectType(entry));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function normalizeCollectionStatusFilter(value) {
|
|
132
|
+
if (value === undefined || value === null || value === "") {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return splitFilterValues(value).map((entry) => {
|
|
137
|
+
const numeric = /^\d+$/.test(entry) ? Number(entry) : undefined;
|
|
138
|
+
if (numeric) {
|
|
139
|
+
return numeric;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const normalized = COLLECTION_STATUS_MAP[entry.toLowerCase()];
|
|
143
|
+
if (!normalized) {
|
|
144
|
+
throw new CommandError(`Unsupported collection status: ${entry}`);
|
|
145
|
+
}
|
|
146
|
+
return normalized;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function normalizeCollectionStatusValue(value) {
|
|
151
|
+
if (value === undefined || value === null || value === "") {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const normalized = normalizeCollectionStatusFilter(value);
|
|
156
|
+
if (normalized.length !== 1) {
|
|
157
|
+
throw new CommandError(`Expected exactly one collection status, received: ${value}`);
|
|
158
|
+
}
|
|
159
|
+
return normalized[0];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function normalizeEpisodeCollectionStatusValue(value) {
|
|
163
|
+
if (value === undefined || value === null || value === "") {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const normalized = String(value).toLowerCase();
|
|
168
|
+
if (/^\d+$/.test(normalized)) {
|
|
169
|
+
const numeric = Number(normalized);
|
|
170
|
+
if ([0, 1, 2, 3].includes(numeric)) {
|
|
171
|
+
return numeric;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const resolved = EPISODE_COLLECTION_STATUS_MAP[normalized];
|
|
176
|
+
if (resolved === undefined) {
|
|
177
|
+
throw new CommandError(`Unsupported episode status: ${value}`);
|
|
178
|
+
}
|
|
179
|
+
return resolved;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function normalizeEpisodeTypeFilter(value) {
|
|
183
|
+
if (value === undefined || value === null || value === "") {
|
|
184
|
+
return {
|
|
185
|
+
label: undefined,
|
|
186
|
+
queryType: undefined,
|
|
187
|
+
matchTypes: null,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const normalized = String(value).toLowerCase();
|
|
192
|
+
if (normalized === "op_ed") {
|
|
193
|
+
return {
|
|
194
|
+
label: "op_ed",
|
|
195
|
+
queryType: undefined,
|
|
196
|
+
matchTypes: new Set([EPISODE_TYPE_MAP.op, EPISODE_TYPE_MAP.ed]),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (/^\d+$/.test(normalized)) {
|
|
201
|
+
const numeric = Number(normalized);
|
|
202
|
+
if (numeric < 0 || numeric > 6) {
|
|
203
|
+
throw new CommandError(`Unsupported episode type: ${value}`);
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
label: numeric,
|
|
207
|
+
queryType: numeric,
|
|
208
|
+
matchTypes: null,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const resolved = EPISODE_TYPE_MAP[normalized];
|
|
213
|
+
if (resolved === undefined) {
|
|
214
|
+
throw new CommandError(`Unsupported episode type: ${value}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
label: normalized,
|
|
219
|
+
queryType: resolved,
|
|
220
|
+
matchTypes: null,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function normalizeCollectionSort(value) {
|
|
225
|
+
if (value === undefined || value === null || value === "") {
|
|
226
|
+
return "updated";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const normalized = String(value).toLowerCase();
|
|
230
|
+
const aliases = {
|
|
231
|
+
score: "community_score",
|
|
232
|
+
community: "community_score",
|
|
233
|
+
rating: "community_score",
|
|
234
|
+
my_score: "user_score",
|
|
235
|
+
user: "user_score",
|
|
236
|
+
};
|
|
237
|
+
const resolved = aliases[normalized] ?? normalized;
|
|
238
|
+
|
|
239
|
+
if (!["updated", "name", "rank", "community_score", "user_score", "date"].includes(resolved)) {
|
|
240
|
+
throw new CommandError(`Unsupported sort field: ${value}`);
|
|
241
|
+
}
|
|
242
|
+
return resolved;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function normalizeGroupSort(value) {
|
|
246
|
+
if (value === undefined || value === null || value === "") {
|
|
247
|
+
return "created";
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const normalized = String(value).toLowerCase();
|
|
251
|
+
if (!GROUP_SORT_VALUES.has(normalized)) {
|
|
252
|
+
throw new CommandError(`Unsupported group sort: ${value}`);
|
|
253
|
+
}
|
|
254
|
+
return normalized;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function normalizeGroupListMode(value) {
|
|
258
|
+
if (value === undefined || value === null || value === "") {
|
|
259
|
+
return "all";
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const normalized = String(value).toLowerCase();
|
|
263
|
+
if (!GROUP_LIST_MODE_VALUES.has(normalized)) {
|
|
264
|
+
throw new CommandError(`Unsupported group list mode: ${value}`);
|
|
265
|
+
}
|
|
266
|
+
return normalized;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function normalizeGroupTopicMode(value) {
|
|
270
|
+
if (value === undefined || value === null || value === "") {
|
|
271
|
+
return "all";
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const normalized = String(value).toLowerCase();
|
|
275
|
+
if (!GROUP_TOPIC_MODE_VALUES.has(normalized)) {
|
|
276
|
+
throw new CommandError(`Unsupported group topic mode: ${value}`);
|
|
277
|
+
}
|
|
278
|
+
return normalized;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function normalizeStatusSite(value) {
|
|
282
|
+
if (value === undefined || value === null || value === "") {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const normalized = String(value).toLowerCase();
|
|
287
|
+
if (!["bgm.tv", "bangumi.tv", "chii.in"].includes(normalized)) {
|
|
288
|
+
throw new CommandError(`Unsupported status site: ${value}`);
|
|
289
|
+
}
|
|
290
|
+
return normalized;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function normalizeStatusAudience(value) {
|
|
294
|
+
if (value === undefined || value === null || value === "") {
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const normalized = String(value).toLowerCase();
|
|
299
|
+
if (["auth", "authenticated"].includes(normalized)) {
|
|
300
|
+
return "Authenticated";
|
|
301
|
+
}
|
|
302
|
+
if (normalized === "guest") {
|
|
303
|
+
return "Guest";
|
|
304
|
+
}
|
|
305
|
+
throw new CommandError(`Unsupported status audience: ${value}`);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function normalizeIndexRelatedCategory(value) {
|
|
309
|
+
if (value === undefined || value === null || value === "") {
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (/^\d+$/.test(String(value))) {
|
|
314
|
+
return Number(value);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const normalized = INDEX_RELATED_CATEGORY_MAP[String(value).toLowerCase()];
|
|
318
|
+
if (normalized === undefined) {
|
|
319
|
+
throw new CommandError(`Unsupported index related category: ${value}`);
|
|
320
|
+
}
|
|
321
|
+
return normalized;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function normalizeTimelineMode(value) {
|
|
325
|
+
if (value === undefined || value === null || value === "") {
|
|
326
|
+
return "all";
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const normalized = String(value).toLowerCase();
|
|
330
|
+
if (!TIMELINE_MODE_VALUES.has(normalized)) {
|
|
331
|
+
throw new CommandError(`Unsupported timeline mode: ${value}`);
|
|
332
|
+
}
|
|
333
|
+
return normalized;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function normalizeTimelineLimit(value) {
|
|
337
|
+
const parsed = normalizePositiveInteger(value, "limit");
|
|
338
|
+
if (parsed === undefined) {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
if (parsed > 20) {
|
|
342
|
+
throw new CommandError(`Expected limit to be <= 20, received: ${value}`);
|
|
343
|
+
}
|
|
344
|
+
return parsed;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function normalizeGroupHotWindow(value) {
|
|
348
|
+
if (value === undefined || value === null || value === "") {
|
|
349
|
+
return "day";
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const normalized = String(value).toLowerCase();
|
|
353
|
+
if (!Object.hasOwn(GROUP_HOT_WINDOWS, normalized)) {
|
|
354
|
+
throw new CommandError(`Unsupported hot window: ${value}`);
|
|
355
|
+
}
|
|
356
|
+
return normalized;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export function normalizeGroupMemberRole(value) {
|
|
360
|
+
if (value === undefined || value === null || value === "") {
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (/^-?\d+$/.test(String(value))) {
|
|
365
|
+
return Number(value);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const normalized = GROUP_MEMBER_ROLE_MAP[String(value).toLowerCase()];
|
|
369
|
+
if (normalized === undefined) {
|
|
370
|
+
throw new CommandError(`Unsupported group member role: ${value}`);
|
|
371
|
+
}
|
|
372
|
+
return normalized;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function normalizeHotResultLimit(value) {
|
|
376
|
+
const parsed = normalizeNonNegativeInteger(value, "limit");
|
|
377
|
+
if (parsed === undefined) {
|
|
378
|
+
return 20;
|
|
379
|
+
}
|
|
380
|
+
if (parsed === 0 || parsed > 100) {
|
|
381
|
+
throw new CommandError(`Expected limit to be between 1 and 100, received: ${value}`);
|
|
382
|
+
}
|
|
383
|
+
return parsed;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export function normalizeHotScanLimit(value, window) {
|
|
387
|
+
const defaults = {
|
|
388
|
+
day: 300,
|
|
389
|
+
week: 1000,
|
|
390
|
+
month: 3000,
|
|
391
|
+
};
|
|
392
|
+
const parsed = normalizeNonNegativeInteger(value, "scan");
|
|
393
|
+
if (parsed === undefined) {
|
|
394
|
+
return defaults[window];
|
|
395
|
+
}
|
|
396
|
+
if (parsed === 0 || parsed > 5000) {
|
|
397
|
+
throw new CommandError(`Expected scan to be between 1 and 5000, received: ${value}`);
|
|
398
|
+
}
|
|
399
|
+
return parsed;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export function normalizeSortOrder(value) {
|
|
403
|
+
if (value === undefined || value === null || value === "") {
|
|
404
|
+
return "desc";
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const normalized = String(value).toLowerCase();
|
|
408
|
+
if (!["asc", "desc"].includes(normalized)) {
|
|
409
|
+
throw new CommandError(`Unsupported sort order: ${value}`);
|
|
410
|
+
}
|
|
411
|
+
return normalized;
|
|
412
|
+
}
|