@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.
Files changed (46) hide show
  1. package/LICENSE +660 -0
  2. package/README.en.md +122 -0
  3. package/README.md +127 -0
  4. package/README.zh-TW.md +122 -0
  5. package/package.json +41 -0
  6. package/src/cli.js +993 -0
  7. package/src/commands/blog.js +213 -0
  8. package/src/commands/calendar.js +32 -0
  9. package/src/commands/character.js +291 -0
  10. package/src/commands/collection.js +418 -0
  11. package/src/commands/episode.js +379 -0
  12. package/src/commands/group.js +488 -0
  13. package/src/commands/index.js +362 -0
  14. package/src/commands/notify.js +74 -0
  15. package/src/commands/person.js +297 -0
  16. package/src/commands/status.js +74 -0
  17. package/src/commands/subject.js +537 -0
  18. package/src/commands/timeline.js +288 -0
  19. package/src/commands/trending.js +58 -0
  20. package/src/commands/tui.js +1537 -0
  21. package/src/commands/user.js +83 -0
  22. package/src/core/client.js +2065 -0
  23. package/src/core/config.js +450 -0
  24. package/src/core/http.js +144 -0
  25. package/src/core/output.js +3888 -0
  26. package/src/core/proxy.js +47 -0
  27. package/src/core/reactions.js +62 -0
  28. package/src/core/turnstile.js +526 -0
  29. package/src/data/bangumi-emotes.json +311 -0
  30. package/src/utils/args.js +113 -0
  31. package/src/utils/auth-flow.js +373 -0
  32. package/src/utils/auth.js +90 -0
  33. package/src/utils/calendar.js +23 -0
  34. package/src/utils/collection-ops.js +333 -0
  35. package/src/utils/collection.js +240 -0
  36. package/src/utils/formatters.js +157 -0
  37. package/src/utils/helpers.js +283 -0
  38. package/src/utils/hot.js +182 -0
  39. package/src/utils/install.js +40 -0
  40. package/src/utils/prompts.js +87 -0
  41. package/src/utils/relay.js +74 -0
  42. package/src/utils/status.js +68 -0
  43. package/src/utils/tui-interactive.js +197 -0
  44. package/src/utils/tui-render.js +86 -0
  45. package/src/utils/turnstile-flow.js +154 -0
  46. package/src/utils/validators.js +412 -0
@@ -0,0 +1,83 @@
1
+ import { BangumiClient } from "../core/client.js";
2
+ import { getConfig } from "../core/config.js";
3
+ import { CommandError, printResult } from "../core/output.js";
4
+ import { firstPositional, parseFlags } from "../utils/args.js";
5
+ import {
6
+ normalizeNonNegativeInteger,
7
+ normalizePageSize,
8
+ resolveUsernameOrMe,
9
+ } from "../utils/helpers.js";
10
+
11
+ export async function runUserCommand(command, args, context) {
12
+ switch (command) {
13
+ case "me": {
14
+ const client = new BangumiClient(getConfig());
15
+ const me = await client.getMe();
16
+ printResult(me, context);
17
+ return;
18
+ }
19
+ case "get": {
20
+ const options = parseFlags(args);
21
+ const client = new BangumiClient(getConfig());
22
+ const username = firstPositional(options);
23
+ if (!username) {
24
+ throw new CommandError("Usage: bgm user get <username_or_initial_uid>");
25
+ }
26
+
27
+ const user = await client.getUser(username);
28
+ printResult(user, context);
29
+ return;
30
+ }
31
+ case "friends": {
32
+ const result = await executeUserFriendsCommand(args);
33
+ printResult(result, context);
34
+ return;
35
+ }
36
+ case "followers": {
37
+ const result = await executeUserFollowersCommand(args);
38
+ printResult(result, context);
39
+ return;
40
+ }
41
+ default:
42
+ throw new CommandError("Usage: bgm user <me|get|friends|followers> ...");
43
+ }
44
+ }
45
+
46
+ async function executeUserFriendsCommand(args) {
47
+ const { client, username, query } = await parseUserListArgs(args);
48
+ const result = await client.listUserFriends(username, query);
49
+ return {
50
+ ...result,
51
+ resource: "user-friends",
52
+ title: "User friends",
53
+ username,
54
+ filters: query,
55
+ };
56
+ }
57
+
58
+ async function executeUserFollowersCommand(args) {
59
+ const { client, username, query } = await parseUserListArgs(args);
60
+ const result = await client.listUserFollowers(username, query);
61
+ return {
62
+ ...result,
63
+ resource: "user-followers",
64
+ title: "User followers",
65
+ username,
66
+ filters: query,
67
+ };
68
+ }
69
+
70
+ async function parseUserListArgs(args) {
71
+ const options = parseFlags(args);
72
+ const client = new BangumiClient(getConfig());
73
+ const username = await resolveUsernameOrMe(client, firstPositional(options));
74
+
75
+ return {
76
+ client,
77
+ username,
78
+ query: {
79
+ limit: normalizePageSize(options.limit),
80
+ offset: normalizeNonNegativeInteger(options.offset, "offset"),
81
+ },
82
+ };
83
+ }