@aronnaxlin/bgm-cli 1.1.2 → 1.1.3
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/package.json +1 -1
- package/src/commands/search.js +20 -3
- package/src/core/community-api.js +14 -45
- package/src/core/output.js +5 -1
- package/src/core/reactions.js +7 -7
- package/src/data/bangumi-emotes.json +4 -4
package/package.json
CHANGED
package/src/commands/search.js
CHANGED
|
@@ -59,7 +59,7 @@ export async function runSearchCommand(command, args, context) {
|
|
|
59
59
|
}
|
|
60
60
|
case "reply":
|
|
61
61
|
case "replies": {
|
|
62
|
-
const result = await executeEntitySearch("replies", args, searchReplies);
|
|
62
|
+
const result = await executeEntitySearch("replies", args, searchReplies, { allowSource: true });
|
|
63
63
|
printResult(result, context);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
@@ -82,11 +82,17 @@ export async function runSearchCommand(command, args, context) {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
const REPLY_SOURCES = new Set([
|
|
86
|
+
"all", "group", "subject", "episode", "ep", "character", "crt", "person", "prsn", "blog",
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
async function executeEntitySearch(resource, args, searchFn, { allowSource = false } = {}) {
|
|
86
90
|
const options = parseFlags(args);
|
|
87
91
|
const keyword = firstPositional(options);
|
|
88
92
|
if (!keyword) {
|
|
89
|
-
throw new CommandError(
|
|
93
|
+
throw new CommandError(
|
|
94
|
+
`Usage: bgm search ${resource} <keyword> [--limit n] [--offset n] [--sort <sort>]${allowSource ? " [--source <source>]" : ""}`,
|
|
95
|
+
);
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
const query = {
|
|
@@ -98,6 +104,16 @@ async function executeEntitySearch(resource, args, searchFn) {
|
|
|
98
104
|
query.sort = options.sort;
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
if (allowSource && options.source) {
|
|
108
|
+
const source = String(options.source).toLowerCase();
|
|
109
|
+
if (!REPLY_SOURCES.has(source)) {
|
|
110
|
+
throw new CommandError(
|
|
111
|
+
"Invalid --source. Use one of: all, group, subject, episode (ep), character (crt), person (prsn), blog.",
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
query.source = source;
|
|
115
|
+
}
|
|
116
|
+
|
|
101
117
|
const result = await searchFn(query);
|
|
102
118
|
|
|
103
119
|
return {
|
|
@@ -109,6 +125,7 @@ async function executeEntitySearch(resource, args, searchFn) {
|
|
|
109
125
|
limit: query.limit,
|
|
110
126
|
offset: query.offset,
|
|
111
127
|
sort: query.sort,
|
|
128
|
+
...(query.source ? { source: query.source } : {}),
|
|
112
129
|
},
|
|
113
130
|
};
|
|
114
131
|
}
|
|
@@ -49,6 +49,12 @@ async function communityRequest(path, options = {}) {
|
|
|
49
49
|
return adaptEnvelope(raw);
|
|
50
50
|
} catch (error) {
|
|
51
51
|
if (error instanceof BangumiApiError) {
|
|
52
|
+
if (isCloudflareChallenge(error)) {
|
|
53
|
+
throw new BangumiCommunityApiError(
|
|
54
|
+
`SearchEncore (bgmdb.ry.mk) rejected the request with a Cloudflare bot challenge (HTTP ${error.status}).`,
|
|
55
|
+
{ status: error.status, details: { url, path } },
|
|
56
|
+
);
|
|
57
|
+
}
|
|
52
58
|
throw new BangumiCommunityApiError(error.message, {
|
|
53
59
|
status: error.status,
|
|
54
60
|
details: error.details,
|
|
@@ -63,6 +69,13 @@ async function communityRequest(path, options = {}) {
|
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
|
|
72
|
+
function isCloudflareChallenge(error) {
|
|
73
|
+
return (
|
|
74
|
+
typeof error.details === "string" &&
|
|
75
|
+
error.details.includes("cdn-cgi/challenge-platform")
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
66
79
|
/**
|
|
67
80
|
* 将第三方的 envelope 格式适配为官方风格:
|
|
68
81
|
* 原始: { data, pagination: { total, limit, offset }, meta: { executionMs } }
|
|
@@ -110,6 +123,7 @@ function buildSearchQuery(params = {}) {
|
|
|
110
123
|
if (params.limit !== undefined) q.limit = params.limit;
|
|
111
124
|
if (params.offset !== undefined) q.offset = params.offset;
|
|
112
125
|
if (params.sort !== undefined) q.sort = params.sort;
|
|
126
|
+
if (params.source !== undefined) q.source = params.source;
|
|
113
127
|
return q;
|
|
114
128
|
}
|
|
115
129
|
|
|
@@ -208,20 +222,6 @@ export async function listGroupTopics(groupKey, query = {}) {
|
|
|
208
222
|
return communityRequest(`/groups/${encode(groupKey)}/topics`, { query });
|
|
209
223
|
}
|
|
210
224
|
|
|
211
|
-
/**
|
|
212
|
-
* 获取指定用户的所有小组话题。
|
|
213
|
-
*/
|
|
214
|
-
export async function listUserGroupTopics(userKey, query = {}) {
|
|
215
|
-
return communityRequest(`/users/${encode(userKey)}/group-topics`, { query });
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* 获取最新的条目话题列表。
|
|
220
|
-
*/
|
|
221
|
-
export async function listRecentSubjectTopics(query = {}) {
|
|
222
|
-
return communityRequest("/subjects/-/topics", { query });
|
|
223
|
-
}
|
|
224
|
-
|
|
225
225
|
/**
|
|
226
226
|
* 获取指定条目的话题列表。
|
|
227
227
|
*/
|
|
@@ -229,27 +229,6 @@ export async function listSubjectTopics(subjectId, query = {}) {
|
|
|
229
229
|
return communityRequest(`/subjects/${encode(subjectId)}/topics`, { query });
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
/**
|
|
233
|
-
* 获取指定用户的所有条目话题。
|
|
234
|
-
*/
|
|
235
|
-
export async function listUserSubjectTopics(userKey, query = {}) {
|
|
236
|
-
return communityRequest(`/users/${encode(userKey)}/subject-topics`, { query });
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* 获取指定用户的目录列表。
|
|
241
|
-
*/
|
|
242
|
-
export async function listUserIndexes(userKey, query = {}) {
|
|
243
|
-
return communityRequest(`/users/${encode(userKey)}/indexes`, { query });
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 获取指定用户的日志列表。
|
|
248
|
-
*/
|
|
249
|
-
export async function listUserBlogs(userKey, query = {}) {
|
|
250
|
-
return communityRequest(`/users/${encode(userKey)}/blogs`, { query });
|
|
251
|
-
}
|
|
252
|
-
|
|
253
232
|
/* ------------------------------------------------------------------ */
|
|
254
233
|
/* 详情接口 */
|
|
255
234
|
/* ------------------------------------------------------------------ */
|
|
@@ -264,16 +243,6 @@ export async function getUser(userKey) {
|
|
|
264
243
|
return communityRequest(`/users/${encode(userKey)}`);
|
|
265
244
|
}
|
|
266
245
|
|
|
267
|
-
/**
|
|
268
|
-
* 获取用户头像历史记录。
|
|
269
|
-
*/
|
|
270
|
-
export async function getUserAvatarHistory(userKey) {
|
|
271
|
-
if (!userKey) {
|
|
272
|
-
throw new BangumiCommunityApiError("Missing userKey.");
|
|
273
|
-
}
|
|
274
|
-
return communityRequest(`/users/${encode(userKey)}/avatars`);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
246
|
/**
|
|
278
247
|
* 获取单个小组信息。
|
|
279
248
|
*/
|
package/src/core/output.js
CHANGED
|
@@ -181,7 +181,7 @@ function buildUsageText(target) {
|
|
|
181
181
|
["bgm [--json] search group <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search groups via SearchEncore."],
|
|
182
182
|
["bgm [--json] search topic <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search group topics via SearchEncore."],
|
|
183
183
|
["bgm [--json] search subject-topic <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search subject topics via SearchEncore."],
|
|
184
|
-
["bgm [--json] search reply <keyword> [--limit n] [--offset n] [--sort <
|
|
184
|
+
["bgm [--json] search reply <keyword> [--limit n] [--offset n] [--sort newest|oldest] [--source <source>]", "Search replies via SearchEncore. Source: all|group|subject|episode|character|person|blog."],
|
|
185
185
|
["bgm [--json] search index <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search indexes via SearchEncore."],
|
|
186
186
|
["bgm [--json] search blog <keyword> [--limit n] [--offset n] [--sort <sort>]", "Search blogs via SearchEncore."],
|
|
187
187
|
], [
|
|
@@ -190,6 +190,10 @@ function buildUsageText(target) {
|
|
|
190
190
|
" (bgmdb.ry.mk). Data is crawled/aggregated, NOT from bangumi.tv",
|
|
191
191
|
" official sources. Every response is tagged with",
|
|
192
192
|
" _meta.isSearchEncore = true for downstream identification.",
|
|
193
|
+
"",
|
|
194
|
+
" --sort: newest|oldest|popular (aliases new|old|hot); anything else ranks by relevance.",
|
|
195
|
+
" Keywords accept inline directives: user:<name|uid> group:<slug>",
|
|
196
|
+
" type:<anime|book|music|game|real> exact:true include:nsfw exclude:nsfw include:blocked",
|
|
193
197
|
]);
|
|
194
198
|
case "notify":
|
|
195
199
|
return buildGroupUsage("Notify", [
|
package/src/core/reactions.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { CommandError } from "./output.js";
|
|
2
2
|
|
|
3
|
-
const TOPIC_POST_REACTION_VALUES = Object.freeze([54, 62, 79, 80, 85, 88, 90, 104, 122, 140]);
|
|
4
|
-
const SUBJECT_COLLECT_REACTION_VALUES = Object.freeze([54]);
|
|
3
|
+
const TOPIC_POST_REACTION_VALUES = Object.freeze([0, 54, 62, 79, 80, 85, 88, 90, 104, 122, 140, 141]);
|
|
4
|
+
const SUBJECT_COLLECT_REACTION_VALUES = Object.freeze([0, 54, 80, 88, 90, 104, 122, 140]);
|
|
5
5
|
|
|
6
6
|
export const BANGUMI_REACTION_TARGETS = Object.freeze({
|
|
7
7
|
subjectPost: Object.freeze({
|
|
8
8
|
label: "subject discussion reply",
|
|
9
9
|
allowedValues: TOPIC_POST_REACTION_VALUES,
|
|
10
|
-
note: "Subject and group topic replies share the p1 topic-post reaction shape; values
|
|
10
|
+
note: "Subject and group topic replies share the p1 topic-post reaction shape; values mirror ALLOWED_COMMON_REACTIONS in bangumi/server-private lib/like.ts.",
|
|
11
11
|
}),
|
|
12
12
|
groupPost: Object.freeze({
|
|
13
13
|
label: "group topic reply",
|
|
14
14
|
allowedValues: TOPIC_POST_REACTION_VALUES,
|
|
15
|
-
note: "Values
|
|
15
|
+
note: "Values mirror ALLOWED_COMMON_REACTIONS in bangumi/server-private lib/like.ts.",
|
|
16
16
|
}),
|
|
17
17
|
episodeComment: Object.freeze({
|
|
18
18
|
label: "episode comment",
|
|
@@ -22,7 +22,7 @@ export const BANGUMI_REACTION_TARGETS = Object.freeze({
|
|
|
22
22
|
subjectCollect: Object.freeze({
|
|
23
23
|
label: "subject collection comment",
|
|
24
24
|
allowedValues: SUBJECT_COLLECT_REACTION_VALUES,
|
|
25
|
-
note: "
|
|
25
|
+
note: "Values mirror ALLOWED_SUBJECT_COLLECT_REACTIONS in bangumi/server-private lib/like.ts; 79 and 141 are not accepted here.",
|
|
26
26
|
}),
|
|
27
27
|
timeline: Object.freeze({
|
|
28
28
|
label: "timeline entry",
|
|
@@ -40,8 +40,8 @@ export function normalizeBangumiReactionValue(value, targetKey) {
|
|
|
40
40
|
if (Number.isNaN(parsed)) {
|
|
41
41
|
throw new CommandError(`Expected reaction value to be an integer, received: ${value}`);
|
|
42
42
|
}
|
|
43
|
-
if (parsed
|
|
44
|
-
throw new CommandError(`Expected reaction value to be
|
|
43
|
+
if (parsed < 0) {
|
|
44
|
+
throw new CommandError(`Expected reaction value to be >= 0, received: ${value}`);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const target = BANGUMI_REACTION_TARGETS[targetKey];
|
|
@@ -299,12 +299,12 @@
|
|
|
299
299
|
"description": "Bangumi p1 反应贴贴白名单。不是所有表情都能用于 like/unlike。",
|
|
300
300
|
"verifiedTargets": {
|
|
301
301
|
"groupPost": {
|
|
302
|
-
"values": [54, 62, 79, 80, 85, 88, 90, 104, 122, 140],
|
|
303
|
-
"source": "
|
|
302
|
+
"values": [0, 54, 62, 79, 80, 85, 88, 90, 104, 122, 140, 141],
|
|
303
|
+
"source": "ALLOWED_COMMON_REACTIONS in bangumi/server-private lib/like.ts (2026-09)."
|
|
304
304
|
},
|
|
305
305
|
"subjectCollect": {
|
|
306
|
-
"values": [54],
|
|
307
|
-
"source": "
|
|
306
|
+
"values": [0, 54, 80, 88, 90, 104, 122, 140],
|
|
307
|
+
"source": "ALLOWED_SUBJECT_COLLECT_REACTIONS in bangumi/server-private lib/like.ts (2026-09)."
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
}
|