@luutuankiet/gsd-reader 0.2.20 → 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.
Files changed (2) hide show
  1. package/cli.cjs +31 -21
  2. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -242,34 +242,44 @@ function promptPassword(prompt) {
242
242
  });
243
243
  }
244
244
 
245
- async function httpRequest(url, options, data) {
246
- const controller = new AbortController();
247
- const timeout = setTimeout(() => controller.abort(), 30000);
245
+ function httpRequest(url, options, data) {
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);
248
250
 
249
251
  try {
250
- const res = await fetch(url, {
251
- method: options.method || 'POST',
252
- headers: options.headers,
253
- body: data,
254
- signal: controller.signal,
255
- });
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}`);
264
+ }
265
+ }
256
266
 
257
- const body = await res.text();
267
+ curlArgs.push(url.toString());
258
268
 
259
- if (res.ok) {
260
- return body.trim() || `HTTP ${res.status}`;
261
- } else if (res.status === 401) {
262
- throw new Error('Authentication failed (401). Check username/password.');
263
- } else {
264
- throw new Error(`HTTP ${res.status}: ${body}`);
265
- }
269
+ const result = execFileSync('curl', curlArgs, {
270
+ encoding: 'utf-8',
271
+ timeout: 120000,
272
+ });
273
+
274
+ return result.trim() || 'Upload complete';
266
275
  } catch (err) {
267
- if (err.name === 'AbortError') {
268
- throw new Error('Request timed out after 30s. Check server/proxy status.');
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.');
269
279
  }
270
- throw err;
280
+ throw new Error(stderr || err.message);
271
281
  } finally {
272
- clearTimeout(timeout);
282
+ try { fs.unlinkSync(tmpFile); } catch (e) {}
273
283
  }
274
284
  }
275
285
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luutuankiet/gsd-reader",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "Interactive Worklog Reader for GSD-Lite WORK.md files with live reload",
5
5
  "keywords": [
6
6
  "gsd-lite",