mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02: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 {Agent as HttpsAgent} from 'https';
|
||||
// import roundRobin from '@derhuerst/round-robin-scheduler';
|
||||
import {randomBytes} from 'crypto';
|
||||
import {stringify} from 'qs';
|
||||
import {Request, fetch} from 'cross-fetch';
|
||||
import {parse as parseContentType} from 'content-type';
|
||||
|
@ -58,6 +57,14 @@ import {HafasError} from './errors.js';
|
|||
// 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 {
|
||||
body,
|
||||
|
@ -122,8 +129,7 @@ const request = async (ctx, userAgent, reqData) => {
|
|||
if (reqOptions.query) {
|
||||
url += '?' + stringify(reqOptions.query, {arrayFormat: 'brackets', encodeValuesOnly: true});
|
||||
}
|
||||
const reqId = randomBytes(3)
|
||||
.toString('hex');
|
||||
const reqId = randomBytesHex(3);
|
||||
const fetchReq = new Request(url, reqOptions);
|
||||
profile.logRequest(ctx, fetchReq, reqId);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue