@wkgeo/cli 0.0.0-stage → 1.1.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/CHANGELOG.md +223 -0
- package/LICENSE +21 -0
- package/README.md +1042 -3
- package/SKILL.md +927 -0
- package/lib/ai/client.mjs +161 -0
- package/lib/ai/config.mjs +221 -0
- package/lib/ai/context.mjs +468 -0
- package/lib/ai/log.mjs +53 -0
- package/lib/api.mjs +339 -0
- package/lib/args.mjs +235 -0
- package/lib/cli.mjs +168 -0
- package/lib/cms.mjs +330 -0
- package/lib/commands/ai.mjs +392 -0
- package/lib/commands/apps.mjs +116 -0
- package/lib/commands/auth.mjs +1288 -0
- package/lib/commands/billing.mjs +666 -0
- package/lib/commands/cms.mjs +2533 -0
- package/lib/commands/config-auth.mjs +621 -0
- package/lib/commands/config.mjs +434 -0
- package/lib/commands/dnscred.mjs +428 -0
- package/lib/commands/domainops.mjs +546 -0
- package/lib/commands/domainorder.mjs +439 -0
- package/lib/commands/import.mjs +164 -0
- package/lib/commands/index.mjs +541 -0
- package/lib/commands/logs.mjs +141 -0
- package/lib/commands/orders.mjs +444 -0
- package/lib/commands/overview.mjs +394 -0
- package/lib/commands/plugins.mjs +678 -0
- package/lib/commands/site.mjs +435 -0
- package/lib/commands/siteops.mjs +1012 -0
- package/lib/commands/sites.mjs +905 -0
- package/lib/commands/skill.mjs +119 -0
- package/lib/commands/template.mjs +258 -0
- package/lib/config.mjs +351 -0
- package/lib/credentials.mjs +160 -0
- package/lib/device-store.mjs +132 -0
- package/lib/device.mjs +464 -0
- package/lib/errors.mjs +299 -0
- package/lib/format.mjs +339 -0
- package/lib/http.mjs +71 -0
- package/lib/index.mjs +44 -0
- package/lib/local-import.mjs +185 -0
- package/lib/login.mjs +1638 -0
- package/lib/oauth-urls.mjs +163 -0
- package/lib/page.mjs +393 -0
- package/lib/pkce.mjs +48 -0
- package/lib/proxy.mjs +454 -0
- package/lib/qr.mjs +31 -0
- package/lib/runtime.mjs +650 -0
- package/lib/site-state.mjs +137 -0
- package/lib/tar.mjs +207 -0
- package/lib/template-package.mjs +522 -0
- package/package.json +53 -4
- package/wkgeo.mjs +17 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 站点参数配置命令(B7 / task-92):`config get` / `config save` / `config review` / `config capabilities`。
|
|
3
|
+
*
|
|
4
|
+
* ## 这一层是什么
|
|
5
|
+
* task-92(2026-10-29)把 CMS `actionTable` 里剩下的 8 条"控制台类"动作搬进 CLI 自己的
|
|
6
|
+
* 云函数 `wkgeo-cli-fc`(`src/console-core.js`,逐字复制 CMS handler + 本地归属闸)。
|
|
7
|
+
* 本文件覆盖其中 4 条:
|
|
8
|
+
* * `config get` → `configGet`(读 `site.settings` + 内联白名单 / TLD 表)
|
|
9
|
+
* * `config save` → `configSave`(写 `site.settings`,IP 黑名单与统计代码走各自的表)
|
|
10
|
+
* * `config review` → `configReview`(审核统计代码,**双闸**:`REVIEW_TOKEN` + `x-review-token`)
|
|
11
|
+
* * `config capabilities` → `cmsAccessCapabilities`(会员 / 支付两档后台能不能选)
|
|
12
|
+
*
|
|
13
|
+
* ## 三条口径(与 B1 内容面 / B3 发布面 / B4 站点面 / B5 插件面完全一致)
|
|
14
|
+
* 1. **站点必须先定**:`--site` > `WKONGAI_SITE` > `wkgeo site use` 记住的那个;
|
|
15
|
+
* 一个都没有就当场报用法错误(`consoleCall` 统一挡,不多跑一次往返)。
|
|
16
|
+
* 2. **写动作默认 dry-run**:`config save` / `config review` 不加 `--confirm` 只打印
|
|
17
|
+
* "将要发什么",一个写请求都不发。
|
|
18
|
+
* 3. **默认人类可读,`--json` 给原始数据**(信封由 `runtime.done()` 统一包)。
|
|
19
|
+
*
|
|
20
|
+
* ## 权限面
|
|
21
|
+
* * 读(`get` / `capabilities`)⇒ `site:read`
|
|
22
|
+
* * 写(`save` / `review`)⇒ `site:write`;**服务端还会校验站点归属**
|
|
23
|
+
* (不是自己名下站一律 403 `not_site_owner`,站不存在 / 已删除回 404,不泄露站名与业主)
|
|
24
|
+
* * `review` 另有第二道闸:函数环境变量 `REVIEW_TOKEN` 与请求头 `x-review-token` 必须一致;
|
|
25
|
+
* **没配这个环境变量就一律 503**(免得没配好反而人人能审)
|
|
26
|
+
*
|
|
27
|
+
* ## 别在这里做的事
|
|
28
|
+
* * ❌ 不走 `/cms` 转发面(B7 起这 4 条都改走 `/cli` 自持通道)
|
|
29
|
+
* * ❌ 不在 CLI 侧校验参数取值:白名单、IP 规则、统计代码域名白名单、跨字段必填
|
|
30
|
+
* 全在服务端(逐字复制 CMS 的 `paramWhitelist` / `validateIpRule` / `validateStatsCode`),
|
|
31
|
+
* CLI 只负责把 JSON 原样递过去 —— 两边各写一套必然出现"CLI 放过了、后端 500"
|
|
32
|
+
* * ❌ 不把 `x-review-token` 放进 body:那个值只走请求头(不进日志、不进审计 detail)
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { UsageError } from '../errors.mjs';
|
|
36
|
+
|
|
37
|
+
/* ------------------------------------------------------------------ 公共小工具 */
|
|
38
|
+
|
|
39
|
+
/** 所有控制台类命令共用的 `--site`(默认取 `wkgeo site use` 选中的站点) */
|
|
40
|
+
const SITE_FLAG = {
|
|
41
|
+
site: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
desc: '站点 ID(uuid;默认用 `wkgeo site use` 选中的站点,可用 WKONGAI_SITE 覆盖)',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** 写动作的确认闸:不加就 dry-run */
|
|
48
|
+
const CONFIRM_FLAG = {
|
|
49
|
+
confirm: {
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
desc: '真发(不加只打印将要发什么,一个写请求都不发)',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function siteIdOf(ctx) {
|
|
56
|
+
const site = ctx.cmsSite();
|
|
57
|
+
return (site && site.id) || '';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function siteText(ctx) {
|
|
61
|
+
const site = ctx.cmsSite();
|
|
62
|
+
if (!site || !site.id) return '(未选站)';
|
|
63
|
+
return site.label ? `${site.label}(${site.id})` : String(site.id);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* dry-run:把"将要发什么"打印出来就**结束**(不发请求、退出码 0)。
|
|
68
|
+
*
|
|
69
|
+
* `request` 也进 `--json`:agent 拿 dry-run 结果做二次确认时要能核对
|
|
70
|
+
* "我要发的就是这些",光有人类文案不够机器读。
|
|
71
|
+
*/
|
|
72
|
+
function dryRun(ctx, action, request, lines) {
|
|
73
|
+
const data = {
|
|
74
|
+
dry_run: true,
|
|
75
|
+
action,
|
|
76
|
+
site_id: siteIdOf(ctx),
|
|
77
|
+
request,
|
|
78
|
+
confirm_hint: '确认无误后加 --confirm 真发',
|
|
79
|
+
};
|
|
80
|
+
const { out } = ctx;
|
|
81
|
+
if (!out.json) {
|
|
82
|
+
out.head(`dry-run:${action}(没有发送任何写请求)`);
|
|
83
|
+
out.line(` 站点:${siteText(ctx)}`);
|
|
84
|
+
for (const l of lines || []) out.line(` ${l}`);
|
|
85
|
+
out.line('');
|
|
86
|
+
out.line(' 确认无误后加 --confirm 真发。');
|
|
87
|
+
}
|
|
88
|
+
ctx.done(data);
|
|
89
|
+
return data;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 服务端动作名(同时用于 dry-run 回执里的 `action`) */
|
|
93
|
+
const ACTION = {
|
|
94
|
+
configGet: 'configGet',
|
|
95
|
+
configSave: 'configSave',
|
|
96
|
+
configReview: 'configReview',
|
|
97
|
+
cmsAccessCapabilities: 'cmsAccessCapabilities',
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** 参数类型的中文名(服务端给的是 `选项` / `数字` / `文本` / `长文本`,这里只补缺) */
|
|
101
|
+
const TYPE_LABEL = {
|
|
102
|
+
选项: '选项',
|
|
103
|
+
数字: '数字',
|
|
104
|
+
文本: '文本',
|
|
105
|
+
长文本: '长文本',
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** 展示用:长文本截断(`ipBlockList` / `statsCode` 动辄几百上千字,终端里塞不下) */
|
|
109
|
+
function clip(value, max = 48) {
|
|
110
|
+
if (value === undefined || value === null) return '';
|
|
111
|
+
if (Array.isArray(value)) {
|
|
112
|
+
const s = value.join(', ');
|
|
113
|
+
return s.length > max ? `${s.slice(0, max)}…(共 ${value.length} 条)` : s;
|
|
114
|
+
}
|
|
115
|
+
const s = String(value);
|
|
116
|
+
if (s === '') return '(空)';
|
|
117
|
+
const oneLine = s.replace(/\s+/g, ' ');
|
|
118
|
+
return oneLine.length > max ? `${oneLine.slice(0, max)}…(${s.length} 字)` : oneLine;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* ══════════════════════════════ 读参数(get) ══════════════════════════════ */
|
|
122
|
+
|
|
123
|
+
export const configGetCommand = {
|
|
124
|
+
name: 'config get',
|
|
125
|
+
summary: '看本站参数(站点状态 / 手机版 / 统计代码 / 水印 / IP 黑名单;只读)',
|
|
126
|
+
usage: 'wkgeo config get [--key <参数名>] [--site <站点ID>] [--json]',
|
|
127
|
+
args: [],
|
|
128
|
+
flags: {
|
|
129
|
+
key: { type: 'string', desc: '只看某一项(如 statsCode)或某一类(选项 / 数字 / 文本 / 长文本)' },
|
|
130
|
+
...SITE_FLAG,
|
|
131
|
+
},
|
|
132
|
+
examples: [
|
|
133
|
+
'wkgeo config get',
|
|
134
|
+
'wkgeo config get --key statsStatus',
|
|
135
|
+
'wkgeo config get --key 选项 --json',
|
|
136
|
+
],
|
|
137
|
+
notes: [
|
|
138
|
+
'需要 `site:read`(只读)。',
|
|
139
|
+
'`statsStatus` 是统计代码的审核状态:改过 `statsCode` 就会变「待审核」,**只有「已通过」**才有 `activeStatsCode`(前台真正输出的那段)。',
|
|
140
|
+
'`activeStatsCode` 是后端算出来的只读项(界面只展示、不给改);`config save` 里带上它会被静默忽略。',
|
|
141
|
+
'`allowed_domains` 是允许贴进统计代码的第三方域名白名单;`tlds` 是域名后缀表(下发一次就够,别再问服务端)。',
|
|
142
|
+
],
|
|
143
|
+
async run(ctx) {
|
|
144
|
+
const { out } = ctx;
|
|
145
|
+
const data = (await ctx.consoleCall(ACTION.configGet)) || {};
|
|
146
|
+
const value = (data && data.value) || {};
|
|
147
|
+
const schema = (data && data.schema) || {};
|
|
148
|
+
const keys = Object.keys(schema);
|
|
149
|
+
|
|
150
|
+
const wanted = String(ctx.flags.key || '').trim();
|
|
151
|
+
const picked = wanted
|
|
152
|
+
? keys.filter((k) => k === wanted || schema[k].type === wanted)
|
|
153
|
+
: keys;
|
|
154
|
+
if (wanted && !picked.length) {
|
|
155
|
+
throw new UsageError(`没有这个参数:${wanted}`, {
|
|
156
|
+
hint: `可用参数:${keys.join(' / ')}(也可以按类型筛:选项 / 数字 / 文本 / 长文本)`,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const rows = picked.map((k) => {
|
|
161
|
+
const one = schema[k] || {};
|
|
162
|
+
return {
|
|
163
|
+
key: k,
|
|
164
|
+
type: TYPE_LABEL[one.type] || String(one.type || ''),
|
|
165
|
+
current: clip(value[k]),
|
|
166
|
+
default: clip(one.defaultValue),
|
|
167
|
+
readonly: one.readOnly === true,
|
|
168
|
+
options: Array.isArray(one.options) ? one.options.join(' / ') : '',
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const payload = {
|
|
173
|
+
site_id: siteIdOf(ctx),
|
|
174
|
+
total: rows.length,
|
|
175
|
+
stats_status: String(value.statsStatus || ''),
|
|
176
|
+
values: picked.reduce((acc, k) => {
|
|
177
|
+
acc[k] = value[k];
|
|
178
|
+
return acc;
|
|
179
|
+
}, {}),
|
|
180
|
+
schema: picked.reduce((acc, k) => {
|
|
181
|
+
acc[k] = schema[k];
|
|
182
|
+
return acc;
|
|
183
|
+
}, {}),
|
|
184
|
+
allowed_domains: Array.isArray(data.allowedDomains) ? data.allowedDomains : [],
|
|
185
|
+
tlds: Array.isArray(data.tlds) ? data.tlds : [],
|
|
186
|
+
second_level_tlds: Array.isArray(data.secondLevelTlds) ? data.secondLevelTlds : [],
|
|
187
|
+
params: rows,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
if (!out.json) {
|
|
191
|
+
out.head(`站点参数(站点 ${siteText(ctx)})`);
|
|
192
|
+
out.table(
|
|
193
|
+
[
|
|
194
|
+
{ title: '参数', key: 'key', width: 20 },
|
|
195
|
+
{ title: '类型', key: 'type', width: 8 },
|
|
196
|
+
{ title: '当前值', key: 'current', width: 40 },
|
|
197
|
+
{ title: '默认', key: 'default', width: 16 },
|
|
198
|
+
],
|
|
199
|
+
rows.map((one) => ({ ...one, key: one.key + (one.readonly ? '(只读)' : '') })),
|
|
200
|
+
);
|
|
201
|
+
out.line(` 合计 ${rows.length} 项`);
|
|
202
|
+
const status = payload.stats_status;
|
|
203
|
+
if (status === '待审核') {
|
|
204
|
+
out.warn('统计代码当前「待审核」:前台还没输出,审核通过后才生效(`wkgeo config review`)。');
|
|
205
|
+
} else if (status === '已驳回') {
|
|
206
|
+
out.warn(`统计代码「已驳回」:${clip(value.statsRejectReason, 80)}`);
|
|
207
|
+
}
|
|
208
|
+
out.info('改参数:`wkgeo config save --set \'{"siteStatus":"关闭"}\'`(默认 dry-run,加 --confirm 真发)');
|
|
209
|
+
}
|
|
210
|
+
ctx.done(payload);
|
|
211
|
+
return payload;
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/* ══════════════════════════════ 写参数(save) ══════════════════════════════ */
|
|
216
|
+
|
|
217
|
+
export const configSaveCommand = {
|
|
218
|
+
name: 'config save',
|
|
219
|
+
summary: '保存本站参数(只改你给了的键,其余保持原样;默认 dry-run)',
|
|
220
|
+
usage: 'wkgeo config save --set <JSON> [--confirm] [--site <站点ID>]',
|
|
221
|
+
args: [],
|
|
222
|
+
flags: {
|
|
223
|
+
set: {
|
|
224
|
+
type: 'string',
|
|
225
|
+
required: true,
|
|
226
|
+
desc: '要改的参数 JSON(键 = 参数名):{"siteStatus":"关闭","closeNotice":"维护中"};只传要改的键即可',
|
|
227
|
+
},
|
|
228
|
+
...CONFIRM_FLAG,
|
|
229
|
+
...SITE_FLAG,
|
|
230
|
+
},
|
|
231
|
+
examples: [
|
|
232
|
+
'wkgeo config save --set \'{"siteStatus":"关闭","closeNotice":"维护中"}\' # dry-run',
|
|
233
|
+
'wkgeo config save --set \'{"watermarkEnabled":"启用"}\' --confirm # 真存',
|
|
234
|
+
'wkgeo config save --set \'{"ipBlockList":["1.2.3.4","10.0.0.0/8"]}\' --confirm # 整段替换',
|
|
235
|
+
],
|
|
236
|
+
notes: [
|
|
237
|
+
'需要 `site:write`。**默认 dry-run**,加 `--confirm` 才真发。',
|
|
238
|
+
'只改**你给了的键**:服务端把 `--set` 合并进现有 `site.settings`,没给的保持原样(不用先 `config get` 再传全量)。',
|
|
239
|
+
'白名单外的键会被**静默丢弃**(不会报错,也不会写进库)—— 键名以 `wkgeo config get` 的清单为准。',
|
|
240
|
+
'`ipBlockList` 是**整段替换**(不是追加):传数组,最多 500 条,每条要过 IP / CIDR 校验;传 `[]` 就是清空。',
|
|
241
|
+
'`statsCode` 改了就会置「待审核」,**必须等审核通过**(`wkgeo config review`)前台才输出;`activeStatsCode` 是只读的,传了也没用。',
|
|
242
|
+
'独立手机站(`mobileSiteEnabled=启用`)时 `mobileDomain` 必填,且必须是合法域名(服务端跨字段校验)。',
|
|
243
|
+
'只读账号回 403(人话:你是只读账号,不能改参数)。',
|
|
244
|
+
],
|
|
245
|
+
async run(ctx) {
|
|
246
|
+
const { out } = ctx;
|
|
247
|
+
const raw = String(ctx.flags.set || '');
|
|
248
|
+
let patch;
|
|
249
|
+
try {
|
|
250
|
+
patch = JSON.parse(raw);
|
|
251
|
+
} catch (e) {
|
|
252
|
+
throw new UsageError(`--set 不是合法 JSON:${e && e.message ? e.message : e}`);
|
|
253
|
+
}
|
|
254
|
+
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
|
|
255
|
+
throw new UsageError('--set 必须是对象:{"键":"值"}(IP 黑名单传数组)');
|
|
256
|
+
}
|
|
257
|
+
const keys = Object.keys(patch);
|
|
258
|
+
if (!keys.length) throw new UsageError('--set 是空对象,没有要改的参数');
|
|
259
|
+
|
|
260
|
+
const body = { value: patch };
|
|
261
|
+
const lines = keys.map((k) => `${k} → ${clip(patch[k], 60)}`);
|
|
262
|
+
if (!ctx.flags.confirm) {
|
|
263
|
+
return dryRun(ctx, ACTION.configSave, body, [`要改的项:${keys.length} 项`, ...lines]);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const res = (await ctx.consoleCall(ACTION.configSave, body)) || {};
|
|
267
|
+
const saved = res.value && typeof res.value === 'object' ? res.value : {};
|
|
268
|
+
const data = {
|
|
269
|
+
site_id: siteIdOf(ctx),
|
|
270
|
+
saved: res.saved !== false,
|
|
271
|
+
changed: keys,
|
|
272
|
+
values: keys.reduce((acc, k) => {
|
|
273
|
+
acc[k] = saved[k];
|
|
274
|
+
return acc;
|
|
275
|
+
}, {}),
|
|
276
|
+
stats_status: String(saved.statsStatus || ''),
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
if (!out.json) {
|
|
280
|
+
out.ok(`参数已保存:${keys.length} 项(${keys.join('、')})`);
|
|
281
|
+
for (const k of keys) out.line(` ${k}:${clip(saved[k], 60)}`);
|
|
282
|
+
if (data.stats_status === '待审核') {
|
|
283
|
+
out.warn('统计代码已提交「待审核」:前台暂时不输出,审核通过后才生效。');
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
ctx.done(data);
|
|
287
|
+
return data;
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/* ══════════════════════════════ 审核统计代码(review) ══════════════════════════════ */
|
|
292
|
+
|
|
293
|
+
export const configReviewCommand = {
|
|
294
|
+
name: 'config review',
|
|
295
|
+
summary: '审核本站统计代码(通过 / 驳回;双闸:REVIEW_TOKEN + --review-token;默认 dry-run)',
|
|
296
|
+
usage: 'wkgeo config review (--pass|--reject) [--reason <原因>] --review-token <审核令牌> [--confirm] [--site <站点ID>]',
|
|
297
|
+
args: [],
|
|
298
|
+
flags: {
|
|
299
|
+
pass: { type: 'boolean', desc: '通过(前台立刻开始输出这段统计代码)' },
|
|
300
|
+
reject: { type: 'boolean', desc: '驳回(前台继续不输出,原因回给客户)' },
|
|
301
|
+
reason: { type: 'string', desc: '驳回原因(最多 200 字;不写 = 「内容不符合要求」)' },
|
|
302
|
+
'review-token': {
|
|
303
|
+
type: 'string',
|
|
304
|
+
required: true,
|
|
305
|
+
desc: '审核令牌(= 函数环境变量 REVIEW_TOKEN;只走请求头 x-review-token,不进 body / 日志)',
|
|
306
|
+
},
|
|
307
|
+
...CONFIRM_FLAG,
|
|
308
|
+
...SITE_FLAG,
|
|
309
|
+
},
|
|
310
|
+
examples: [
|
|
311
|
+
'wkgeo config review --pass --review-token "$env:REVIEW_TOKEN" # dry-run',
|
|
312
|
+
'wkgeo config review --pass --review-token "$env:REVIEW_TOKEN" --confirm # 真通过',
|
|
313
|
+
'wkgeo config review --reject --reason "只允许统计代码" --review-token "$env:REVIEW_TOKEN" --confirm',
|
|
314
|
+
],
|
|
315
|
+
notes: [
|
|
316
|
+
'需要 `site:write`。**默认 dry-run**,加 `--confirm` 才真发。',
|
|
317
|
+
'**双闸**:① 函数环境变量 `REVIEW_TOKEN` 没配 ⇒ 一律 503「审核接口暂不可用」(这是故意的,免得没配好反而人人能审);② 请求头 `x-review-token` 与它不一致 ⇒ 403「没有审核权限」。',
|
|
318
|
+
'`--review-token` 只放请求头,**不写进 body**,也不进审计 detail(避免令牌落库/落日志)。',
|
|
319
|
+
'站点还没提交统计代码时回 400「这个站点还没提交统计代码」—— 先 `wkgeo config save --set \'{"statsCode":"…"}\'`。',
|
|
320
|
+
'通过 ⇒ `statsStatus=已通过` + `activeStatsCode` 同步为这段代码;驳回 ⇒ `statsStatus=已驳回` + 原因回给客户,前台继续不输出。',
|
|
321
|
+
],
|
|
322
|
+
async run(ctx) {
|
|
323
|
+
const { out } = ctx;
|
|
324
|
+
if (!ctx.flags.pass && !ctx.flags.reject) {
|
|
325
|
+
throw new UsageError('请给出 --pass 或 --reject(二选一)', {
|
|
326
|
+
hint: 'wkgeo config review --pass --review-token <令牌> | --reject --reason "…"',
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
if (ctx.flags.pass && ctx.flags.reject) {
|
|
330
|
+
throw new UsageError('--pass 与 --reject 不能同时给');
|
|
331
|
+
}
|
|
332
|
+
/* 参数名统一过 `camel()`(`cli/lib/args.mjs#parseFlags`),所以取的是 `reviewToken`。 */
|
|
333
|
+
const token = String(ctx.flags.reviewToken || '').trim();
|
|
334
|
+
if (!token) throw new UsageError('--review-token 不能是空串', { hint: '取值 = 函数环境变量 REVIEW_TOKEN 的原文' });
|
|
335
|
+
|
|
336
|
+
const passed = ctx.flags.pass === true;
|
|
337
|
+
const body = { result: passed ? '通过' : '驳回' };
|
|
338
|
+
const reason = String(ctx.flags.reason || '').trim();
|
|
339
|
+
if (!passed) body.reason = reason.slice(0, 200);
|
|
340
|
+
else if (reason) body.reason = reason.slice(0, 200);
|
|
341
|
+
|
|
342
|
+
const lines = [
|
|
343
|
+
`结果:${passed ? '通过' : '驳回'}`,
|
|
344
|
+
`令牌:${token.slice(0, 4)}…(只放请求头 x-review-token,共 ${token.length} 字)`,
|
|
345
|
+
];
|
|
346
|
+
if (!passed) lines.push(`原因:${body.reason || '内容不符合要求'}`);
|
|
347
|
+
if (!ctx.flags.confirm) {
|
|
348
|
+
return dryRun(ctx, ACTION.configReview, { ...body, site_id: siteIdOf(ctx) }, lines);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/* ⚠️ 令牌走头、不走 body:`consoleCall` 的 `opts.headers` 会原样透传,
|
|
352
|
+
服务端拿 `req.headers['x-review-token']` 与 `REVIEW_TOKEN` 逐字比对。 */
|
|
353
|
+
const res = (await ctx.consoleCall(ACTION.configReview, body, { headers: { 'x-review-token': token } })) || {};
|
|
354
|
+
const data = {
|
|
355
|
+
site_id: siteIdOf(ctx),
|
|
356
|
+
status: String(res.status || (passed ? '已通过' : '已驳回')),
|
|
357
|
+
passed,
|
|
358
|
+
reason: passed ? '' : String(body.reason || ''),
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
if (!out.json) {
|
|
362
|
+
if (data.passed) {
|
|
363
|
+
out.ok(`统计代码已通过(${data.status}):前台从现在开始输出这段代码`);
|
|
364
|
+
} else {
|
|
365
|
+
out.ok(`统计代码已驳回(${data.status})`);
|
|
366
|
+
out.info(` 原因:${data.reason || '内容不符合要求'}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
ctx.done(data);
|
|
370
|
+
return data;
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/* ══════════════════════════════ 会员 / 支付能力(capabilities) ══════════════════════════════ */
|
|
375
|
+
|
|
376
|
+
const REASON_TEXT = {
|
|
377
|
+
member_plugin_missing: '本站还没装过会员插件',
|
|
378
|
+
member_plugin_disabled: '会员插件已停用(重开:`wkgeo plugins toggle --key member --enable --confirm`)',
|
|
379
|
+
member_plugin_table_missing: '本站还没有 plugin 表(迁移没跑),按"不可用"处理',
|
|
380
|
+
pay_channel_none: '本站没有任何启用的支付通道(站点 / 站长 / 角色 / 平台四个归属都没有)',
|
|
381
|
+
pay_channel_table_missing: '支付通道表还没建好,按"不可用"处理',
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
export const configCapabilitiesCommand = {
|
|
385
|
+
name: 'config capabilities',
|
|
386
|
+
summary: '看本站能不能开会员 / 收款(后台这两档能不能选;只读)',
|
|
387
|
+
usage: 'wkgeo config capabilities [--site <站点ID>] [--json]',
|
|
388
|
+
args: [],
|
|
389
|
+
flags: { ...SITE_FLAG },
|
|
390
|
+
examples: ['wkgeo config capabilities', 'wkgeo config capabilities --json'],
|
|
391
|
+
notes: [
|
|
392
|
+
'需要 `site:read`(只读)。',
|
|
393
|
+
'只回答"后台能不能选会员 / 支付这两档",**不**决定读者能不能看(读者侧只看令牌,不看插件开关)。',
|
|
394
|
+
'`reasons` 里的码会原样给出来(`member_plugin_disabled` / `pay_channel_none` …),人类模式翻成人话。',
|
|
395
|
+
'支付通道按归属四路判定:站点 → 站长个人 → 站点角色 → 平台兜底,**只要有一条启用**就算能收钱。',
|
|
396
|
+
],
|
|
397
|
+
async run(ctx) {
|
|
398
|
+
const { out } = ctx;
|
|
399
|
+
const res = (await ctx.consoleCall(ACTION.cmsAccessCapabilities)) || {};
|
|
400
|
+
const raw = (res && res.reasons) || {};
|
|
401
|
+
const data = {
|
|
402
|
+
site_id: siteIdOf(ctx),
|
|
403
|
+
member: res.member === true,
|
|
404
|
+
pay: res.pay === true,
|
|
405
|
+
reasons: {
|
|
406
|
+
member: String(raw.member || ''),
|
|
407
|
+
pay: String(raw.pay || ''),
|
|
408
|
+
},
|
|
409
|
+
reason_text: {
|
|
410
|
+
member: REASON_TEXT[raw.member] || String(raw.member || ''),
|
|
411
|
+
pay: REASON_TEXT[raw.pay] || String(raw.pay || ''),
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
if (!out.json) {
|
|
416
|
+
out.head(`会员 / 支付能力(站点 ${siteText(ctx)})`);
|
|
417
|
+
out.line(` 会员:${data.member ? '可用' : '不可用'}${data.reasons.member ? `(${data.reason_text.member})` : ''}`);
|
|
418
|
+
out.line(` 支付:${data.pay ? '可用' : '不可用'}${data.reasons.pay ? `(${data.reason_text.pay})` : ''}`);
|
|
419
|
+
if (!data.member && !data.pay) {
|
|
420
|
+
out.info('两档都不可用:先 `wkgeo plugins list` 看会员插件状态,支付通道要在管理端配。');
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
ctx.done(data);
|
|
424
|
+
return data;
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
/** 注册表(顺序 = 帮助里的顺序) */
|
|
429
|
+
export const CONFIG_CONSOLE_COMMANDS = [
|
|
430
|
+
configGetCommand,
|
|
431
|
+
configSaveCommand,
|
|
432
|
+
configReviewCommand,
|
|
433
|
+
configCapabilitiesCommand,
|
|
434
|
+
];
|