@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,488 @@
|
|
|
1
|
+
import { BangumiClient } from "../core/client.js";
|
|
2
|
+
import { getConfig } from "../core/config.js";
|
|
3
|
+
import { CommandError, printResult } from "../core/output.js";
|
|
4
|
+
import { normalizeBangumiReactionValue } from "../core/reactions.js";
|
|
5
|
+
import { firstPositional, getPositional, parseFlags } from "../utils/args.js";
|
|
6
|
+
import {
|
|
7
|
+
normalizeNonNegativeInteger,
|
|
8
|
+
normalizePageSize,
|
|
9
|
+
resolveUsernameOrMe,
|
|
10
|
+
} from "../utils/helpers.js";
|
|
11
|
+
import {
|
|
12
|
+
normalizeGroupHotWindow,
|
|
13
|
+
normalizeGroupListMode,
|
|
14
|
+
normalizeGroupMemberRole,
|
|
15
|
+
normalizeGroupSort,
|
|
16
|
+
normalizeGroupTopicMode,
|
|
17
|
+
normalizeHotResultLimit,
|
|
18
|
+
normalizeHotScanLimit,
|
|
19
|
+
} from "../utils/validators.js";
|
|
20
|
+
import {
|
|
21
|
+
aggregateHotGroups,
|
|
22
|
+
computeHotCutoffTimestamp,
|
|
23
|
+
fetchRecentRepliedTopics,
|
|
24
|
+
fetchTopicsForHotWindow,
|
|
25
|
+
rankHotTopics,
|
|
26
|
+
} from "../utils/hot.js";
|
|
27
|
+
import { resolveTurnstileTokenForMutation } from "../utils/turnstile-flow.js";
|
|
28
|
+
|
|
29
|
+
export async function runGroupCommand(command, args, context) {
|
|
30
|
+
switch (command) {
|
|
31
|
+
case "list": {
|
|
32
|
+
const result = await executeGroupListCommand(args);
|
|
33
|
+
printResult(result, context);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
case "get": {
|
|
37
|
+
const result = await executeGroupGetCommand(args);
|
|
38
|
+
printResult(result, context);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
case "topics": {
|
|
42
|
+
const result = await executeGroupTopicsCommand(args);
|
|
43
|
+
printResult(result, context);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
case "topic": {
|
|
47
|
+
const result = await executeGroupTopicCommand(args);
|
|
48
|
+
printResult(result, context);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
case "create-topic": {
|
|
52
|
+
const result = await executeGroupCreateTopicCommand(args, context);
|
|
53
|
+
printResult(result, context);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
case "reply": {
|
|
57
|
+
const result = await executeGroupReplyCommand(args, context);
|
|
58
|
+
printResult(result, context);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
case "edit-topic": {
|
|
62
|
+
const result = await executeGroupEditTopicCommand(args);
|
|
63
|
+
printResult(result, context);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
case "post": {
|
|
67
|
+
const result = await executeGroupPostCommand(args);
|
|
68
|
+
printResult(result, context);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
case "edit-post": {
|
|
72
|
+
const result = await executeGroupEditPostCommand(args);
|
|
73
|
+
printResult(result, context);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
case "delete-post": {
|
|
77
|
+
const result = await executeGroupDeletePostCommand(args);
|
|
78
|
+
printResult(result, context);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
case "like-post": {
|
|
82
|
+
const result = await executeGroupLikePostCommand(args);
|
|
83
|
+
printResult(result, context);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
case "unlike-post": {
|
|
87
|
+
const result = await executeGroupUnlikePostCommand(args);
|
|
88
|
+
printResult(result, context);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
case "members": {
|
|
92
|
+
const result = await executeGroupMembersCommand(args);
|
|
93
|
+
printResult(result, context);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
case "user": {
|
|
97
|
+
const result = await executeUserGroupsCommand(args);
|
|
98
|
+
printResult(result, context);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
case "recent-topics": {
|
|
102
|
+
const result = await executeRecentGroupTopicsCommand(args);
|
|
103
|
+
printResult(result, context);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
case "latest-replies": {
|
|
107
|
+
const result = await executeLatestRepliedGroupTopicsCommand(args);
|
|
108
|
+
printResult(result, context);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
case "hot": {
|
|
112
|
+
const result = await executeHotGroupsCommand(args);
|
|
113
|
+
printResult(result, context);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
case "hot-topics": {
|
|
117
|
+
const result = await executeHotGroupTopicsCommand(args);
|
|
118
|
+
printResult(result, context);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
throw new CommandError("Usage: bgm group <list|get|topics|topic|create-topic|reply|edit-topic|post|edit-post|delete-post|like-post|unlike-post|members|user|recent-topics|latest-replies|hot|hot-topics> ...");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function executeGroupListCommand(args) {
|
|
127
|
+
const options = parseFlags(args);
|
|
128
|
+
const client = new BangumiClient(getConfig());
|
|
129
|
+
const mode = normalizeGroupListMode(options.mode);
|
|
130
|
+
const sort = normalizeGroupSort(options.sort);
|
|
131
|
+
const limit = normalizePageSize(options.limit);
|
|
132
|
+
const offset = normalizeNonNegativeInteger(options.offset, "offset");
|
|
133
|
+
const result = await client.listGroups({
|
|
134
|
+
mode,
|
|
135
|
+
sort,
|
|
136
|
+
limit,
|
|
137
|
+
offset,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
...result,
|
|
142
|
+
resource: "group-list",
|
|
143
|
+
filters: { mode, sort, limit, offset },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function executeGroupGetCommand(args) {
|
|
148
|
+
const options = parseFlags(args);
|
|
149
|
+
const client = new BangumiClient(getConfig());
|
|
150
|
+
const groupName = firstPositional(options);
|
|
151
|
+
if (!groupName) {
|
|
152
|
+
throw new CommandError("Usage: bgm group get <group_name>");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return client.getGroup(groupName);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export async function executeGroupTopicsCommand(args) {
|
|
159
|
+
const options = parseFlags(args);
|
|
160
|
+
const client = new BangumiClient(getConfig());
|
|
161
|
+
const groupName = firstPositional(options);
|
|
162
|
+
if (!groupName) {
|
|
163
|
+
throw new CommandError("Usage: bgm group topics <group_name> [--limit n] [--offset n]");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const limit = normalizePageSize(options.limit);
|
|
167
|
+
const offset = normalizeNonNegativeInteger(options.offset, "offset");
|
|
168
|
+
const result = await client.listGroupTopics(groupName, {
|
|
169
|
+
limit,
|
|
170
|
+
offset,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
...result,
|
|
175
|
+
resource: "group-topics",
|
|
176
|
+
groupName: String(groupName),
|
|
177
|
+
filters: { limit, offset },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function executeGroupTopicCommand(args) {
|
|
182
|
+
const options = parseFlags(args);
|
|
183
|
+
const client = new BangumiClient(getConfig());
|
|
184
|
+
const topicId = firstPositional(options);
|
|
185
|
+
if (!topicId) {
|
|
186
|
+
throw new CommandError("Usage: bgm group topic <topic_id> [--reply-limit n]");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const replyLimit = normalizeNonNegativeInteger(options.replyLimit, "reply-limit") ?? 20;
|
|
190
|
+
const topic = await client.getGroupTopic(topicId);
|
|
191
|
+
return {
|
|
192
|
+
...topic,
|
|
193
|
+
resource: "group-topic-detail",
|
|
194
|
+
filters: {
|
|
195
|
+
replyLimit,
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export async function executeGroupCreateTopicCommand(args, context = {}) {
|
|
201
|
+
const options = parseFlags(args);
|
|
202
|
+
const client = new BangumiClient(getConfig());
|
|
203
|
+
const groupName = firstPositional(options);
|
|
204
|
+
const title = getPositional(options, 1) ?? options.title;
|
|
205
|
+
const content = getPositional(options, 2) ?? options.content;
|
|
206
|
+
|
|
207
|
+
if (!groupName || !title || !content) {
|
|
208
|
+
throw new CommandError("Usage: bgm group create-topic <group_name> <title> <content> [--turnstile-token <token>] [--manual] [--listen-host <host>] [--port <n>] [--public-origin <url>] [--timeout-seconds <n>]");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const turnstileToken = await resolveTurnstileTokenForMutation(options, {
|
|
212
|
+
actionLabel: "create a group topic",
|
|
213
|
+
context,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const result = await client.createGroupTopic(groupName, {
|
|
217
|
+
title,
|
|
218
|
+
content,
|
|
219
|
+
turnstileToken,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
resource: "group-topic-mutation",
|
|
224
|
+
action: "create-topic",
|
|
225
|
+
groupName: String(groupName),
|
|
226
|
+
title: String(title),
|
|
227
|
+
topicId: result.id,
|
|
228
|
+
url: result.id ? `https://bgm.tv/group/topic/${result.id}` : undefined,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function executeGroupReplyCommand(args, context = {}) {
|
|
233
|
+
const options = parseFlags(args);
|
|
234
|
+
const client = new BangumiClient(getConfig());
|
|
235
|
+
const topicId = firstPositional(options);
|
|
236
|
+
const content = getPositional(options, 1) ?? options.content;
|
|
237
|
+
const replyTo = normalizeNonNegativeInteger(options.replyTo, "reply-to") ?? 0;
|
|
238
|
+
|
|
239
|
+
if (!topicId || !content) {
|
|
240
|
+
throw new CommandError("Usage: bgm group reply <topic_id> <content> [--reply-to <reply_id>] [--turnstile-token <token>] [--manual] [--listen-host <host>] [--port <n>] [--public-origin <url>] [--timeout-seconds <n>]");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const turnstileToken = await resolveTurnstileTokenForMutation(options, {
|
|
244
|
+
actionLabel: "reply to a group topic",
|
|
245
|
+
context,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const result = await client.createGroupReply(topicId, {
|
|
249
|
+
content,
|
|
250
|
+
replyTo,
|
|
251
|
+
turnstileToken,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
resource: "group-topic-mutation",
|
|
256
|
+
action: "reply",
|
|
257
|
+
topicId: Number(topicId),
|
|
258
|
+
postId: result.id,
|
|
259
|
+
replyTo,
|
|
260
|
+
url: `https://bgm.tv/group/topic/${topicId}`,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export async function executeGroupEditTopicCommand(args) {
|
|
265
|
+
const options = parseFlags(args);
|
|
266
|
+
const topicId = firstPositional(options);
|
|
267
|
+
const title = getPositional(options, 1) ?? options.title;
|
|
268
|
+
const content = getPositional(options, 2) ?? options.content;
|
|
269
|
+
if (!topicId || !title || !content) {
|
|
270
|
+
throw new CommandError("Usage: bgm group edit-topic <topic_id> <title> <content>");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
await new BangumiClient(getConfig()).updateGroupTopic(topicId, { title, content });
|
|
274
|
+
return {
|
|
275
|
+
resource: "group-topic-mutation",
|
|
276
|
+
action: "edit-topic",
|
|
277
|
+
topicId: Number(topicId),
|
|
278
|
+
title: String(title),
|
|
279
|
+
url: `https://bgm.tv/group/topic/${topicId}`,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export async function executeGroupPostCommand(args) {
|
|
284
|
+
const options = parseFlags(args);
|
|
285
|
+
const postId = firstPositional(options);
|
|
286
|
+
if (!postId) {
|
|
287
|
+
throw new CommandError("Usage: bgm group post <post_id>");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
resource: "topic-post",
|
|
292
|
+
scope: "group",
|
|
293
|
+
postId: Number(postId),
|
|
294
|
+
data: await new BangumiClient(getConfig()).getGroupPost(postId),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export async function executeGroupEditPostCommand(args) {
|
|
299
|
+
const options = parseFlags(args);
|
|
300
|
+
const postId = firstPositional(options);
|
|
301
|
+
const content = getPositional(options, 1) ?? options.content;
|
|
302
|
+
if (!postId || !content) {
|
|
303
|
+
throw new CommandError("Usage: bgm group edit-post <post_id> <content>");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
await new BangumiClient(getConfig()).updateGroupPost(postId, { content });
|
|
307
|
+
return buildGroupPostMutationResult("edit-post", { postId });
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export async function executeGroupDeletePostCommand(args) {
|
|
311
|
+
const options = parseFlags(args);
|
|
312
|
+
const postId = firstPositional(options);
|
|
313
|
+
if (!postId) {
|
|
314
|
+
throw new CommandError("Usage: bgm group delete-post <post_id>");
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
await new BangumiClient(getConfig()).deleteGroupPost(postId);
|
|
318
|
+
return buildGroupPostMutationResult("delete-post", { postId });
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export async function executeGroupLikePostCommand(args) {
|
|
322
|
+
const options = parseFlags(args);
|
|
323
|
+
const postId = firstPositional(options);
|
|
324
|
+
const value = normalizeBangumiReactionValue(options.value ?? getPositional(options, 1), "groupPost");
|
|
325
|
+
if (!postId || value === undefined) {
|
|
326
|
+
throw new CommandError("Usage: bgm group like-post <post_id> <value>");
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
await new BangumiClient(getConfig()).likeGroupPost(postId, value);
|
|
330
|
+
return buildGroupPostMutationResult("like-post", { postId, value });
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export async function executeGroupUnlikePostCommand(args) {
|
|
334
|
+
const options = parseFlags(args);
|
|
335
|
+
const postId = firstPositional(options);
|
|
336
|
+
if (!postId) {
|
|
337
|
+
throw new CommandError("Usage: bgm group unlike-post <post_id>");
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
await new BangumiClient(getConfig()).unlikeGroupPost(postId);
|
|
341
|
+
return buildGroupPostMutationResult("unlike-post", { postId });
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function buildGroupPostMutationResult(action, details) {
|
|
345
|
+
return {
|
|
346
|
+
resource: "post-mutation",
|
|
347
|
+
scope: "group",
|
|
348
|
+
action,
|
|
349
|
+
postId: Number(details.postId),
|
|
350
|
+
value: details.value,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export async function executeGroupMembersCommand(args) {
|
|
355
|
+
const options = parseFlags(args);
|
|
356
|
+
const client = new BangumiClient(getConfig());
|
|
357
|
+
const groupName = firstPositional(options);
|
|
358
|
+
if (!groupName) {
|
|
359
|
+
throw new CommandError("Usage: bgm group members <group_name> [--role member] [--limit n] [--offset n]");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const role = normalizeGroupMemberRole(options.role);
|
|
363
|
+
const limit = normalizePageSize(options.limit);
|
|
364
|
+
const offset = normalizeNonNegativeInteger(options.offset, "offset");
|
|
365
|
+
const result = await client.listGroupMembers(groupName, {
|
|
366
|
+
role,
|
|
367
|
+
limit,
|
|
368
|
+
offset,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
return {
|
|
372
|
+
...result,
|
|
373
|
+
resource: "group-members",
|
|
374
|
+
groupName: String(groupName),
|
|
375
|
+
filters: { role, limit, offset },
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export async function executeUserGroupsCommand(args) {
|
|
380
|
+
const options = parseFlags(args);
|
|
381
|
+
const client = new BangumiClient(getConfig());
|
|
382
|
+
const username = await resolveUsernameOrMe(client, firstPositional(options));
|
|
383
|
+
|
|
384
|
+
const limit = normalizePageSize(options.limit);
|
|
385
|
+
const offset = normalizeNonNegativeInteger(options.offset, "offset");
|
|
386
|
+
const result = await client.listUserGroups(username, { limit, offset });
|
|
387
|
+
return {
|
|
388
|
+
...result,
|
|
389
|
+
resource: "group-list",
|
|
390
|
+
title: "User groups",
|
|
391
|
+
username: String(username),
|
|
392
|
+
filters: { mode: `user:${username}`, limit, offset },
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export async function executeRecentGroupTopicsCommand(args) {
|
|
397
|
+
const options = parseFlags(args);
|
|
398
|
+
const client = new BangumiClient(getConfig());
|
|
399
|
+
const mode = normalizeGroupTopicMode(options.mode);
|
|
400
|
+
const limit = normalizePageSize(options.limit);
|
|
401
|
+
const offset = normalizeNonNegativeInteger(options.offset, "offset");
|
|
402
|
+
const result = await client.listRecentGroupTopics({
|
|
403
|
+
mode,
|
|
404
|
+
limit,
|
|
405
|
+
offset,
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
return {
|
|
409
|
+
...result,
|
|
410
|
+
resource: "group-recent-topics",
|
|
411
|
+
filters: { mode, limit, offset },
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export async function executeLatestRepliedGroupTopicsCommand(args) {
|
|
416
|
+
const options = parseFlags(args);
|
|
417
|
+
const client = new BangumiClient(getConfig());
|
|
418
|
+
const mode = normalizeGroupTopicMode(options.mode);
|
|
419
|
+
const limit = normalizeHotResultLimit(options.limit);
|
|
420
|
+
const scan = normalizeHotScanLimit(options.scan, "day");
|
|
421
|
+
const topics = await fetchRecentRepliedTopics(client, {
|
|
422
|
+
mode,
|
|
423
|
+
limit,
|
|
424
|
+
scan,
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
resource: "group-latest-replies",
|
|
429
|
+
data: topics,
|
|
430
|
+
total: topics.length,
|
|
431
|
+
filters: {
|
|
432
|
+
mode,
|
|
433
|
+
limit,
|
|
434
|
+
scan,
|
|
435
|
+
},
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export async function executeHotGroupsCommand(args) {
|
|
440
|
+
const options = parseFlags(args);
|
|
441
|
+
const client = new BangumiClient(getConfig());
|
|
442
|
+
const window = normalizeGroupHotWindow(options.window);
|
|
443
|
+
const mode = normalizeGroupTopicMode(options.mode);
|
|
444
|
+
const limit = normalizeHotResultLimit(options.limit);
|
|
445
|
+
const scan = normalizeHotScanLimit(options.scan, window);
|
|
446
|
+
const topics = await fetchTopicsForHotWindow(client, { window, mode, scan });
|
|
447
|
+
const rankedTopics = rankHotTopics(topics, window);
|
|
448
|
+
const grouped = aggregateHotGroups(rankedTopics, window).slice(0, limit);
|
|
449
|
+
|
|
450
|
+
return {
|
|
451
|
+
resource: "group-hot",
|
|
452
|
+
data: grouped,
|
|
453
|
+
total: grouped.length,
|
|
454
|
+
filters: {
|
|
455
|
+
window,
|
|
456
|
+
mode,
|
|
457
|
+
limit,
|
|
458
|
+
scan,
|
|
459
|
+
sampledTopics: rankedTopics.length,
|
|
460
|
+
cutoff: computeHotCutoffTimestamp(window),
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export async function executeHotGroupTopicsCommand(args) {
|
|
466
|
+
const options = parseFlags(args);
|
|
467
|
+
const client = new BangumiClient(getConfig());
|
|
468
|
+
const window = normalizeGroupHotWindow(options.window);
|
|
469
|
+
const mode = normalizeGroupTopicMode(options.mode);
|
|
470
|
+
const limit = normalizeHotResultLimit(options.limit);
|
|
471
|
+
const scan = normalizeHotScanLimit(options.scan, window);
|
|
472
|
+
const topics = await fetchTopicsForHotWindow(client, { window, mode, scan });
|
|
473
|
+
const ranked = rankHotTopics(topics, window).slice(0, limit);
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
resource: "group-hot-topics",
|
|
477
|
+
data: ranked,
|
|
478
|
+
total: ranked.length,
|
|
479
|
+
filters: {
|
|
480
|
+
window,
|
|
481
|
+
mode,
|
|
482
|
+
limit,
|
|
483
|
+
scan,
|
|
484
|
+
sampledTopics: topics.length,
|
|
485
|
+
cutoff: computeHotCutoffTimestamp(window),
|
|
486
|
+
},
|
|
487
|
+
};
|
|
488
|
+
}
|