mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-02-07 22:18:31 -06:00
30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
const roundSpeed = (bandwidth) => {
|
|
return Math.round(bandwidth / 1250) / 100;
|
|
}
|
|
|
|
module.exports.parseOokla = (test) => {
|
|
let ping = Math.round(test.ping.latency);
|
|
let download = roundSpeed(test.download.bandwidth);
|
|
let upload = roundSpeed(test.upload.bandwidth);
|
|
let time = Math.round((test.download.elapsed + test.upload.elapsed) / 1000);
|
|
|
|
return {ping, download, upload, time, resultId: test.result?.id};
|
|
}
|
|
|
|
module.exports.parseLibre = (test) => ({...test, ping: Math.round(test.ping), time: Math.round(test.elapsed / 1000),
|
|
resultId: null});
|
|
|
|
module.exports.parseCloudflare = (test) => ({...test, time: Math.round(test.elapsed), resultId: null});
|
|
|
|
module.exports.parseData = (provider, data) => {
|
|
switch (provider) {
|
|
case "ookla":
|
|
return this.parseOokla(data);
|
|
case "libre":
|
|
return this.parseLibre(data);
|
|
case "cloudflare":
|
|
return this.parseCloudflare(data);
|
|
default:
|
|
throw {message: "Invalid provider"};
|
|
}
|
|
} |