@k03mad/request 1.0.0 → 1.1.1
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/app/lib/request.js +6 -5
- package/package.json +1 -1
package/app/lib/request.js
CHANGED
|
@@ -15,10 +15,11 @@ const debug = _debug('mad:request');
|
|
|
15
15
|
const prepareRequestOpts = (opts = {}) => {
|
|
16
16
|
const UA = 'curl/8.1.2';
|
|
17
17
|
|
|
18
|
-
const preparedOpts = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const preparedOpts = {...opts};
|
|
19
|
+
|
|
20
|
+
if (!preparedOpts.timeout) {
|
|
21
|
+
preparedOpts.timeout = {request: 10_000};
|
|
22
|
+
}
|
|
22
23
|
|
|
23
24
|
if (!preparedOpts.headers) {
|
|
24
25
|
preparedOpts.headers = {'user-agent': UA};
|
|
@@ -105,7 +106,7 @@ export const requestCache = (url, opts = {}, {cacheBy, expire = 43_200} = {}) =>
|
|
|
105
106
|
const {cachedResponse, date} = cache.get(cacheKey);
|
|
106
107
|
|
|
107
108
|
const measurement = 'seconds';
|
|
108
|
-
const currentDiff = (Date.now() - date)
|
|
109
|
+
const currentDiff = Math.round((Date.now() - date) / 1000);
|
|
109
110
|
|
|
110
111
|
if (currentDiff < expire) {
|
|
111
112
|
debug(`${green('FROM CACHE')} :: ${currentDiff}/${expire} ${measurement} left :: ${log}`);
|