@luutuankiet/gsd-reader 0.2.21 → 0.2.23
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 +24 -34
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -56,8 +56,8 @@ const positionalArgs = args.filter(a => !a.startsWith('--') && a !== command);
|
|
|
56
56
|
|
|
57
57
|
async function commandDump() {
|
|
58
58
|
const worklogPath = positionalArgs[0] || './gsd-lite/WORK.md';
|
|
59
|
-
const remote = getFlag('remote');
|
|
60
|
-
const user = getFlag('user');
|
|
59
|
+
const remote = getFlag('remote') || process.env.GSD_READER_REMOTE;
|
|
60
|
+
const user = getFlag('user') || process.env.GSD_READER_USER;
|
|
61
61
|
|
|
62
62
|
if (!remote) {
|
|
63
63
|
console.error('❌ --remote=URL is required');
|
|
@@ -144,7 +144,7 @@ async function commandDump() {
|
|
|
144
144
|
console.log(`[dump] Archive created: ${(tarStats.size / 1024).toFixed(1)} KB`);
|
|
145
145
|
|
|
146
146
|
// Step 3: Get password
|
|
147
|
-
let password = getFlag('pass');
|
|
147
|
+
let password = getFlag('pass') || process.env.GSD_READER_PASS;
|
|
148
148
|
if (!password && user) {
|
|
149
149
|
password = await promptPassword(`Password for ${user}: `);
|
|
150
150
|
}
|
|
@@ -242,44 +242,34 @@ function promptPassword(prompt) {
|
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
function httpRequest(url, options, data) {
|
|
246
|
-
|
|
247
|
-
const
|
|
248
|
-
const tmpFile = path.join(require('os').tmpdir(), `gsd-upload-${Date.now()}.tar.gz`);
|
|
249
|
-
fs.writeFileSync(tmpFile, data);
|
|
245
|
+
async function httpRequest(url, options, data) {
|
|
246
|
+
const controller = new AbortController();
|
|
247
|
+
const timeout = setTimeout(() => controller.abort(), 300000); // 5 min (intercontinental uploads)
|
|
250
248
|
|
|
251
249
|
try {
|
|
252
|
-
const
|
|
253
|
-
'
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
}
|
|
266
|
-
|
|
267
|
-
curlArgs.push(url.toString());
|
|
268
|
-
|
|
269
|
-
const result = execFileSync('curl', curlArgs, {
|
|
270
|
-
encoding: 'utf-8',
|
|
271
|
-
timeout: 120000,
|
|
250
|
+
const res = await fetch(url, {
|
|
251
|
+
method: options.method || 'POST',
|
|
252
|
+
headers: options.headers,
|
|
253
|
+
body: data,
|
|
254
|
+
signal: controller.signal,
|
|
272
255
|
});
|
|
273
256
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
257
|
+
const body = await res.text();
|
|
258
|
+
|
|
259
|
+
if (res.ok) {
|
|
260
|
+
return body.trim() || `HTTP ${res.status}`;
|
|
261
|
+
} else if (res.status === 401) {
|
|
278
262
|
throw new Error('Authentication failed (401). Check username/password.');
|
|
263
|
+
} else {
|
|
264
|
+
throw new Error(`HTTP ${res.status}: ${body}`);
|
|
265
|
+
}
|
|
266
|
+
} catch (err) {
|
|
267
|
+
if (err.name === 'AbortError') {
|
|
268
|
+
throw new Error('Request timed out after 300s. Check server/proxy status.');
|
|
279
269
|
}
|
|
280
|
-
throw
|
|
270
|
+
throw err;
|
|
281
271
|
} finally {
|
|
282
|
-
|
|
272
|
+
clearTimeout(timeout);
|
|
283
273
|
}
|
|
284
274
|
}
|
|
285
275
|
|