agentgui 1.0.274 → 1.0.275
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/CLAUDE.md +280 -280
- package/IPFS_DOWNLOADER.md +277 -277
- package/TASK_2C_COMPLETION.md +334 -334
- package/bin/gmgui.cjs +54 -54
- package/build-portable.js +3 -42
- package/database.js +1422 -1406
- package/lib/claude-runner.js +1130 -1130
- package/lib/ipfs-downloader.js +459 -459
- package/lib/speech.js +152 -152
- package/package.json +1 -1
- package/readme.md +76 -76
- package/server.js +3787 -3794
- package/setup-npm-token.sh +68 -68
- package/static/app.js +773 -773
- package/static/event-rendering-showcase.html +708 -708
- package/static/index.html +3178 -3180
- package/static/js/agent-auth.js +298 -298
- package/static/js/audio-recorder-processor.js +18 -18
- package/static/js/client.js +2656 -2656
- package/static/js/conversations.js +583 -583
- package/static/js/dialogs.js +267 -267
- package/static/js/event-consolidator.js +101 -101
- package/static/js/event-filter.js +311 -311
- package/static/js/event-processor.js +452 -452
- package/static/js/features.js +413 -413
- package/static/js/kalman-filter.js +67 -67
- package/static/js/progress-dialog.js +130 -130
- package/static/js/script-runner.js +219 -219
- package/static/js/streaming-renderer.js +2123 -2120
- package/static/js/syntax-highlighter.js +269 -269
- package/static/js/tts-websocket-handler.js +152 -152
- package/static/js/ui-components.js +431 -431
- package/static/js/voice.js +849 -849
- package/static/js/websocket-manager.js +596 -596
- package/static/templates/INDEX.html +465 -465
- package/static/templates/README.md +190 -190
- package/static/templates/agent-capabilities.html +56 -56
- package/static/templates/agent-metadata-panel.html +44 -44
- package/static/templates/agent-status-badge.html +30 -30
- package/static/templates/code-annotation-panel.html +155 -155
- package/static/templates/code-suggestion-panel.html +184 -184
- package/static/templates/command-header.html +77 -77
- package/static/templates/command-output-scrollable.html +118 -118
- package/static/templates/elapsed-time.html +54 -54
- package/static/templates/error-alert.html +106 -106
- package/static/templates/error-history-timeline.html +160 -160
- package/static/templates/error-recovery-options.html +109 -109
- package/static/templates/error-stack-trace.html +95 -95
- package/static/templates/error-summary.html +80 -80
- package/static/templates/event-counter.html +48 -48
- package/static/templates/execution-actions.html +97 -97
- package/static/templates/execution-progress-bar.html +80 -80
- package/static/templates/execution-stepper.html +120 -120
- package/static/templates/file-breadcrumb.html +118 -118
- package/static/templates/file-diff-viewer.html +121 -121
- package/static/templates/file-metadata.html +133 -133
- package/static/templates/file-read-panel.html +66 -66
- package/static/templates/file-write-panel.html +120 -120
- package/static/templates/git-branch-remote.html +107 -107
- package/static/templates/git-diff-list.html +101 -101
- package/static/templates/git-log-visualization.html +153 -153
- package/static/templates/git-status-panel.html +115 -115
- package/static/templates/quality-metrics-display.html +170 -170
- package/static/templates/terminal-output-panel.html +87 -87
- package/static/templates/test-results-display.html +144 -144
- package/static/theme.js +72 -72
- package/test-download-progress.js +223 -223
- package/test-websocket-broadcast.js +147 -147
- package/tests/ipfs-downloader.test.js +370 -370
|
@@ -1,223 +1,223 @@
|
|
|
1
|
-
import https from 'https';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
|
|
6
|
-
const testDir = path.join(os.tmpdir(), 'test-download-progress');
|
|
7
|
-
if (!fs.existsSync(testDir)) {
|
|
8
|
-
fs.mkdirSync(testDir, { recursive: true });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const GATEWAYS = [
|
|
12
|
-
'https://ipfs.io',
|
|
13
|
-
'https://gateway.pinata.cloud',
|
|
14
|
-
'https://cloudflare-ipfs.com',
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
function downloadWithProgress(url, destination, onProgress = null) {
|
|
18
|
-
let bytesDownloaded = 0;
|
|
19
|
-
let totalBytes = 0;
|
|
20
|
-
let lastProgressTime = Date.now();
|
|
21
|
-
let lastProgressBytes = 0;
|
|
22
|
-
const speeds = [];
|
|
23
|
-
let retryCount = 0;
|
|
24
|
-
let gatewayIndex = 0;
|
|
25
|
-
|
|
26
|
-
const emitProgress = () => {
|
|
27
|
-
const now = Date.now();
|
|
28
|
-
const deltaTime = (now - lastProgressTime) / 1000;
|
|
29
|
-
const deltaBytes = bytesDownloaded - lastProgressBytes;
|
|
30
|
-
const speed = deltaTime > 0 ? Math.round(deltaBytes / deltaTime) : 0;
|
|
31
|
-
|
|
32
|
-
if (speed > 0) {
|
|
33
|
-
speeds.push(speed);
|
|
34
|
-
if (speeds.length > 10) speeds.shift();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const avgSpeed = speeds.length > 0 ? Math.round(speeds.reduce((a, b) => a + b, 0) / speeds.length) : 0;
|
|
38
|
-
const eta = avgSpeed > 0 && totalBytes > bytesDownloaded ? Math.round((totalBytes - bytesDownloaded) / avgSpeed) : 0;
|
|
39
|
-
|
|
40
|
-
if (onProgress) {
|
|
41
|
-
onProgress({
|
|
42
|
-
bytesDownloaded,
|
|
43
|
-
bytesRemaining: Math.max(0, totalBytes - bytesDownloaded),
|
|
44
|
-
totalBytes,
|
|
45
|
-
downloadSpeed: avgSpeed,
|
|
46
|
-
eta,
|
|
47
|
-
retryCount,
|
|
48
|
-
currentGateway: url,
|
|
49
|
-
status: bytesDownloaded >= totalBytes ? 'completed' : 'downloading',
|
|
50
|
-
percentComplete: totalBytes > 0 ? Math.round((bytesDownloaded / totalBytes) * 100) : 0,
|
|
51
|
-
timestamp: now
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
lastProgressTime = now;
|
|
56
|
-
lastProgressBytes = bytesDownloaded;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
const dir = path.dirname(destination);
|
|
61
|
-
if (!fs.existsSync(dir)) {
|
|
62
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const attemptDownload = (gateway) => {
|
|
66
|
-
if (onProgress) {
|
|
67
|
-
onProgress({
|
|
68
|
-
bytesDownloaded: 0,
|
|
69
|
-
bytesRemaining: 0,
|
|
70
|
-
totalBytes: 0,
|
|
71
|
-
downloadSpeed: 0,
|
|
72
|
-
eta: 0,
|
|
73
|
-
retryCount,
|
|
74
|
-
currentGateway: gateway,
|
|
75
|
-
status: 'connecting',
|
|
76
|
-
percentComplete: 0,
|
|
77
|
-
timestamp: Date.now()
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
https.get(gateway, { timeout: 30000 }, (res) => {
|
|
82
|
-
if ([301, 302, 307, 308].includes(res.statusCode)) {
|
|
83
|
-
const location = res.headers.location;
|
|
84
|
-
if (location) return attemptDownload(location);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (res.statusCode !== 200) {
|
|
88
|
-
res.resume();
|
|
89
|
-
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
90
|
-
retryCount++;
|
|
91
|
-
gatewayIndex++;
|
|
92
|
-
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
93
|
-
}
|
|
94
|
-
return reject(new Error(`HTTP ${res.statusCode}`));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
totalBytes = parseInt(res.headers['content-length'], 10) || 0;
|
|
98
|
-
bytesDownloaded = 0;
|
|
99
|
-
lastProgressBytes = 0;
|
|
100
|
-
lastProgressTime = Date.now();
|
|
101
|
-
|
|
102
|
-
const file = fs.createWriteStream(destination);
|
|
103
|
-
let lastEmit = Date.now();
|
|
104
|
-
|
|
105
|
-
res.on('data', (chunk) => {
|
|
106
|
-
bytesDownloaded += chunk.length;
|
|
107
|
-
const now = Date.now();
|
|
108
|
-
if (now - lastEmit >= 200) {
|
|
109
|
-
emitProgress();
|
|
110
|
-
lastEmit = now;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
res.on('end', () => {
|
|
115
|
-
emitProgress();
|
|
116
|
-
file.destroy();
|
|
117
|
-
resolve({ destination, bytesDownloaded, success: true });
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
res.on('error', (err) => {
|
|
121
|
-
file.destroy();
|
|
122
|
-
fs.unlink(destination, () => {});
|
|
123
|
-
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
124
|
-
retryCount++;
|
|
125
|
-
gatewayIndex++;
|
|
126
|
-
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
127
|
-
}
|
|
128
|
-
reject(err);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
file.on('error', (err) => {
|
|
132
|
-
res.destroy();
|
|
133
|
-
fs.unlink(destination, () => {});
|
|
134
|
-
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
135
|
-
retryCount++;
|
|
136
|
-
gatewayIndex++;
|
|
137
|
-
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
138
|
-
}
|
|
139
|
-
reject(err);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
res.pipe(file);
|
|
143
|
-
}).on('timeout', () => {
|
|
144
|
-
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
145
|
-
retryCount++;
|
|
146
|
-
gatewayIndex++;
|
|
147
|
-
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
148
|
-
}
|
|
149
|
-
reject(new Error('Download timeout'));
|
|
150
|
-
}).on('error', (err) => {
|
|
151
|
-
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
152
|
-
retryCount++;
|
|
153
|
-
gatewayIndex++;
|
|
154
|
-
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
155
|
-
}
|
|
156
|
-
reject(err);
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
attemptDownload(GATEWAYS[0]);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
let progressCount = 0;
|
|
165
|
-
let lastPrintTime = Date.now();
|
|
166
|
-
let minInterval = Infinity;
|
|
167
|
-
let maxInterval = 0;
|
|
168
|
-
const progressIntervals = [];
|
|
169
|
-
|
|
170
|
-
console.log('Starting download progress tracking test...\n');
|
|
171
|
-
|
|
172
|
-
downloadWithProgress(
|
|
173
|
-
'https://www.w3.org/WAI/WCAG21/Techniques/pdf/pdf-files/table-example.pdf',
|
|
174
|
-
path.join(testDir, 'test-file.pdf'),
|
|
175
|
-
(progress) => {
|
|
176
|
-
progressCount++;
|
|
177
|
-
const now = Date.now();
|
|
178
|
-
const interval = now - lastPrintTime;
|
|
179
|
-
|
|
180
|
-
if (progressCount > 1) {
|
|
181
|
-
progressIntervals.push(interval);
|
|
182
|
-
minInterval = Math.min(minInterval, interval);
|
|
183
|
-
maxInterval = Math.max(maxInterval, interval);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
console.log(`[${progressCount}] Progress Update:
|
|
187
|
-
Status: ${progress.status}
|
|
188
|
-
Downloaded: ${(progress.bytesDownloaded / 1024).toFixed(1)}KB / ${(progress.totalBytes / 1024).toFixed(1)}KB
|
|
189
|
-
Speed: ${(progress.downloadSpeed / 1024).toFixed(2)}MB/s
|
|
190
|
-
ETA: ${progress.eta}s
|
|
191
|
-
Complete: ${progress.percentComplete}%
|
|
192
|
-
Retry Count: ${progress.retryCount}
|
|
193
|
-
Gateway: ${progress.currentGateway}
|
|
194
|
-
Interval: ${interval}ms\n`);
|
|
195
|
-
|
|
196
|
-
lastPrintTime = now;
|
|
197
|
-
}
|
|
198
|
-
).then((result) => {
|
|
199
|
-
const avgInterval = progressIntervals.length > 0 ? progressIntervals.reduce((a, b) => a + b, 0) / progressIntervals.length : 0;
|
|
200
|
-
console.log('\n=== Download Complete ===');
|
|
201
|
-
console.log(`Result: ${JSON.stringify(result, null, 2)}`);
|
|
202
|
-
console.log(`\nProgress Tracking Statistics:
|
|
203
|
-
Total Updates: ${progressCount}
|
|
204
|
-
Interval Range: ${minInterval}ms - ${maxInterval}ms
|
|
205
|
-
Average Interval: ${avgInterval.toFixed(0)}ms
|
|
206
|
-
Expected Interval: 200ms (should be 100-500ms range)`);
|
|
207
|
-
|
|
208
|
-
if (avgInterval >= 100 && avgInterval <= 500) {
|
|
209
|
-
console.log(' Status: PASS - Progress interval within acceptable range');
|
|
210
|
-
} else {
|
|
211
|
-
console.log(' Status: FAIL - Progress interval outside acceptable range');
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (fs.existsSync(path.join(testDir, 'test-file.pdf'))) {
|
|
215
|
-
const stat = fs.statSync(path.join(testDir, 'test-file.pdf'));
|
|
216
|
-
console.log(`\nDownloaded file size: ${(stat.size / 1024).toFixed(1)}KB`);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
process.exit(0);
|
|
220
|
-
}).catch((err) => {
|
|
221
|
-
console.error('Download failed:', err.message);
|
|
222
|
-
process.exit(1);
|
|
223
|
-
});
|
|
1
|
+
import https from 'https';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import os from 'os';
|
|
5
|
+
|
|
6
|
+
const testDir = path.join(os.tmpdir(), 'test-download-progress');
|
|
7
|
+
if (!fs.existsSync(testDir)) {
|
|
8
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const GATEWAYS = [
|
|
12
|
+
'https://ipfs.io',
|
|
13
|
+
'https://gateway.pinata.cloud',
|
|
14
|
+
'https://cloudflare-ipfs.com',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
function downloadWithProgress(url, destination, onProgress = null) {
|
|
18
|
+
let bytesDownloaded = 0;
|
|
19
|
+
let totalBytes = 0;
|
|
20
|
+
let lastProgressTime = Date.now();
|
|
21
|
+
let lastProgressBytes = 0;
|
|
22
|
+
const speeds = [];
|
|
23
|
+
let retryCount = 0;
|
|
24
|
+
let gatewayIndex = 0;
|
|
25
|
+
|
|
26
|
+
const emitProgress = () => {
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
const deltaTime = (now - lastProgressTime) / 1000;
|
|
29
|
+
const deltaBytes = bytesDownloaded - lastProgressBytes;
|
|
30
|
+
const speed = deltaTime > 0 ? Math.round(deltaBytes / deltaTime) : 0;
|
|
31
|
+
|
|
32
|
+
if (speed > 0) {
|
|
33
|
+
speeds.push(speed);
|
|
34
|
+
if (speeds.length > 10) speeds.shift();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const avgSpeed = speeds.length > 0 ? Math.round(speeds.reduce((a, b) => a + b, 0) / speeds.length) : 0;
|
|
38
|
+
const eta = avgSpeed > 0 && totalBytes > bytesDownloaded ? Math.round((totalBytes - bytesDownloaded) / avgSpeed) : 0;
|
|
39
|
+
|
|
40
|
+
if (onProgress) {
|
|
41
|
+
onProgress({
|
|
42
|
+
bytesDownloaded,
|
|
43
|
+
bytesRemaining: Math.max(0, totalBytes - bytesDownloaded),
|
|
44
|
+
totalBytes,
|
|
45
|
+
downloadSpeed: avgSpeed,
|
|
46
|
+
eta,
|
|
47
|
+
retryCount,
|
|
48
|
+
currentGateway: url,
|
|
49
|
+
status: bytesDownloaded >= totalBytes ? 'completed' : 'downloading',
|
|
50
|
+
percentComplete: totalBytes > 0 ? Math.round((bytesDownloaded / totalBytes) * 100) : 0,
|
|
51
|
+
timestamp: now
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
lastProgressTime = now;
|
|
56
|
+
lastProgressBytes = bytesDownloaded;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const dir = path.dirname(destination);
|
|
61
|
+
if (!fs.existsSync(dir)) {
|
|
62
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const attemptDownload = (gateway) => {
|
|
66
|
+
if (onProgress) {
|
|
67
|
+
onProgress({
|
|
68
|
+
bytesDownloaded: 0,
|
|
69
|
+
bytesRemaining: 0,
|
|
70
|
+
totalBytes: 0,
|
|
71
|
+
downloadSpeed: 0,
|
|
72
|
+
eta: 0,
|
|
73
|
+
retryCount,
|
|
74
|
+
currentGateway: gateway,
|
|
75
|
+
status: 'connecting',
|
|
76
|
+
percentComplete: 0,
|
|
77
|
+
timestamp: Date.now()
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
https.get(gateway, { timeout: 30000 }, (res) => {
|
|
82
|
+
if ([301, 302, 307, 308].includes(res.statusCode)) {
|
|
83
|
+
const location = res.headers.location;
|
|
84
|
+
if (location) return attemptDownload(location);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (res.statusCode !== 200) {
|
|
88
|
+
res.resume();
|
|
89
|
+
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
90
|
+
retryCount++;
|
|
91
|
+
gatewayIndex++;
|
|
92
|
+
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
93
|
+
}
|
|
94
|
+
return reject(new Error(`HTTP ${res.statusCode}`));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
totalBytes = parseInt(res.headers['content-length'], 10) || 0;
|
|
98
|
+
bytesDownloaded = 0;
|
|
99
|
+
lastProgressBytes = 0;
|
|
100
|
+
lastProgressTime = Date.now();
|
|
101
|
+
|
|
102
|
+
const file = fs.createWriteStream(destination);
|
|
103
|
+
let lastEmit = Date.now();
|
|
104
|
+
|
|
105
|
+
res.on('data', (chunk) => {
|
|
106
|
+
bytesDownloaded += chunk.length;
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
if (now - lastEmit >= 200) {
|
|
109
|
+
emitProgress();
|
|
110
|
+
lastEmit = now;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
res.on('end', () => {
|
|
115
|
+
emitProgress();
|
|
116
|
+
file.destroy();
|
|
117
|
+
resolve({ destination, bytesDownloaded, success: true });
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
res.on('error', (err) => {
|
|
121
|
+
file.destroy();
|
|
122
|
+
fs.unlink(destination, () => {});
|
|
123
|
+
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
124
|
+
retryCount++;
|
|
125
|
+
gatewayIndex++;
|
|
126
|
+
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
127
|
+
}
|
|
128
|
+
reject(err);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
file.on('error', (err) => {
|
|
132
|
+
res.destroy();
|
|
133
|
+
fs.unlink(destination, () => {});
|
|
134
|
+
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
135
|
+
retryCount++;
|
|
136
|
+
gatewayIndex++;
|
|
137
|
+
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
138
|
+
}
|
|
139
|
+
reject(err);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
res.pipe(file);
|
|
143
|
+
}).on('timeout', () => {
|
|
144
|
+
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
145
|
+
retryCount++;
|
|
146
|
+
gatewayIndex++;
|
|
147
|
+
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
148
|
+
}
|
|
149
|
+
reject(new Error('Download timeout'));
|
|
150
|
+
}).on('error', (err) => {
|
|
151
|
+
if (gatewayIndex < GATEWAYS.length - 1) {
|
|
152
|
+
retryCount++;
|
|
153
|
+
gatewayIndex++;
|
|
154
|
+
return setTimeout(() => attemptDownload(GATEWAYS[gatewayIndex]), 1000 * Math.pow(2, Math.min(retryCount, 3)));
|
|
155
|
+
}
|
|
156
|
+
reject(err);
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
attemptDownload(GATEWAYS[0]);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let progressCount = 0;
|
|
165
|
+
let lastPrintTime = Date.now();
|
|
166
|
+
let minInterval = Infinity;
|
|
167
|
+
let maxInterval = 0;
|
|
168
|
+
const progressIntervals = [];
|
|
169
|
+
|
|
170
|
+
console.log('Starting download progress tracking test...\n');
|
|
171
|
+
|
|
172
|
+
downloadWithProgress(
|
|
173
|
+
'https://www.w3.org/WAI/WCAG21/Techniques/pdf/pdf-files/table-example.pdf',
|
|
174
|
+
path.join(testDir, 'test-file.pdf'),
|
|
175
|
+
(progress) => {
|
|
176
|
+
progressCount++;
|
|
177
|
+
const now = Date.now();
|
|
178
|
+
const interval = now - lastPrintTime;
|
|
179
|
+
|
|
180
|
+
if (progressCount > 1) {
|
|
181
|
+
progressIntervals.push(interval);
|
|
182
|
+
minInterval = Math.min(minInterval, interval);
|
|
183
|
+
maxInterval = Math.max(maxInterval, interval);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
console.log(`[${progressCount}] Progress Update:
|
|
187
|
+
Status: ${progress.status}
|
|
188
|
+
Downloaded: ${(progress.bytesDownloaded / 1024).toFixed(1)}KB / ${(progress.totalBytes / 1024).toFixed(1)}KB
|
|
189
|
+
Speed: ${(progress.downloadSpeed / 1024).toFixed(2)}MB/s
|
|
190
|
+
ETA: ${progress.eta}s
|
|
191
|
+
Complete: ${progress.percentComplete}%
|
|
192
|
+
Retry Count: ${progress.retryCount}
|
|
193
|
+
Gateway: ${progress.currentGateway}
|
|
194
|
+
Interval: ${interval}ms\n`);
|
|
195
|
+
|
|
196
|
+
lastPrintTime = now;
|
|
197
|
+
}
|
|
198
|
+
).then((result) => {
|
|
199
|
+
const avgInterval = progressIntervals.length > 0 ? progressIntervals.reduce((a, b) => a + b, 0) / progressIntervals.length : 0;
|
|
200
|
+
console.log('\n=== Download Complete ===');
|
|
201
|
+
console.log(`Result: ${JSON.stringify(result, null, 2)}`);
|
|
202
|
+
console.log(`\nProgress Tracking Statistics:
|
|
203
|
+
Total Updates: ${progressCount}
|
|
204
|
+
Interval Range: ${minInterval}ms - ${maxInterval}ms
|
|
205
|
+
Average Interval: ${avgInterval.toFixed(0)}ms
|
|
206
|
+
Expected Interval: 200ms (should be 100-500ms range)`);
|
|
207
|
+
|
|
208
|
+
if (avgInterval >= 100 && avgInterval <= 500) {
|
|
209
|
+
console.log(' Status: PASS - Progress interval within acceptable range');
|
|
210
|
+
} else {
|
|
211
|
+
console.log(' Status: FAIL - Progress interval outside acceptable range');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (fs.existsSync(path.join(testDir, 'test-file.pdf'))) {
|
|
215
|
+
const stat = fs.statSync(path.join(testDir, 'test-file.pdf'));
|
|
216
|
+
console.log(`\nDownloaded file size: ${(stat.size / 1024).toFixed(1)}KB`);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
process.exit(0);
|
|
220
|
+
}).catch((err) => {
|
|
221
|
+
console.error('Download failed:', err.message);
|
|
222
|
+
process.exit(1);
|
|
223
|
+
});
|