@lijuneleven/easy-terminal 0.1.0 → 0.1.1

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
@@ -12,3 +12,5 @@ The CLI starts the local `easy_terminal` service. Pass server flags directly:
12
12
  ```sh
13
13
  easy-terminal --port 9090
14
14
  ```
15
+
16
+ The installer downloads the platform binary from GitHub Release first, then falls back to Gitee Release.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lijuneleven/easy-terminal",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Local web terminal with Feishu remote session control.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const fs = require("fs");
4
- const os = require("os");
5
4
  const path = require("path");
5
+ const http = require("http");
6
6
  const https = require("https");
7
7
  const { pipeline } = require("stream/promises");
8
8
  const { createWriteStream } = require("fs");
@@ -11,9 +11,11 @@ const packageJson = require("../package.json");
11
11
 
12
12
  const owner = process.env.EASY_TERMINAL_GITHUB_OWNER || "elevenlj";
13
13
  const repo = process.env.EASY_TERMINAL_GITHUB_REPO || "easy_terminal";
14
+ const giteeRepo = process.env.EASY_TERMINAL_GITEE_REPO || "eleven_lj/easy_terminal";
14
15
  const version = packageJson.version;
15
16
  const platform = process.platform;
16
17
  const arch = process.arch;
18
+ const requestTimeoutMs = Number(process.env.EASY_TERMINAL_DOWNLOAD_TIMEOUT_MS || 30000);
17
19
 
18
20
  const platformMap = {
19
21
  darwin: "darwin",
@@ -44,20 +46,24 @@ if (!targetPlatform || !targetArch) {
44
46
 
45
47
  const ext = targetPlatform === "windows" ? ".exe" : "";
46
48
  const assetName = `easy_terminal-${targetPlatform}-${targetArch}${ext}`;
47
- const url = `https://github.com/${owner}/${repo}/releases/download/v${version}/${assetName}`;
49
+ const urls = [
50
+ `https://github.com/${owner}/${repo}/releases/download/v${version}/${assetName}`,
51
+ `https://gitee.com/${giteeRepo}/releases/download/v${version}/${assetName}`
52
+ ];
48
53
  const vendorDir = path.resolve(__dirname, "..", "vendor");
49
54
  const outPath = path.join(vendorDir, targetPlatform === "windows" ? "easy_terminal.exe" : "easy_terminal");
50
55
 
51
56
  async function download(downloadUrl, redirects = 0) {
52
57
  if (redirects > 5) {
53
- fail("too many redirects while downloading binary");
58
+ throw new Error("too many redirects while downloading binary");
54
59
  }
55
60
 
56
61
  await fs.promises.mkdir(vendorDir, { recursive: true });
57
62
 
58
63
  await new Promise((resolve, reject) => {
59
- https
60
- .get(downloadUrl, (res) => {
64
+ const mod = downloadUrl.startsWith("https:") ? https : http;
65
+ const request = mod
66
+ .get(downloadUrl, { headers: { "User-Agent": "easy-terminal-npm" } }, (res) => {
61
67
  if ([301, 302, 303, 307, 308].includes(res.statusCode || 0)) {
62
68
  res.resume();
63
69
  download(res.headers.location, redirects + 1).then(resolve, reject);
@@ -73,6 +79,9 @@ async function download(downloadUrl, redirects = 0) {
73
79
  pipeline(res, createWriteStream(outPath)).then(resolve, reject);
74
80
  })
75
81
  .on("error", reject);
82
+ request.setTimeout(requestTimeoutMs, () => {
83
+ request.destroy(new Error(`download timed out after ${requestTimeoutMs}ms`));
84
+ });
76
85
  });
77
86
 
78
87
  if (targetPlatform !== "windows") {
@@ -80,10 +89,27 @@ async function download(downloadUrl, redirects = 0) {
80
89
  }
81
90
  }
82
91
 
83
- download(url).catch((err) => {
84
- try {
85
- fs.rmSync(outPath, { force: true });
86
- } catch (_) {
92
+ async function main() {
93
+ const failures = [];
94
+
95
+ for (const url of urls) {
96
+ try {
97
+ console.log(`[easy-terminal] downloading ${assetName}`);
98
+ console.log(`[easy-terminal] source: ${url}`);
99
+ await download(url);
100
+ console.log(`[easy-terminal] installed binary to ${outPath}`);
101
+ return;
102
+ } catch (err) {
103
+ try {
104
+ fs.rmSync(outPath, { force: true });
105
+ } catch (_) {
106
+ }
107
+ failures.push(`${url}: ${err.message}`);
108
+ console.warn(`[easy-terminal] download failed, trying next source`);
109
+ }
87
110
  }
88
- fail(`${err.message}. URL: ${url}`);
89
- });
111
+
112
+ fail(`could not download binary from any source.\n${failures.map((item) => `- ${item}`).join("\n")}`);
113
+ }
114
+
115
+ main();