@yizhuan-cli/cli 0.1.8 → 0.1.10-beta.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/README.md CHANGED
@@ -7,13 +7,13 @@
7
7
  需要 Node.js 22 或更高版本。
8
8
 
9
9
  ```bash
10
- npm install -g @yizhuan-cli/cli@0.1.8
10
+ npm install -g @yizhuan-cli/cli@0.1.10-beta.0
11
11
  ```
12
12
 
13
13
  如果发布在私有 npm registry,请加上对应 registry:
14
14
 
15
15
  ```bash
16
- npm install -g @yizhuan-cli/cli@0.1.8 --registry=https://your-private-registry.example
16
+ npm install -g @yizhuan-cli/cli@0.1.10-beta.0 --registry=https://your-private-registry.example
17
17
  ```
18
18
 
19
19
  ## 配置
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yizhuan-cli/cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.10-beta.0",
4
4
  "description": "易撰命令行工具,用于通过 API Key 查询易撰真实数据。",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "name": "yizhuan-cli",
4
- "version": "0.1.8",
5
- "compatibleCliVersion": "0.1.8",
6
- "source": "npm:@yizhuan-cli/cli@0.1.8",
4
+ "version": "0.1.10-beta.0",
5
+ "compatibleCliVersion": "0.1.10-beta.0",
6
+ "source": "npm:@yizhuan-cli/cli@0.1.10-beta.0",
7
7
  "digestAlgorithm": "sha256",
8
8
  "files": [
9
9
  {
package/src/config.js CHANGED
@@ -158,7 +158,7 @@ Options:
158
158
  --api-base-url <url> API 地址,默认 ${DEFAULT_API_BASE_URL}
159
159
  --api-key-stdin 从标准输入读取 API Key(推荐用于自动化)
160
160
  --api-key <key> 从参数读取 API Key(可能保留在 Shell 历史中)
161
- --force 覆盖已有配置
161
+ --force 覆盖已有配置;未指定地址时重置为正式 API 地址
162
162
  --help 显示本帮助
163
163
 
164
164
  未持有 API Key:${CLI_TOOLS_URL}`)
@@ -187,9 +187,7 @@ export async function runConfigInit(
187
187
  }
188
188
 
189
189
  const apiKey = validateApiKey(await readApiKey(args))
190
- const apiBaseUrl = validateApiBaseUrl(
191
- args.apiBaseUrl || existingConfig?.apiBaseUrl || DEFAULT_API_BASE_URL
192
- )
190
+ const apiBaseUrl = validateApiBaseUrl(args.apiBaseUrl || DEFAULT_API_BASE_URL)
193
191
  const config = {
194
192
  ...(existingConfig || {}),
195
193
  apiBaseUrl,
package/src/doctor.js CHANGED
@@ -52,9 +52,9 @@ export function inspectLocalEnvironment(
52
52
  ? check('pass', 'node', `Node.js ${nodeVersion} 满足 >=${minimumNode}`)
53
53
  : check('fail', 'node', `Node.js ${nodeVersion} 不满足 ${packageJson.engines?.node || '版本要求'}`, `安装 Node.js ${minimumNode || 22} 或更高版本。`))
54
54
 
55
- checks.push(packageJson.version === '0.1.8'
55
+ checks.push(packageJson.version === '0.1.10-beta.0'
56
56
  ? check('pass', 'cli_version', `CLI ${packageJson.version}`)
57
- : check('fail', 'cli_version', `CLI 版本为 ${packageJson.version},预期 0.1.8`, '安装 @yizhuan-cli/cli@0.1.8。'))
57
+ : check('fail', 'cli_version', `CLI 版本为 ${packageJson.version},预期 0.1.10-beta.0`, '安装 @yizhuan-cli/cli@0.1.10-beta.0。'))
58
58
 
59
59
  if (!exists(configPath)) {
60
60
  checks.push(check('fail', 'config', `配置不存在:${configPath}`, '运行 yizhuan config init。'))
package/src/index.js CHANGED
@@ -25,6 +25,7 @@ const ABILITIES = new Set([
25
25
  'work_query',
26
26
  'membership_info',
27
27
  'favorites_query'
28
+ ,'detection'
28
29
  ])
29
30
 
30
31
  const PARAM_FLAG_KEYS = [
@@ -67,6 +68,7 @@ Examples:
67
68
  yizhuan execute --ability accounts --params '{"mode":"public_search","platform":"toutiao","keyword":"张三"}'
68
69
  yizhuan execute --ability radar --params '{"mode":"following"}'
69
70
  yizhuan execute --ability radar --mode timeline --timeRange 7d
71
+ yizhuan execute --ability detection --json-file detection.json
70
72
  yizhuan execute --ability radar --params '{"mode":"unfollow","articleId":"205169870"}'
71
73
 
72
74
  Notes:
@@ -84,6 +86,7 @@ Abilities:
84
86
  membership 会员查询
85
87
  favorites 收藏查询
86
88
  public_author_search 作者全网搜索,兼容低层能力
89
+ detection 一键检测(原创/风险)
87
90
 
88
91
  Config:
89
92
  ${CONFIG_PATH}
@@ -366,8 +369,29 @@ async function execute(args) {
366
369
  throw new Error(`请求失败 HTTP ${response.status}:${text}`)
367
370
  }
368
371
 
369
- const payload = JSON.parse(text)
370
- console.log(JSON.stringify(payload.result?.data?.json ?? payload, null, 2))
372
+ let result = payloadResult(JSON.parse(text))
373
+ const requestParams = buildExecuteParams(args)
374
+ if (ability === 'detection' && requestParams?.wait === true && result?.status === 'pending' && result?.data?.id) {
375
+ const timeoutSeconds = Number(requestParams.timeoutSeconds) > 0 ? Number(requestParams.timeoutSeconds) : 120
376
+ const deadline = Date.now() + timeoutSeconds * 1000
377
+ while (Date.now() < deadline && result.status === 'pending') {
378
+ await new Promise((resolve) => setTimeout(resolve, Math.max(500, Number(result.data.pollAfterSeconds || 3) * 1000)))
379
+ if (Date.now() >= deadline) break
380
+ const poll = await fetch(`${config.apiBaseUrl}/api/cli.execute`, {
381
+ method: 'POST',
382
+ headers: { authorization: config.apiKey, 'content-type': 'application/json', 'x-device-type': 'pc' },
383
+ body: JSON.stringify({ json: { ability: 'detection', params: { mode: 'get', id: result.data.id } } })
384
+ })
385
+ const pollText = await poll.text()
386
+ if (!poll.ok) throw new Error(`请求失败 HTTP ${poll.status}:${pollText}`)
387
+ result = payloadResult(JSON.parse(pollText))
388
+ }
389
+ }
390
+ console.log(JSON.stringify(result, null, 2))
391
+ }
392
+
393
+ function payloadResult(payload) {
394
+ return payload.result?.data?.json ?? payload
371
395
  }
372
396
 
373
397
  function renderQuery(payload, format) {