@wkgeo/cli 1.1.4 → 2.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/CHANGELOG.md +14 -1
- package/README.md +1 -1
- package/SKILL.md +2 -2
- package/lib/api.mjs +22 -27
- package/lib/cms.mjs +0 -2
- package/lib/commands/auth.mjs +10 -18
- package/lib/commands/cms.mjs +66 -18
- package/lib/commands/index.mjs +9 -75
- package/lib/commands/member.mjs +936 -932
- package/lib/commands/orders.mjs +27 -1
- package/lib/commands/site.mjs +388 -435
- package/lib/commands/siteops.mjs +438 -1013
- package/lib/commands/sites.mjs +0 -1
- package/lib/commands/template.mjs +11 -1
- package/lib/errors.mjs +31 -0
- package/lib/site-create.mjs +1 -2
- package/lib/template-publish.mjs +36 -78
- package/lib/templates-sync.mjs +51 -23
- package/package.json +1 -1
- package/lib/commands/dnscred.mjs +0 -428
- package/lib/commands/domainops.mjs +0 -546
- package/lib/commands/domainorder.mjs +0 -439
package/lib/commands/sites.mjs
CHANGED
|
@@ -732,7 +732,6 @@ export const sitesGetCommand = {
|
|
|
732
732
|
if (detail.cert_status || detail.cert_not_after) {
|
|
733
733
|
out.line(` 证书:${detail.cert_status || '-'}${detail.cert_not_after ? `(到期 ${formatTime(detail.cert_not_after)})` : ''}`);
|
|
734
734
|
}
|
|
735
|
-
if (detail.pool_id) out.line(` 计费池:${detail.pool_id}`);
|
|
736
735
|
if (detail.provision_attempts) out.line(` 开通尝试:${detail.provision_attempts} 次`);
|
|
737
736
|
out.line(` 创建时间:${formatTime(site.created_at)}${detail.updated_at ? ` · 更新时间:${formatTime(detail.updated_at)}` : ''}`);
|
|
738
737
|
if (detail.last_error) out.warn(`最近一次错误:${detail.last_error}${detail.last_error_at ? `(${formatTime(detail.last_error_at)})` : ''}`);
|
|
@@ -1083,7 +1083,7 @@ export const templatePublishCommand = {
|
|
|
1083
1083
|
'wkgeo template publish --dir ./tpl/demo --key t144-probe --confirm # 真写(测试 key)',
|
|
1084
1084
|
],
|
|
1085
1085
|
notes: [
|
|
1086
|
-
'凭据只从 env / 本机 `oss.env`
|
|
1086
|
+
'凭据只从 env / 本机 `oss.env` 读,**永不打印**(只报"已配置 + 来源路径 + 末 4 位");数据库读写走真库 RDS 通道(腾讯 CloudBase 旧网关已退役)。',
|
|
1087
1087
|
'真写前先把**市场行 + OSS 前缀清单**存档到 `.tmp-build/t144/`(`--archive` 可改),写完再存一份,前后可比。',
|
|
1088
1088
|
'OSS 走手写 V1 签名(CLI 零依赖,不引 ali-oss);`prefix`/`max-keys` 这类普通查询参数**不进签名**,进了会 SignatureDoesNotMatch。',
|
|
1089
1089
|
'顺序:上传 → prune(新替旧)→ upsert 市场行(`version` 自增、`sha256` = 发布清单摘要)→ 回读(行 / files 数 / OSS HEAD / 对象直链 / 预览短链)。',
|
|
@@ -1325,6 +1325,13 @@ export const templatesPullCommand = {
|
|
|
1325
1325
|
out.ok(
|
|
1326
1326
|
`已拉取 ${r.fileCount} 个文件(${fmtBytes(r.bytes)}${r.binaryCount ? `,其中二进制 ${r.binaryCount}` : ''})→ ${r.dir}`,
|
|
1327
1327
|
);
|
|
1328
|
+
if (r.skipped && r.skipped.length) {
|
|
1329
|
+
for (const one of r.skipped) {
|
|
1330
|
+
out.warn(
|
|
1331
|
+
`跳过超限文件 ${one.path}(${one.measured}${one.reason === 'binary-bytes' ? ' 字节' : ' 字符'}):大体积演示资产不进站点模板副本,其余文件照常同步`,
|
|
1332
|
+
);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1328
1335
|
out.info(`模板:${r.template.name || '-'}(key ${r.template.key || '-'} · id ${r.template.id || '-'})`);
|
|
1329
1336
|
out.info(`manifest:${r.manifestPath}(contentHash ${r.contentHash.slice(0, 12)}…)`);
|
|
1330
1337
|
out.table(
|
|
@@ -1344,6 +1351,8 @@ export const templatesPullCommand = {
|
|
|
1344
1351
|
binary_count: r.binaryCount,
|
|
1345
1352
|
bytes: r.bytes,
|
|
1346
1353
|
files: r.files,
|
|
1354
|
+
skipped: r.skipped || [],
|
|
1355
|
+
warnings: r.warnings || [],
|
|
1347
1356
|
next: 'wkgeo templates push --dir <目录> --dry-run',
|
|
1348
1357
|
});
|
|
1349
1358
|
},
|
|
@@ -1403,6 +1412,7 @@ export const templatesPushCommand = {
|
|
|
1403
1412
|
template: r.template,
|
|
1404
1413
|
plan: r.plan,
|
|
1405
1414
|
warnings: r.warnings,
|
|
1415
|
+
skipped: r.skipped || [],
|
|
1406
1416
|
applied: r.applied === true,
|
|
1407
1417
|
written: r.written,
|
|
1408
1418
|
content_hash: r.contentHash || null,
|
package/lib/errors.mjs
CHANGED
|
@@ -264,6 +264,37 @@ export function classifyResponse({ httpStatus = 200, body = null, action = '', r
|
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
if (codeNum === 404) return bad('not_found', message || '资源不存在', { code: 404 });
|
|
267
|
+
/**
|
|
268
|
+
* ★ 2026-11-17(task-627):**409 = 状态冲突**(下单打进来才有,之前落到 `unknown`)。
|
|
269
|
+
*
|
|
270
|
+
* 两种要分开:
|
|
271
|
+
* · `idempotency_mismatch` —— 同一幂等键的参数与已建订单不一致(**这一单其实已经建好了**)。
|
|
272
|
+
* 服务端原文带实现词 `idempotency_key`,**不能照抄给用户**,翻成"别重复下单 + 怎么继续付";
|
|
273
|
+
* · 其余(`ICP_ASSIST_OPEN_ORDER_EXISTS` 还有未完成服务单 / `VIP_ALREADY_ACTIVE` 仍在有效期)
|
|
274
|
+
* 后端文案本身就是人话 ⇒ 原样透出,只补一句下一步。
|
|
275
|
+
*/
|
|
276
|
+
if (codeNum === 409) {
|
|
277
|
+
const biz = String(
|
|
278
|
+
(body && (body.error_code || (body.data && body.data.code))) || '',
|
|
279
|
+
);
|
|
280
|
+
if (biz === 'idempotency_mismatch' || /idempotency/i.test(message)) {
|
|
281
|
+
return bad(
|
|
282
|
+
'conflict',
|
|
283
|
+
'这一单已经创建,请不要重复下单:订单 30 分钟内未支付会自动关闭(优惠券随之释放),' +
|
|
284
|
+
'关闭后再重新下单即可;也可以在网页「我的订单」里继续支付。',
|
|
285
|
+
{
|
|
286
|
+
code: 409,
|
|
287
|
+
hint:
|
|
288
|
+
`先 \`${cmdName} orders list\` 看这一单在不在;待支付就去网页收银台付,` +
|
|
289
|
+
`或 \`${cmdName} orders pay <订单号>\` 查一次状态。**不要**换个参数再下一单(会锁券、留多张待支付单)。`,
|
|
290
|
+
},
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
return bad('conflict', message || '该操作与当前状态冲突,请刷新后重试', {
|
|
294
|
+
code: 409,
|
|
295
|
+
hint: '按提示处理后再试;不要靠重复下单绕过(会锁券 / 留下多张待支付单)。',
|
|
296
|
+
});
|
|
297
|
+
}
|
|
267
298
|
if (codeNum === 400) {
|
|
268
299
|
// 内容类自持动作没带站点(`content-core.js` 的「缺少 siteId:CLI 内容动作必须指定站点…」)
|
|
269
300
|
if (/缺少 siteId|指定站点/.test(message)) {
|
package/lib/site-create.mjs
CHANGED
|
@@ -112,7 +112,6 @@ function siteBrief(row) {
|
|
|
112
112
|
name: one.name || '',
|
|
113
113
|
status: one.status || null,
|
|
114
114
|
owner_user_id: one.owner_user_id || one.owner_id || null,
|
|
115
|
-
pool_id: one.pool_id || null,
|
|
116
115
|
prefix_host: prefixHost || null,
|
|
117
116
|
prefix_url: one.prefix_url || (prefixHost ? `https://${prefixHost}/` : null),
|
|
118
117
|
};
|
|
@@ -419,7 +418,7 @@ export async function runSiteCreate(ctx, flags) {
|
|
|
419
418
|
hint: '用 `wkgeo sites list` 确认是否已经建出来了;刚建出来但没有 id 属服务端异常。',
|
|
420
419
|
});
|
|
421
420
|
}
|
|
422
|
-
record('create_site', { site_id: site.id, prefix_host: site.prefix_host,
|
|
421
|
+
record('create_site', { site_id: site.id, prefix_host: site.prefix_host, region });
|
|
423
422
|
if (!json) {
|
|
424
423
|
out.ok(`站点已创建:${site.name || name}`);
|
|
425
424
|
say(`站点 ID:${site.id}`);
|
package/lib/template-publish.mjs
CHANGED
|
@@ -112,22 +112,8 @@ export function resolveOssCreds({ cwd = process.cwd(), env = process.env } = {})
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
*
|
|
117
|
-
*/
|
|
118
|
-
export function resolveDbCreds({ cwd = process.cwd(), env = process.env } = {}) {
|
|
119
|
-
const explicit = env.WKGEO_CLOUDBASE_ENV;
|
|
120
|
-
const root = explicit && fs.existsSync(explicit) ? explicit : findUp(cwd, path.join('tencent', 'cloudbase', '.env'));
|
|
121
|
-
const file = explicit && fs.existsSync(explicit) ? path.resolve(explicit) : root ? path.join(root, 'tencent', 'cloudbase', '.env') : null;
|
|
122
|
-
const vars = file ? parseEnvFile(file) : {};
|
|
123
|
-
const pick = (k) => env[k] || vars[k] || '';
|
|
124
|
-
return {
|
|
125
|
-
envId: pick('CLOUDBASE_ENV_ID'),
|
|
126
|
-
apiKey: pick('CLOUDBASE_APIKEY'),
|
|
127
|
-
source: file,
|
|
128
|
-
gateway: pick('CLOUDBASE_GATEWAY'),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
115
|
+
/* 数据库凭据:2026-11-18 task-973 —— 腾讯 CloudBase `exec-pgsql` + `CLOUDBASE_APIKEY` 已退役,
|
|
116
|
+
* 不再解析 / 不再要求;写市场行走真库 RDS 通道(见下面 `dbExec`)。 */
|
|
131
117
|
|
|
132
118
|
/** 只报"有没有配",不报值 */
|
|
133
119
|
export function credsSummary(creds) {
|
|
@@ -139,12 +125,6 @@ export function credsSummary(creds) {
|
|
|
139
125
|
source: creds.oss.source,
|
|
140
126
|
access_key_id_tail: creds.oss.accessKeyId ? creds.oss.accessKeyId.slice(-4) : '',
|
|
141
127
|
},
|
|
142
|
-
db: {
|
|
143
|
-
configured: !!(creds.db.envId && creds.db.apiKey),
|
|
144
|
-
env_id: creds.db.envId,
|
|
145
|
-
source: creds.db.source,
|
|
146
|
-
api_key_tail: creds.db.apiKey ? creds.db.apiKey.slice(-4) : '',
|
|
147
|
-
},
|
|
148
128
|
};
|
|
149
129
|
}
|
|
150
130
|
|
|
@@ -241,65 +221,56 @@ export function ossPublicUrl({ creds, objectKey }) {
|
|
|
241
221
|
return `https://${creds.bucket}.${creds.region}.aliyuncs.com/${objectKey}`;
|
|
242
222
|
}
|
|
243
223
|
|
|
244
|
-
/* ------------------------------------------------------------------
|
|
224
|
+
/* ------------------------------------------------------------------ 数据库(真库 RDS) */
|
|
225
|
+
|
|
226
|
+
/** 懒加载真库通道:`deploy-web/_lib/pg-rds.mjs` 不在 npm 包里 ⇒ 只在真正要读写市场行时才解析。 */
|
|
227
|
+
let rdsModPromise = null;
|
|
228
|
+
function loadRds() {
|
|
229
|
+
if (!rdsModPromise) {
|
|
230
|
+
rdsModPromise = import(new URL('../../deploy-web/_lib/pg-rds.mjs', import.meta.url).href).catch((e) => {
|
|
231
|
+
rdsModPromise = null;
|
|
232
|
+
throw new CliError('数据库通道不可用(真库 RDS 探针仅仓库内可用)', {
|
|
233
|
+
kind: 'db',
|
|
234
|
+
code: 'EDB',
|
|
235
|
+
hint: String((e && e.message) || e).slice(0, 300),
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return rdsModPromise;
|
|
240
|
+
}
|
|
245
241
|
|
|
246
242
|
/**
|
|
247
|
-
* 执行一条 PG
|
|
248
|
-
*
|
|
249
|
-
* body `{sql, parameters, role:'cloudbase_postgres'}`,响应取 `data ?? rows ?? 自身`。
|
|
243
|
+
* 执行一条 PG 语句(2026-11-18 task-973:腾讯 CloudBase `exec-pgsql` 网关已退役,改走真库 RDS)。
|
|
244
|
+
* `rdsExec` 返回行对象数组(与旧网关形状一致);只读语句不给 `write`,写语句显式 `write:true`。
|
|
250
245
|
*/
|
|
251
|
-
export async function dbExec({
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${creds.apiKey}` },
|
|
256
|
-
body: JSON.stringify({ sql, parameters, role: 'cloudbase_postgres' }),
|
|
257
|
-
});
|
|
258
|
-
const text = await res.text();
|
|
259
|
-
let json = null;
|
|
260
|
-
try {
|
|
261
|
-
json = JSON.parse(text);
|
|
262
|
-
} catch {
|
|
263
|
-
json = null;
|
|
264
|
-
}
|
|
265
|
-
if (!res.ok) {
|
|
266
|
-
throw new CliError(`数据库请求失败 ${res.status}`, {
|
|
267
|
-
kind: 'db',
|
|
268
|
-
code: 'EDB',
|
|
269
|
-
hint: (text || '').slice(0, 300),
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
const data = json && (json.data ?? json.rows ?? json.result ?? json);
|
|
273
|
-
const rows = Array.isArray(data) ? data : data && Array.isArray(data.rows) ? data.rows : [];
|
|
274
|
-
return { rows, raw: json };
|
|
246
|
+
export async function dbExec({ sql, parameters = [], write = false } = {}) {
|
|
247
|
+
const mod = await loadRds();
|
|
248
|
+
const rows = await mod.rdsExec(sql, parameters, write ? { write: true } : undefined);
|
|
249
|
+
return { rows, raw: rows };
|
|
275
250
|
}
|
|
276
251
|
|
|
277
252
|
/** 读一行市场模板(不存在返回 null) */
|
|
278
|
-
export async function readMarketRow({
|
|
253
|
+
export async function readMarketRow({ key } = {}) {
|
|
279
254
|
const { rows } = await dbExec({
|
|
280
|
-
creds,
|
|
281
255
|
sql: `select id::text as id, key, name, sort, price_cents, coalesce(version, 0) as version, sha256, jsonb_array_length(files) as files_count, enabled, updated_at::text as updated_at from ${MARKET_TABLE} where key = $1 limit 1`,
|
|
282
256
|
parameters: [key],
|
|
283
|
-
fetchImpl,
|
|
284
257
|
});
|
|
285
258
|
return rows[0] || null;
|
|
286
259
|
}
|
|
287
260
|
|
|
288
261
|
/** 删一行市场模板(清理测试用;调用方负责确认 key) */
|
|
289
|
-
export async function deleteMarketRow({
|
|
262
|
+
export async function deleteMarketRow({ key } = {}) {
|
|
290
263
|
const { rows } = await dbExec({
|
|
291
|
-
creds,
|
|
292
264
|
sql: `delete from ${MARKET_TABLE} where key = $1 returning id::text as id, key`,
|
|
293
265
|
parameters: [key],
|
|
294
|
-
|
|
266
|
+
write: true,
|
|
295
267
|
});
|
|
296
268
|
return rows[0] || null;
|
|
297
269
|
}
|
|
298
270
|
|
|
299
271
|
/** upsert:`files` 就是这个 key 的完整清单(覆盖写),`version` 自增 */
|
|
300
|
-
export async function upsertMarketRow({
|
|
272
|
+
export async function upsertMarketRow({ row } = {}) {
|
|
301
273
|
const { rows } = await dbExec({
|
|
302
|
-
creds,
|
|
303
274
|
sql: `insert into ${MARKET_TABLE}
|
|
304
275
|
(key, name, summary, files, sort, enabled, price_cents, demo, industries, visible_scope, requires_plugins, version, sha256)
|
|
305
276
|
values ($1, $2, $3, $4::jsonb, $5, true, $6, $7::jsonb, $8::jsonb, 'all', '[]'::jsonb, 1, $9)
|
|
@@ -327,7 +298,7 @@ returning id::text as id, key, name, sort, price_cents, coalesce(version, 0) as
|
|
|
327
298
|
JSON.stringify(row.industries || []),
|
|
328
299
|
row.sha256,
|
|
329
300
|
],
|
|
330
|
-
|
|
301
|
+
write: true,
|
|
331
302
|
});
|
|
332
303
|
return rows[0] || null;
|
|
333
304
|
}
|
|
@@ -498,7 +469,7 @@ export async function publishTemplate({
|
|
|
498
469
|
onStep = () => {},
|
|
499
470
|
} = {}) {
|
|
500
471
|
const collected = await collectTemplate({ dir, key });
|
|
501
|
-
const resolved = creds || { oss: resolveOssCreds({ cwd })
|
|
472
|
+
const resolved = creds || { oss: resolveOssCreds({ cwd }) };
|
|
502
473
|
if (!resolved.oss.accessKeyId || !resolved.oss.accessKeySecret) {
|
|
503
474
|
throw new CliError('OSS 凭据缺失(OSS_ACCESS_KEY_ID / OSS_ACCESS_KEY_SECRET)', {
|
|
504
475
|
kind: 'usage',
|
|
@@ -507,21 +478,12 @@ export async function publishTemplate({
|
|
|
507
478
|
hint: '写到 oss.env(仓库根)或设进环境变量;本命令不打印任何密钥',
|
|
508
479
|
});
|
|
509
480
|
}
|
|
510
|
-
if (!resolved.db.envId || !resolved.db.apiKey) {
|
|
511
|
-
throw new CliError('数据库凭据缺失(CLOUDBASE_ENV_ID / CLOUDBASE_APIKEY)', {
|
|
512
|
-
kind: 'usage',
|
|
513
|
-
code: 'ENOCREDS',
|
|
514
|
-
exitCode: 2,
|
|
515
|
-
hint: '写到 tencent/cloudbase/.env 或设进环境变量',
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
481
|
const ossCreds = {
|
|
519
482
|
accessKeyId: resolved.oss.accessKeyId,
|
|
520
483
|
accessKeySecret: resolved.oss.accessKeySecret,
|
|
521
484
|
bucket: resolved.oss.bucket,
|
|
522
485
|
region: resolved.oss.region,
|
|
523
486
|
};
|
|
524
|
-
const dbCreds = { envId: resolved.db.envId, apiKey: resolved.db.apiKey, gateway: resolved.db.gateway };
|
|
525
487
|
const paths = archivePaths(archiveDir, collected.key);
|
|
526
488
|
const steps = [];
|
|
527
489
|
const step = (name, status, detail = null) => {
|
|
@@ -533,7 +495,7 @@ export async function publishTemplate({
|
|
|
533
495
|
|
|
534
496
|
// ① 读目录 + 计划(含现有市场行 / OSS 清单 = "前"存档)
|
|
535
497
|
step('collect', 'ok', { files: collected.files.length, bytes: collected.totalBytes, problems: collected.problems.length });
|
|
536
|
-
const marketBefore = await readMarketRow({
|
|
498
|
+
const marketBefore = await readMarketRow({ key: collected.key });
|
|
537
499
|
const ossBefore = await ossList({ creds: ossCreds, prefix: `templates/${collected.key}/`, fetchImpl });
|
|
538
500
|
step('archive-before', 'ok', { market: !!marketBefore, oss_objects: ossBefore.keys.length });
|
|
539
501
|
const plan = buildPlan({
|
|
@@ -596,7 +558,6 @@ export async function publishTemplate({
|
|
|
596
558
|
|
|
597
559
|
// ④ upsert 市场行(files 顺序 = template.json.files 顺序)
|
|
598
560
|
const row = await upsertMarketRow({
|
|
599
|
-
creds: dbCreds,
|
|
600
561
|
row: {
|
|
601
562
|
key: collected.key,
|
|
602
563
|
name: collected.name,
|
|
@@ -608,12 +569,11 @@ export async function publishTemplate({
|
|
|
608
569
|
industries: collected.industries,
|
|
609
570
|
sha256: collected.digest,
|
|
610
571
|
},
|
|
611
|
-
fetchImpl,
|
|
612
572
|
});
|
|
613
573
|
step('market-upsert', 'ok', row);
|
|
614
574
|
|
|
615
575
|
// ⑤ 回读校验
|
|
616
|
-
const marketAfter = await readMarketRow({
|
|
576
|
+
const marketAfter = await readMarketRow({ key: collected.key });
|
|
617
577
|
const ossAfter = await ossList({ creds: ossCreds, prefix: `templates/${collected.key}/`, fetchImpl });
|
|
618
578
|
const heads = [];
|
|
619
579
|
for (const up of plan.uploads) {
|
|
@@ -699,18 +659,17 @@ export async function cleanupTemplate({ key, creds = null, cwd = process.cwd(),
|
|
|
699
659
|
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(String(key || ''))) {
|
|
700
660
|
throw new CliError(`非法 key:${key}`, { kind: 'usage', code: 'EBADKEY', exitCode: 2 });
|
|
701
661
|
}
|
|
702
|
-
const resolved = creds || { oss: resolveOssCreds({ cwd })
|
|
662
|
+
const resolved = creds || { oss: resolveOssCreds({ cwd }) };
|
|
703
663
|
const ossCreds = resolved.oss;
|
|
704
|
-
const dbCreds = resolved.db;
|
|
705
664
|
const before = await ossList({ creds: ossCreds, prefix: `templates/${key}/`, fetchImpl });
|
|
706
665
|
const removed = [];
|
|
707
666
|
for (const obj of before.keys) {
|
|
708
667
|
const r = await ossDelete({ creds: ossCreds, objectKey: obj.key, fetchImpl });
|
|
709
668
|
if (r.ok) removed.push(obj.key);
|
|
710
669
|
}
|
|
711
|
-
const row = await deleteMarketRow({
|
|
670
|
+
const row = await deleteMarketRow({ key });
|
|
712
671
|
const after = await ossList({ creds: ossCreds, prefix: `templates/${key}/`, fetchImpl });
|
|
713
|
-
const rowAfter = await readMarketRow({
|
|
672
|
+
const rowAfter = await readMarketRow({ key });
|
|
714
673
|
return { key, removed, row, oss_before: before.keys.length, oss_after: after.keys.length, market_before: !!row, market_after: !!rowAfter };
|
|
715
674
|
}
|
|
716
675
|
|
|
@@ -720,7 +679,6 @@ export default {
|
|
|
720
679
|
buildPlan,
|
|
721
680
|
cleanupTemplate,
|
|
722
681
|
resolveOssCreds,
|
|
723
|
-
resolveDbCreds,
|
|
724
682
|
credsSummary,
|
|
725
683
|
ossPut,
|
|
726
684
|
ossHead,
|
package/lib/templates-sync.mjs
CHANGED
|
@@ -42,6 +42,35 @@ export const MANIFEST_VERSION = 1;
|
|
|
42
42
|
/** 服务端 `templateMaxBytes = 400 * 1024`(**按字符**算);二进制按字节同口径兜住 */
|
|
43
43
|
export const MAX_FILE_CHARS = 400 * 1024;
|
|
44
44
|
export const MAX_FILE_BYTES = 400 * 1024;
|
|
45
|
+
/**
|
|
46
|
+
* 超限文件 = **不该进站点模板副本的大体积演示资产**(three.min.js / 大图等)。
|
|
47
|
+
*
|
|
48
|
+
* ⚠️ 2026-11-14 task-107:以前拉 / 推遇到超限文件**整包直接失败**,结果是
|
|
49
|
+
* 「库里本来就有的大文件把整站的拉/推全堵死」——base 站 `assets/vendor/three-0.147.0/three.min.js`
|
|
50
|
+
* (607784 字符)与闵航站 `home.jpg`(538619 字节)就是这样堵住的,其余几十个小文件一个都推不上去。
|
|
51
|
+
* 现在改成:**跳过这一个文件 + 告警**,其余文件照常拉 / 推;上限本身**不调大**(避免整站模板过大)。
|
|
52
|
+
*/
|
|
53
|
+
export function oversizeOf(filePath, buf) {
|
|
54
|
+
const rel = String(filePath || '');
|
|
55
|
+
const text = Buffer.isBuffer(buf) ? buf : Buffer.from(String(buf === undefined || buf === null ? '' : buf), 'utf8');
|
|
56
|
+
if (isBinaryPath(rel)) {
|
|
57
|
+
if (text.length > MAX_FILE_BYTES) return { reason: 'binary-bytes', measured: text.length, limit: MAX_FILE_BYTES };
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const chars = text.toString('utf8').length;
|
|
61
|
+
if (chars > MAX_FILE_CHARS) return { reason: 'text-chars', measured: chars, limit: MAX_FILE_CHARS };
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 超限告警文案(拉 / 推共用;不打印正文) */
|
|
66
|
+
export function oversizeWarning(rel, one) {
|
|
67
|
+
const unit = one.reason === 'binary-bytes' ? '字节' : '字符';
|
|
68
|
+
return (
|
|
69
|
+
`跳过超限文件 ${rel}(${one.measured} ${unit},上限 ${one.limit}):大体积演示资产不进站点模板副本,` +
|
|
70
|
+
'其余文件照常同步;要放它请走素材库 / 母版引用'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
45
74
|
/** 路径上限:对齐 `template-files.js` 的 `TEMPLATE_FILE_MAX_PATH_CHARS` / 每段 64 字符 */
|
|
46
75
|
export const MAX_PATH_CHARS = 200;
|
|
47
76
|
export const MAX_SEGMENT_CHARS = 64;
|
|
@@ -285,24 +314,17 @@ export async function pullTemplate({
|
|
|
285
314
|
|
|
286
315
|
const at = now().toISOString();
|
|
287
316
|
const files = [];
|
|
317
|
+
const skipped = [];
|
|
288
318
|
let binaryCount = 0;
|
|
289
319
|
let totalBytes = 0;
|
|
290
320
|
for (const raw of remoteFiles) {
|
|
291
321
|
const rel = assertSafePath(raw.path);
|
|
292
322
|
const buf = entryBytes({ ...raw, path: rel });
|
|
293
323
|
const binary = isBinaryPath(rel);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
hint: '把这张图/字体压缩后再放回来;模板里的大文件建议走素材库(assets upload)',
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
} else if (buf.toString('utf8').length > MAX_FILE_CHARS) {
|
|
302
|
-
throw new CliError(`第 ${files.length + 1} 个模板文件太长:${rel}(${buf.toString('utf8').length} 字符,上限 ${MAX_FILE_CHARS})`, {
|
|
303
|
-
kind: 'file_too_large',
|
|
304
|
-
hint: '拆成多个 partials 文件(服务端 templateFileSave 也按 40 万字符挡)',
|
|
305
|
-
});
|
|
324
|
+
const oversize = oversizeOf(rel, buf);
|
|
325
|
+
if (oversize) {
|
|
326
|
+
skipped.push({ path: rel, bytes: buf.length, measured: oversize.measured, reason: oversize.reason });
|
|
327
|
+
continue;
|
|
306
328
|
}
|
|
307
329
|
const target = resolveInside(root, rel);
|
|
308
330
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
@@ -341,6 +363,8 @@ export async function pullTemplate({
|
|
|
341
363
|
bytes: totalBytes,
|
|
342
364
|
contentHash: manifest.contentHash,
|
|
343
365
|
files,
|
|
366
|
+
skipped,
|
|
367
|
+
warnings: skipped.map((one) => oversizeWarning(one.path, { reason: one.reason, measured: one.measured, limit: one.reason === 'binary-bytes' ? MAX_FILE_BYTES : MAX_FILE_CHARS })),
|
|
344
368
|
};
|
|
345
369
|
}
|
|
346
370
|
|
|
@@ -401,20 +425,17 @@ function scanLocal(dir) {
|
|
|
401
425
|
};
|
|
402
426
|
walk(root);
|
|
403
427
|
const files = [];
|
|
428
|
+
const skipped = [];
|
|
404
429
|
for (const abs of absPaths) {
|
|
405
430
|
const rel = path.relative(root, abs).split(path.sep).join('/');
|
|
406
431
|
if (rel === MANIFEST_FILE) continue;
|
|
407
432
|
const safe = assertSafePath(rel);
|
|
408
433
|
const buf = fs.readFileSync(abs);
|
|
409
434
|
const binary = isBinaryPath(safe);
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
} else if (buf.toString('utf8').length > MAX_FILE_CHARS) {
|
|
415
|
-
throw new CliError(`本地模板文件太长:${safe}(${buf.toString('utf8').length} 字符,上限 ${MAX_FILE_CHARS})`, {
|
|
416
|
-
kind: 'file_too_large',
|
|
417
|
-
});
|
|
435
|
+
const oversize = oversizeOf(safe, buf);
|
|
436
|
+
if (oversize) {
|
|
437
|
+
skipped.push({ path: safe, bytes: buf.length, measured: oversize.measured, reason: oversize.reason });
|
|
438
|
+
continue;
|
|
418
439
|
}
|
|
419
440
|
files.push({
|
|
420
441
|
path: safe,
|
|
@@ -426,7 +447,7 @@ function scanLocal(dir) {
|
|
|
426
447
|
text: binary ? null : buf.toString('utf8'),
|
|
427
448
|
});
|
|
428
449
|
}
|
|
429
|
-
return files.sort((a, b) => a.path.localeCompare(b.path));
|
|
450
|
+
return { files: files.sort((a, b) => a.path.localeCompare(b.path)), skipped };
|
|
430
451
|
}
|
|
431
452
|
|
|
432
453
|
/** 远端当前文件(按 manifest 里那套模板取;不传 id = 当前启用那套) */
|
|
@@ -482,7 +503,9 @@ export async function planPush({ dir = '', api = null, prune = false, cwd = proc
|
|
|
482
503
|
|
|
483
504
|
const { manifest, file: manifestPath } = readManifest(root);
|
|
484
505
|
assertSameSite(manifest, api);
|
|
485
|
-
const
|
|
506
|
+
const scanned = scanLocal(root);
|
|
507
|
+
const local = scanned.files;
|
|
508
|
+
const skipped = scanned.skipped;
|
|
486
509
|
const remote = await fetchRemote(api, manifest);
|
|
487
510
|
const localMap = new Map(local.map((f) => [f.path, f]));
|
|
488
511
|
const remoteMap = new Map(remote.files.map((f) => [f.path, f]));
|
|
@@ -507,8 +530,12 @@ export async function planPush({ dir = '', api = null, prune = false, cwd = proc
|
|
|
507
530
|
manifest,
|
|
508
531
|
plan,
|
|
509
532
|
local,
|
|
533
|
+
skipped,
|
|
510
534
|
remote: remote.files,
|
|
511
|
-
warnings:
|
|
535
|
+
warnings: [
|
|
536
|
+
...remote.warnings,
|
|
537
|
+
...skipped.map((one) => oversizeWarning(one.path, { reason: one.reason, measured: one.measured, limit: one.reason === 'binary-bytes' ? MAX_FILE_BYTES : MAX_FILE_CHARS })),
|
|
538
|
+
],
|
|
512
539
|
};
|
|
513
540
|
}
|
|
514
541
|
|
|
@@ -541,6 +568,7 @@ export async function pushTemplate({
|
|
|
541
568
|
template: { id: planned.manifest.templateId || null, key: planned.manifest.key || null },
|
|
542
569
|
plan,
|
|
543
570
|
warnings: planned.warnings.slice(),
|
|
571
|
+
skipped: planned.skipped || [],
|
|
544
572
|
written: [],
|
|
545
573
|
failed: [],
|
|
546
574
|
};
|