Skip to content

Commit de334cb

Browse files
authored
Bug fixes and optimizations (#14)
* test * test * sync * sync * sync * sync * sync * sync * sync * sync * sync * sync * sync * sync * sync * sync * syncing * syncing v2.4.0 changes * sync
1 parent e1d59fd commit de334cb

File tree

11 files changed

+2342
-614
lines changed

11 files changed

+2342
-614
lines changed

.editorconfig

Lines changed: 0 additions & 14 deletions
This file was deleted.

.eslintrc.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
2+
"root": true,
23
"env": {
3-
"browser": false,
4-
"commonjs": true,
54
"es6": true,
65
"node": true
76
},
87
"parserOptions": {
9-
"ecmaVersion": 2017,
8+
"ecmaVersion": 9,
109
"ecmaFeatures": {
1110
"jsx": true
1211
},
@@ -22,5 +21,9 @@
2221
"no-unused-vars": "warn",
2322
"constructor-super": "warn",
2423
"valid-typeof": "warn"
25-
}
26-
}
24+
},
25+
"extends": [
26+
"eslint:recommended",
27+
"prettier"
28+
]
29+
}

alexa-cookie/alexa-cookie.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-prototype-builtins */
12
/* jshint -W097 */
23
/* jshint -W030 */
34
/* jshint strict: false */
@@ -20,7 +21,7 @@ const cookieTools = require('cookie');
2021
const amazonProxy = require('./lib/proxy.js');
2122
const removeRoute = require('express-remove-route');
2223

23-
const defaultAmazonPage = 'amazon.com';
24+
// const defaultAmazonPage = 'amazon.com';
2425
const defaultUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0';
2526
const defaultUserAgentLinux = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36';
2627
//const defaultUserAgentMacOs = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36';

alexa-cookie/lib/proxy.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-prototype-builtins */
12
/* jshint -W097 */
23
/* jshint -W030 */
34
/* jshint strict: false */
@@ -14,46 +15,46 @@ const cookieTools = require('cookie');
1415
let webApp;
1516

1617
function addCookies(Cookie, headers) {
17-
if (!headers || !headers['set-cookie']) return Cookie;
18-
const cookies = cookieTools.parse(Cookie);
19-
for (let cookie of headers['set-cookie']) {
20-
cookie = cookie.match(/^([^=]+)=([^;]+);.*/);
21-
if (cookie && cookie.length === 3) {
22-
if (cookie[1] === 'ap-fid' && cookie[2] === '""') continue;
23-
cookies[cookie[1]] = cookie[2];
18+
if (!headers || !headers['set-cookie']) return Cookie;
19+
const cookies = cookieTools.parse(Cookie);
20+
for (let cookie of headers['set-cookie']) {
21+
cookie = cookie.match(/^([^=]+)=([^;]+);.*/);
22+
if (cookie && cookie.length === 3) {
23+
if (cookie[1] === 'ap-fid' && cookie[2] === '""') continue;
24+
cookies[cookie[1]] = cookie[2];
25+
}
26+
}
27+
Cookie = '';
28+
for (let name in cookies) {
29+
if (!cookies.hasOwnProperty(name)) continue;
30+
Cookie += name + '=' + cookies[name] + '; ';
2431
}
25-
}
26-
Cookie = '';
27-
for (let name in cookies) {
28-
if (!cookies.hasOwnProperty(name)) continue;
29-
Cookie += name + '=' + cookies[name] + '; ';
30-
}
31-
Cookie = Cookie.replace(/[; ]*$/, '');
32-
return Cookie;
32+
Cookie = Cookie.replace(/[; ]*$/, '');
33+
return Cookie;
3334
}
3435

3536
function customStringify(v, func, intent) {
36-
const cache = new Map();
37-
return JSON.stringify(v, function(key, value) {
38-
if (typeof value === 'object' && value !== null) {
39-
if (cache.get(value)) {
40-
// Circular reference found, discard key
41-
return;
42-
}
43-
// Store value in our map
44-
cache.set(value, true);
45-
}
46-
return value;
47-
}, intent);
37+
const cache = new Map();
38+
return JSON.stringify(v, function(key, value) {
39+
if (typeof value === 'object' && value !== null) {
40+
if (cache.get(value)) {
41+
// Circular reference found, discard key
42+
return;
43+
}
44+
// Store value in our map
45+
cache.set(value, true);
46+
}
47+
return value;
48+
}, intent);
4849
}
4950

5051
function initAmazonProxy(_options, webapp, callbackCookie, callbackListening) {
51-
if (webapp) {
52-
webApp = webapp;
53-
}
52+
if (webapp) {
53+
webApp = webapp;
54+
}
5455

55-
const getLocalHost = function(noPort = false) {
56-
return `${(_options.proxyHost || _options.proxyOwnIp)}${(noPort || _options.useHeroku) ? '' : `:${_options.proxyPort}`}`;
56+
const getLocalHost = function(noPort = false) {
57+
return `${(_options.proxyHost || _options.proxyOwnIp)}${(noPort || _options.useHeroku) ? '' : `:${_options.proxyPort}`}`;
5758
};
5859
const initialCookies = {};
5960
if (!_options.formerRegistrationData || !_options.formerRegistrationData.frc) {
@@ -324,4 +325,4 @@ function initAmazonProxy(_options, webapp, callbackCookie, callbackListening) {
324325
}
325326
}
326327

327-
module.exports.initAmazonProxy = initAmazonProxy;
328+
module.exports.initAmazonProxy = initAmazonProxy;

0 commit comments

Comments
 (0)