@luutuankiet/gsd-reader 0.2.19 → 0.2.21
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/cli.cjs +36 -30
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -243,38 +243,44 @@ function promptPassword(prompt) {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
function httpRequest(url, options, data) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
req.setTimeout(30000, () => {
|
|
265
|
-
req.destroy(new Error('Request timed out after 30s. Check server/proxy status.'));
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
req.on('error', (err) => {
|
|
269
|
-
if (err.code === 'ECONNRESET') {
|
|
270
|
-
reject(new Error('Connection reset by server. Causes: (1) Reverse proxy body size limit, (2) Server rejected upload, (3) Network interruption. Original: ' + err.message));
|
|
271
|
-
} else {
|
|
272
|
-
reject(err);
|
|
246
|
+
// Use curl subprocess — Node.js https/fetch has HTTP/1.1 issues with Cloudflare
|
|
247
|
+
const { execFileSync } = require('child_process');
|
|
248
|
+
const tmpFile = path.join(require('os').tmpdir(), `gsd-upload-${Date.now()}.tar.gz`);
|
|
249
|
+
fs.writeFileSync(tmpFile, data);
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
const curlArgs = [
|
|
253
|
+
'--silent',
|
|
254
|
+
'--show-error',
|
|
255
|
+
'--fail',
|
|
256
|
+
'--max-time', '120',
|
|
257
|
+
'--data-binary', `@${tmpFile}`,
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
// Forward headers (skip Content-Length — curl calculates from file)
|
|
261
|
+
for (const [key, value] of Object.entries(options.headers)) {
|
|
262
|
+
if (key.toLowerCase() !== 'content-length') {
|
|
263
|
+
curlArgs.push('-H', `${key}: ${value}`);
|
|
273
264
|
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
curlArgs.push(url.toString());
|
|
268
|
+
|
|
269
|
+
const result = execFileSync('curl', curlArgs, {
|
|
270
|
+
encoding: 'utf-8',
|
|
271
|
+
timeout: 120000,
|
|
274
272
|
});
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
})
|
|
273
|
+
|
|
274
|
+
return result.trim() || 'Upload complete';
|
|
275
|
+
} catch (err) {
|
|
276
|
+
const stderr = (err.stderr || '').toString();
|
|
277
|
+
if (stderr.includes('401') || (err.status === 22 && stderr.includes('Unauthorized'))) {
|
|
278
|
+
throw new Error('Authentication failed (401). Check username/password.');
|
|
279
|
+
}
|
|
280
|
+
throw new Error(stderr || err.message);
|
|
281
|
+
} finally {
|
|
282
|
+
try { fs.unlinkSync(tmpFile); } catch (e) {}
|
|
283
|
+
}
|
|
278
284
|
}
|
|
279
285
|
|
|
280
286
|
// =============================================================================
|