+39
-18
@@ -42,21 +42,42 @@ #!/usr/bin/env node | ||
| return new Promise((resolve, reject) => { | ||
| https.get(url, (res) => { | ||
| if (res.statusCode === 302 || res.statusCode === 301) { | ||
| download(res.headers.location).then(resolve).catch(reject); | ||
| return; | ||
| } | ||
| const file = fs.createWriteStream(path.join(binDir, 'download' + platform.ext)); | ||
| res.pipe(file); | ||
| file.on('finish', () => { | ||
| if (platform.ext === '.zip') { | ||
| const { execSync } = require('child_process'); | ||
| execSync(`powershell -Command "Expand-Archive -Path '${file.path}' -DestinationPath '${binDir}' -Force"`); | ||
| } else { | ||
| const { execSync } = require('child_process'); | ||
| execSync(`tar -xzf '${file.path}' -C '${binDir}'`); | ||
| const doDownload = (downloadUrl) => { | ||
| https.get(downloadUrl, (res) => { | ||
| if (res.statusCode === 302 || res.statusCode === 301) { | ||
| const redirectUrl = res.headers.location; | ||
| if (!redirectUrl) { | ||
| reject(new Error('Redirect without location')); | ||
| return; | ||
| } | ||
| doDownload(redirectUrl); | ||
| return; | ||
| } | ||
| fs.unlinkSync(file.path); | ||
| resolve(); | ||
| }); | ||
| }).on('error', reject); | ||
| if (res.statusCode !== 200) { | ||
| reject(new Error(`Download failed with status ${res.statusCode}`)); | ||
| return; | ||
| } | ||
| const file = fs.createWriteStream(path.join(binDir, 'download' + platform.ext)); | ||
| res.pipe(file); | ||
| file.on('finish', () => { | ||
| try { | ||
| if (platform.ext === '.zip') { | ||
| const { execSync } = require('child_process'); | ||
| execSync(`powershell -Command "Expand-Archive -Path '${file.path}' -DestinationPath '${binDir}' -Force"`, { stdio: 'ignore' }); | ||
| } else { | ||
| const { execSync } = require('child_process'); | ||
| execSync(`tar -xzf '${file.path}' -C '${binDir}'`, { stdio: 'ignore' }); | ||
| } | ||
| fs.unlinkSync(file.path); | ||
| if (!fs.existsSync(binPath)) { | ||
| reject(new Error('Downloaded file not found after extraction')); | ||
| return; | ||
| } | ||
| resolve(); | ||
| } catch (err) { | ||
| reject(err); | ||
| } | ||
| }); | ||
| file.on('error', reject); | ||
| }).on('error', reject); | ||
| }; | ||
| doDownload(url); | ||
| }); | ||
@@ -63,0 +84,0 @@ } |
+1
-1
| { | ||
| "name": "codexctl", | ||
| "version": "0.4.5", | ||
| "version": "0.4.6", | ||
| "description": "Codex CLI Profile Manager - Manage multiple AI CLI accounts", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
8791
9.06%148
16.54%