@sheepbun/yips 0.1.46 → 0.1.47

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/postinstall.js +29 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheepbun/yips",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "description": "Yips Personal Desktop Agent",
5
5
  "scripts": {
6
6
  "postinstall": "node postinstall.js"
package/postinstall.js CHANGED
@@ -5,8 +5,8 @@ const os = require('os');
5
5
 
6
6
  const isWin = os.platform() === 'win32';
7
7
  const ext = isWin ? '.exe' : '';
8
- const binaryName = isWin ? 'yips-windows.exe' : 'yips-linux';
9
- const url = `https://github.com/sheepbun/yips/releases/latest/download/${binaryName}`;
8
+ const binaryName = isWin ? 'yips-core-windows.exe' : 'yips-core-linux';
9
+ const initialUrl = `https://github.com/sheepbun/yips/releases/latest/download/${binaryName}`;
10
10
  const binDir = path.join(__dirname, 'bin');
11
11
 
12
12
  if (!fs.existsSync(binDir)) {
@@ -15,35 +15,37 @@ if (!fs.existsSync(binDir)) {
15
15
 
16
16
  const dest = path.join(binDir, `yips${ext}`);
17
17
 
18
- console.log(`Downloading Yips binary from ${url}...`);
18
+ console.log(`Downloading Yips binary from ${initialUrl}...`);
19
19
 
20
- https.get(url, (res) => {
21
- if (res.statusCode === 301 || res.statusCode === 302) {
22
- // Follow redirect
23
- https.get(res.headers.location, (redirectRes) => {
24
- downloadStream(redirectRes);
25
- }).on('error', handleError);
26
- } else {
27
- downloadStream(res);
28
- }
29
- }).on('error', handleError);
30
-
31
- function downloadStream(res) {
32
- if (res.statusCode !== 200) {
33
- console.error(`Failed to download: HTTP ${res.statusCode}`);
34
- process.exit(1);
35
- }
36
- const file = fs.createWriteStream(dest);
37
- res.pipe(file);
38
- file.on('finish', () => {
39
- file.close();
40
- if (!isWin) {
41
- fs.chmodSync(dest, 0o755);
20
+ function download(url) {
21
+ https.get(url, (res) => {
22
+ if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307 || res.statusCode === 308) {
23
+ // Follow redirect
24
+ if (res.headers.location) {
25
+ download(res.headers.location);
26
+ } else {
27
+ console.error(`Redirect without location header (status ${res.statusCode})`);
28
+ process.exit(1);
29
+ }
30
+ } else if (res.statusCode === 200) {
31
+ const file = fs.createWriteStream(dest);
32
+ res.pipe(file);
33
+ file.on('finish', () => {
34
+ file.close();
35
+ if (!isWin) {
36
+ fs.chmodSync(dest, 0o755);
37
+ }
38
+ console.log('Downloaded Yips binary successfully.');
39
+ });
40
+ } else {
41
+ console.error(`Failed to download: HTTP ${res.statusCode}`);
42
+ process.exit(1);
42
43
  }
43
- console.log('Downloaded Yips binary successfully.');
44
- });
44
+ }).on('error', handleError);
45
45
  }
46
46
 
47
+ download(initialUrl);
48
+
47
49
  function handleError(err) {
48
50
  console.error('Error downloading Yips:', err.message);
49
51
  process.exit(1);