@aweray/hsk-cli 0.3.0 → 0.4.2

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/bin/hsk-cli.js CHANGED
@@ -181,13 +181,14 @@ const hostCmd = program
181
181
  .option('--json', '以 JSON 格式输出(等同于 --format json)')
182
182
  .option('--open', '上传完成后自动打开浏览器进行认领')
183
183
  .option('--resource-id <id>', '资源 ID(传入则更新已有资源,否则创建新资源)')
184
+ .option('--reuse', '复用已有资源,不存在则创建新资源')
184
185
  .action(async (filePath, options) => {
185
186
  const fmt = getFormat(options);
186
187
  if (isDryRun(options)) {
187
188
  const fs = require('fs');
188
189
  const path = require('path');
189
190
  const stats = fs.existsSync(filePath) ? fs.statSync(filePath) : null;
190
- const apiUrl = process.env.HSK_FILE_HOSTING_API || 'https://onion-forward-api.oraybeta.com/public/file-hosting';
191
+ const apiUrl = process.env.HSK_FILE_HOSTING_API;
191
192
  const cmdParts = ['hsk-cli file-hosting'];
192
193
  if (apiUrl) cmdParts.push(`-api "${apiUrl}"`);
193
194
  if (options.resourceId) cmdParts.push(`-resource-id ${options.resourceId}`);
@@ -205,7 +206,7 @@ const hostCmd = program
205
206
  return;
206
207
  }
207
208
  try {
208
- const result = await fileHosting.host(filePath, { resourceId: options.resourceId });
209
+ const result = await fileHosting.host(filePath, { resourceId: options.resourceId, reuse: options.reuse });
209
210
  handleOutput(result, fmt);
210
211
  if (options.open && result.publicUrl) {
211
212
  console.log(chalk.gray('🌐 正在打开浏览器...'));
@@ -301,8 +302,8 @@ program
301
302
  .option('--build-dir <dir>', '构建输出目录,如 "dist"')
302
303
  .option('--pack-output <file>', '打包输出文件名,如 "dist.zip"', 'dist.zip')
303
304
  .option('--no-build', '跳过构建,直接打包上传')
304
- .option('--no-clean', '上传后保留打包文件')
305
305
  .option('--resource-id <id>', '资源 ID(更新已有资源)')
306
+ .option('--reuse', '复用已有资源,不存在则创建新资源')
306
307
  .option('--open', '上传完成后自动打开浏览器进行认领')
307
308
  .option('--json', '以 JSON 格式输出(等同于 --format json)')
308
309
  .action(async (options) => {
@@ -316,10 +317,11 @@ program
316
317
 
317
318
  if (isDryRun(options)) {
318
319
  const info = options.arch ? platform.fromString(options.arch) : platform.detect();
319
- const apiUrl = process.env.HSK_FILE_HOSTING_API || 'https://onion-forward-api.oraybeta.com/public/file-hosting';
320
+ const apiUrl = process.env.HSK_FILE_HOSTING_API;
320
321
  const cmdParts = ['hsk-cli file-hosting'];
321
322
  if (apiUrl) cmdParts.push(`-api "${apiUrl}"`);
322
323
  if (options.resourceId) cmdParts.push(`-resource-id ${options.resourceId}`);
324
+ if (options.reuse) cmdParts.push('--reuse');
323
325
  cmdParts.push(buildDir);
324
326
  console.log(format.dryRunInfo(
325
327
  `${buildCmd} → ${cmdParts.join(' ')}`,
@@ -327,6 +329,7 @@ program
327
329
  构建命令: buildCmd,
328
330
  构建目录: buildDir,
329
331
  资源ID: options.resourceId || '(新建)',
332
+ 复用检测: options.reuse ? '启用' : '禁用',
330
333
  预期操作: '构建 → 原生二进制自动打包目录 → 上传',
331
334
  预期输出: '[AI_RESULT] public_url + resource_id',
332
335
  }
@@ -350,7 +353,7 @@ program
350
353
 
351
354
  // 3. 上传(原生二进制自动打包目录)
352
355
  console.log(chalk.cyan('☁️ 上传中...'));
353
- const result = await fileHosting.host(buildDir, { resourceId: options.resourceId });
356
+ const result = await fileHosting.host(buildDir, { resourceId: options.resourceId, reuse: options.reuse });
354
357
 
355
358
  handleOutput(result, fmt);
356
359
 
@@ -3,6 +3,7 @@ const path = require('path');
3
3
  const { spawn } = require('child_process');
4
4
  const download = require('./download');
5
5
  const resourceStore = require('./resourceStore');
6
+ const resourceChecker = require('./resourceChecker');
6
7
 
7
8
  /**
8
9
  * 解析原生二进制输出,提取 [AI_RESULT] 键值对
@@ -49,6 +50,34 @@ async function host(filePath, options = {}) {
49
50
  throw new Error(`文件不存在: ${resolvedPath}`);
50
51
  }
51
52
 
53
+ // === reuse: 检测已有资源是否有效 ===
54
+ if (options.reuse) {
55
+ let existing = null;
56
+ if (options.resourceId) {
57
+ existing = resourceStore.findResource((r) => r.type === 'host' && r.resourceId === options.resourceId);
58
+ } else {
59
+ existing = resourceStore.findResource((r) => r.type === 'host' && r.filePath === resolvedPath);
60
+ }
61
+ if (existing) {
62
+ const check = await resourceChecker.checkResource(existing);
63
+ if (check.valid) {
64
+ return {
65
+ success: true,
66
+ mode: 'reused',
67
+ publicUrl: existing.publicUrl,
68
+ resourceId: existing.resourceId,
69
+ filePath: resolvedPath,
70
+ fileName: path.basename(resolvedPath),
71
+ reused: true,
72
+ };
73
+ }
74
+ // 失效:保存旧 resourceId 用于更新
75
+ if (!options.resourceId) {
76
+ options.resourceId = existing.resourceId;
77
+ }
78
+ }
79
+ }
80
+
52
81
  // 确保原生二进制存在
53
82
  const binPath = await download.ensureBinary();
54
83
 
package/lib/tunnel.js CHANGED
@@ -41,7 +41,7 @@ async function start(options) {
41
41
  }
42
42
 
43
43
  const binPath = await download.ensureBinary(arch);
44
- const args = ['-ip', ip, '-port', String(portNum)];
44
+ const args = ['tunnel', '-ip', ip, '-port', String(portNum)];
45
45
 
46
46
  if (detached) {
47
47
  const logFile = pidManager.getLogFilePath('tunnel', { ip, port: portNum });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aweray/hsk-cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.2",
4
4
  "description": "HSK CLI - 内网穿透 & 文件托管,支持 Windows/macOS/Linux 多平台",
5
5
  "main": "index.js",
6
6
  "bin": {
package/versions.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
- "version": "0.3.0",
2
+ "version": "0.4.2",
3
3
  "downloadBaseUrl": "https://dw.oray.com/onion/cli",
4
4
  "binaries": {
5
5
  "windows-amd64": {
6
- "filename": "hsk-cli-windows-amd64-v0.3.0.exe"
6
+ "filename": "hsk-cli-windows-amd64-v0.4.2.exe"
7
7
  },
8
8
  "darwin-amd64": {
9
- "filename": "hsk-cli-darwin-amd64-v0.3.0"
9
+ "filename": "hsk-cli-darwin-amd64-v0.4.2"
10
10
  },
11
11
  "darwin-arm64": {
12
- "filename": "hsk-cli-darwin-arm64-v0.3.0"
12
+ "filename": "hsk-cli-darwin-arm64-v0.4.2"
13
13
  },
14
14
  "linux-amd64": {
15
- "filename": "hsk-cli-linux-amd64-v0.3.0"
15
+ "filename": "hsk-cli-linux-amd64-v0.4.2"
16
16
  }
17
17
  }
18
18
  }