mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
replaced node crypto with web crypto
This commit is contained in:
parent
f7909aac29
commit
46e21f8d75
1 changed files with 9 additions and 3 deletions
|
@ -2,7 +2,6 @@
|
||||||
// import {isIP} from 'net';
|
// import {isIP} from 'net';
|
||||||
// import {Agent as HttpsAgent} from 'https';
|
// import {Agent as HttpsAgent} from 'https';
|
||||||
// import roundRobin from '@derhuerst/round-robin-scheduler';
|
// import roundRobin from '@derhuerst/round-robin-scheduler';
|
||||||
import {randomBytes} from 'crypto';
|
|
||||||
import {stringify} from 'qs';
|
import {stringify} from 'qs';
|
||||||
import {Request, fetch} from 'cross-fetch';
|
import {Request, fetch} from 'cross-fetch';
|
||||||
import {parse as parseContentType} from 'content-type';
|
import {parse as parseContentType} from 'content-type';
|
||||||
|
@ -58,6 +57,14 @@ import {HafasError} from './errors.js';
|
||||||
// return ua;
|
// return ua;
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
const randomBytesHex = (nBytes = 8) => {
|
||||||
|
const array = new Uint8Array(nBytes);
|
||||||
|
crypto.getRandomValues(array);
|
||||||
|
return Array.from(array)
|
||||||
|
.map((byte) => byte.toString(16).padStart(2, '0'))
|
||||||
|
.join('');
|
||||||
|
};
|
||||||
|
|
||||||
const checkIfResponseIsOk = (_) => {
|
const checkIfResponseIsOk = (_) => {
|
||||||
const {
|
const {
|
||||||
body,
|
body,
|
||||||
|
@ -122,8 +129,7 @@ const request = async (ctx, userAgent, reqData) => {
|
||||||
if (reqOptions.query) {
|
if (reqOptions.query) {
|
||||||
url += '?' + stringify(reqOptions.query, {arrayFormat: 'brackets', encodeValuesOnly: true});
|
url += '?' + stringify(reqOptions.query, {arrayFormat: 'brackets', encodeValuesOnly: true});
|
||||||
}
|
}
|
||||||
const reqId = randomBytes(3)
|
const reqId = randomBytesHex(3);
|
||||||
.toString('hex');
|
|
||||||
const fetchReq = new Request(url, reqOptions);
|
const fetchReq = new Request(url, reqOptions);
|
||||||
profile.logRequest(ctx, fetchReq, reqId);
|
profile.logRequest(ctx, fetchReq, reqId);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue