@qodalis/cli-speed-test 0.0.4 → 2.0.0-beta.10
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/package.json +16 -32
- package/public-api.d.mts +33 -0
- package/public-api.d.ts +33 -2
- package/public-api.js +283 -0
- package/public-api.js.map +1 -0
- package/public-api.mjs +280 -0
- package/public-api.mjs.map +1 -0
- package/umd/index.global.js +2956 -0
- package/README.md +0 -17
- package/esm2022/lib/cli-speed-test.module.mjs +0 -19
- package/esm2022/lib/processors/cli-speed-test-command-processor.mjs +0 -169
- package/esm2022/lib/version.mjs +0 -3
- package/esm2022/public-api.mjs +0 -6
- package/esm2022/qodalis-cli-speed-test.mjs +0 -5
- package/fesm2022/qodalis-cli-speed-test.mjs +0 -200
- package/fesm2022/qodalis-cli-speed-test.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/cli-speed-test.module.d.ts +0 -6
- package/lib/processors/cli-speed-test-command-processor.d.ts +0 -23
- package/lib/version.d.ts +0 -1
- package/umd/index.js +0 -182
package/umd/index.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('@qodalis/cli-core'), require('axios')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['@qodalis/cli-core', 'axios'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.cliCore, global.axios));
|
|
5
|
-
})(this, (function (cliCore, axios) { 'use strict';
|
|
6
|
-
|
|
7
|
-
// Automatically generated during build
|
|
8
|
-
const LIBRARY_VERSION = '0.0.4';
|
|
9
|
-
|
|
10
|
-
class CliSpeedTestCommandProcessor {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.command = 'speed-test';
|
|
13
|
-
this.description = 'Run an internet speed test';
|
|
14
|
-
this.author = cliCore.DefaultLibraryAuthor;
|
|
15
|
-
this.processors = [];
|
|
16
|
-
this.version = LIBRARY_VERSION;
|
|
17
|
-
this.metadata = {
|
|
18
|
-
icon: '🚀',
|
|
19
|
-
requiredCoreVersion: '0.0.16',
|
|
20
|
-
requiredCliVersion: '1.0.37',
|
|
21
|
-
};
|
|
22
|
-
this.processors = [
|
|
23
|
-
{
|
|
24
|
-
command: 'run',
|
|
25
|
-
description: 'Run the internet speed test',
|
|
26
|
-
parameters: [
|
|
27
|
-
{
|
|
28
|
-
name: 'download-url',
|
|
29
|
-
description: 'URL to download the file',
|
|
30
|
-
type: 'string',
|
|
31
|
-
required: false,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'upload-url',
|
|
35
|
-
description: 'URL to upload the file',
|
|
36
|
-
type: 'string',
|
|
37
|
-
required: false,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
processCommand: async (command, context) => {
|
|
41
|
-
const source = axios.CancelToken.source();
|
|
42
|
-
const subscription = context.onAbort.subscribe(() => {
|
|
43
|
-
source.cancel('Speed test aborted by user');
|
|
44
|
-
subscription.unsubscribe();
|
|
45
|
-
});
|
|
46
|
-
new Promise(async (resolve, reject) => {
|
|
47
|
-
context.writer.writeInfo('Starting live speed test...');
|
|
48
|
-
const downloadUrl = command.args['download-url'] ||
|
|
49
|
-
'https://proxy.qodalis.com/proxy/https/nbg1-speed.hetzner.com/100MB.bin';
|
|
50
|
-
const uploadUrl = command.args['upload-url'] ||
|
|
51
|
-
'https://httpbin.org/post';
|
|
52
|
-
try {
|
|
53
|
-
await this.runDownloadSpeedTest(downloadUrl, context, source.token);
|
|
54
|
-
await this.runUploadSpeedTest(uploadUrl, context, source);
|
|
55
|
-
context.writer.writeInfo('Speed test completed');
|
|
56
|
-
resolve();
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
context.writer.writeError(`Speed test failed: ${error?.toString()}`);
|
|
60
|
-
reject(error);
|
|
61
|
-
}
|
|
62
|
-
subscription.unsubscribe();
|
|
63
|
-
context.showPrompt();
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
}
|
|
69
|
-
async processCommand(command, context) {
|
|
70
|
-
await context.executor.showHelp(command, context);
|
|
71
|
-
}
|
|
72
|
-
writeDescription(context) {
|
|
73
|
-
const { writer } = context;
|
|
74
|
-
writer.writeln(this.description);
|
|
75
|
-
writer.writeln();
|
|
76
|
-
writer.writeln('📋 Usage:');
|
|
77
|
-
writer.writeln(` ${writer.wrapInColor('speed-test run', cliCore.CliForegroundColor.Cyan)} Run download & upload test`);
|
|
78
|
-
writer.writeln(` ${writer.wrapInColor('speed-test run --download-url=<url>', cliCore.CliForegroundColor.Cyan)} Custom download URL`);
|
|
79
|
-
writer.writeln(` ${writer.wrapInColor('speed-test run --upload-url=<url>', cliCore.CliForegroundColor.Cyan)} Custom upload URL`);
|
|
80
|
-
writer.writeln();
|
|
81
|
-
writer.writeln(`💡 Press ${writer.wrapInColor('Ctrl+C', cliCore.CliForegroundColor.Yellow)} to abort the test`);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Run the download speed test with live updates.
|
|
85
|
-
* @param context CLI execution context.
|
|
86
|
-
*/
|
|
87
|
-
async runDownloadSpeedTest(url, context, cancelToken) {
|
|
88
|
-
const startTime = performance.now();
|
|
89
|
-
let previousTime = startTime;
|
|
90
|
-
let previousLoaded = 0;
|
|
91
|
-
await axios.get(url, {
|
|
92
|
-
responseType: 'arraybuffer',
|
|
93
|
-
cancelToken: cancelToken,
|
|
94
|
-
headers: {
|
|
95
|
-
Origin: null,
|
|
96
|
-
},
|
|
97
|
-
onDownloadProgress: (progressEvent) => {
|
|
98
|
-
if (!!cancelToken.reason) {
|
|
99
|
-
throw new Error('Speed test aborted by user');
|
|
100
|
-
}
|
|
101
|
-
const currentTime = performance.now();
|
|
102
|
-
const elapsedTime = (currentTime - previousTime) / 1000;
|
|
103
|
-
const bytesSinceLastUpdate = progressEvent.loaded - previousLoaded;
|
|
104
|
-
if (elapsedTime > 0) {
|
|
105
|
-
const speedInBps = bytesSinceLastUpdate / elapsedTime; // Bytes per second
|
|
106
|
-
const speedInMbps = (speedInBps * 8) / (1024 * 1024); // Convert to Mbps
|
|
107
|
-
context.writer.writeln(`Download Speed: ${speedInMbps.toFixed(2)} Mbps (Progress: ${((progressEvent.loaded / progressEvent.total) *
|
|
108
|
-
100).toFixed(2)}%)`);
|
|
109
|
-
}
|
|
110
|
-
// Update previous values
|
|
111
|
-
previousTime = currentTime;
|
|
112
|
-
previousLoaded = progressEvent.loaded;
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
const endTime = performance.now();
|
|
116
|
-
const totalTime = (endTime - startTime) / 1000;
|
|
117
|
-
context.writer.writeSuccess(`Download test completed in ${totalTime.toFixed(2)} seconds`);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Run the upload speed test with live updates.
|
|
121
|
-
* @param context CLI execution context.
|
|
122
|
-
*/
|
|
123
|
-
async runUploadSpeedTest(url, context, source) {
|
|
124
|
-
const testData = new Uint8Array(20 * 1024 * 1024); // 20 MB of random data
|
|
125
|
-
testData.fill(0);
|
|
126
|
-
const startTime = performance.now();
|
|
127
|
-
let previousTime = startTime;
|
|
128
|
-
let previousUploaded = 0;
|
|
129
|
-
let uploadComplete = false;
|
|
130
|
-
try {
|
|
131
|
-
await axios.post(url, testData, {
|
|
132
|
-
headers: { 'Content-Type': 'application/octet-stream' },
|
|
133
|
-
cancelToken: source.token,
|
|
134
|
-
responseType: 'stream',
|
|
135
|
-
onUploadProgress: (progressEvent) => {
|
|
136
|
-
if (!!source.token.reason) {
|
|
137
|
-
throw new Error('Speed test aborted by user');
|
|
138
|
-
}
|
|
139
|
-
const currentTime = performance.now();
|
|
140
|
-
const elapsedTime = (currentTime - previousTime) / 1000; // Time since last update
|
|
141
|
-
const bytesSinceLastUpdate = progressEvent.loaded - previousUploaded;
|
|
142
|
-
if (elapsedTime > 0) {
|
|
143
|
-
const speedInBps = bytesSinceLastUpdate / elapsedTime; // Bytes per second
|
|
144
|
-
const speedInMbps = (speedInBps * 8) / (1024 * 1024); // Convert to Mbps
|
|
145
|
-
context.writer.writeln(`Upload Speed: ${speedInMbps.toFixed(2)} Mbps (Progress: ${((progressEvent.loaded / progressEvent.total) *
|
|
146
|
-
100).toFixed(2)}%)`);
|
|
147
|
-
}
|
|
148
|
-
// Update previous values
|
|
149
|
-
previousTime = currentTime;
|
|
150
|
-
previousUploaded = progressEvent.loaded;
|
|
151
|
-
if (progressEvent.loaded >= progressEvent.total) {
|
|
152
|
-
uploadComplete = true;
|
|
153
|
-
source.cancel('Upload test completed');
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
catch (e) {
|
|
159
|
-
if (axios.isCancel(e)) {
|
|
160
|
-
if (!uploadComplete) {
|
|
161
|
-
context.writer.writeError('Upload test aborted by user');
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
const endTime = performance.now();
|
|
165
|
-
const totalTime = (endTime - startTime) / 1000;
|
|
166
|
-
context.writer.writeSuccess(`Upload test completed in ${totalTime.toFixed(2)} seconds`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
throw e;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const module = {
|
|
177
|
-
name: '@qodalis/cli-speed-test',
|
|
178
|
-
processors: [new CliSpeedTestCommandProcessor()],
|
|
179
|
-
};
|
|
180
|
-
cliCore.bootUmdModule(module);
|
|
181
|
-
|
|
182
|
-
}));
|