gologin-commonjs 3.0.2 → 3.0.3
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/dist/fonts_config +104 -0
- package/dist/gologin-browser-ext.zip +0 -0
- package/dist/gologin_zeroprofile.b64 +1 -0
- package/dist/src/browser/browser-user-data-manager.js +140 -230
- package/dist/src/gologin.js +372 -734
- package/dist/zero_profile.zip +0 -0
- package/gologin/index.d.ts +18 -18
- package/package.json +5 -5
- package/types/example.d.ts +1 -0
- package/types/examples/example-amazon-cloud-browser.d.ts +1 -0
- package/types/examples/example-amazon-headless.d.ts +1 -0
- package/types/examples/example-amazon.d.ts +1 -0
- package/types/examples/example-create-custom-profile.d.ts +1 -0
- package/types/examples/example-create-profile.d.ts +1 -0
- package/types/examples/example-custom-args.d.ts +1 -0
- package/types/examples/example-fast-profile-settings.d.ts +1 -0
- package/types/examples/example-gmail.d.ts +1 -0
- package/types/examples/example-iphey.d.ts +1 -0
- package/types/examples/example-local-profile.d.ts +1 -0
- package/types/examples/example-login-walmart.d.ts +1 -0
- package/types/examples/example-stopremote.d.ts +1 -0
- package/types/examples/example-timezone.d.ts +1 -0
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
4
|
+
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.uploadCookies =
|
|
7
|
-
exports.setOriginalExtPaths =
|
|
8
|
-
exports.setExtPathsAndRemoveDeleted =
|
|
9
|
-
exports.recalculateId =
|
|
10
|
-
exports.downloadFonts =
|
|
11
|
-
exports.downloadCookies =
|
|
12
|
-
exports.copyFontsConfigFile =
|
|
13
|
-
exports.composeFonts =
|
|
14
|
-
void 0;
|
|
6
|
+
exports.uploadCookies = exports.setOriginalExtPaths = exports.setExtPathsAndRemoveDeleted = exports.recalculateId = exports.downloadFonts = exports.downloadCookies = exports.copyFontsConfigFile = exports.composeFonts = void 0;
|
|
15
7
|
var _crypto = require("crypto");
|
|
16
8
|
var _fs = require("fs");
|
|
17
9
|
var _os = require("os");
|
|
@@ -19,69 +11,65 @@ var _path = require("path");
|
|
|
19
11
|
var _requestretry = _interopRequireDefault(require("requestretry"));
|
|
20
12
|
var _url = require("url");
|
|
21
13
|
var _fonts = require("../../fonts.js");
|
|
22
|
-
function _interopRequireDefault(e) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const {
|
|
16
|
+
access,
|
|
17
|
+
readFile,
|
|
18
|
+
writeFile,
|
|
19
|
+
mkdir,
|
|
20
|
+
readdir,
|
|
21
|
+
copyFile,
|
|
22
|
+
rename
|
|
23
|
+
} = _fs.promises;
|
|
24
|
+
const _filename = (0, _url.fileURLToPath)(require('url').pathToFileURL(_filename).toString());
|
|
30
25
|
const _dirname = (0, _path.dirname)(_filename);
|
|
31
|
-
const FONTS_URL =
|
|
32
|
-
const FONTS_DIR_NAME =
|
|
26
|
+
const FONTS_URL = 'https://fonts.gologin.com/';
|
|
27
|
+
const FONTS_DIR_NAME = 'fonts';
|
|
33
28
|
const HOMEDIR = (0, _os.homedir)();
|
|
34
|
-
const BROWSER_PATH = (0, _path.join)(HOMEDIR,
|
|
29
|
+
const BROWSER_PATH = (0, _path.join)(HOMEDIR, '.gologin', 'browser');
|
|
35
30
|
const OS_PLATFORM = process.platform;
|
|
36
|
-
const DEFAULT_ORBITA_EXTENSIONS_NAMES = [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"CryptoTokenExtension",
|
|
40
|
-
"Web Store",
|
|
41
|
-
];
|
|
42
|
-
const GOLOGIN_BASE_FOLDER_NAME = ".gologin";
|
|
43
|
-
const GOLOGIN_TEST_FOLDER_NAME = ".gologin_test";
|
|
31
|
+
const DEFAULT_ORBITA_EXTENSIONS_NAMES = ['Google Hangouts', 'Chromium PDF Viewer', 'CryptoTokenExtension', 'Web Store'];
|
|
32
|
+
const GOLOGIN_BASE_FOLDER_NAME = '.gologin';
|
|
33
|
+
const GOLOGIN_TEST_FOLDER_NAME = '.gologin_test';
|
|
44
34
|
const osPlatform = process.platform;
|
|
45
|
-
const downloadCookies = ({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
35
|
+
const downloadCookies = ({
|
|
36
|
+
profileId,
|
|
37
|
+
ACCESS_TOKEN,
|
|
38
|
+
API_BASE_URL
|
|
39
|
+
}) => _requestretry.default.get(`${API_BASE_URL}/browser/${profileId}/cookies`, {
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
42
|
+
'user-agent': 'gologin-api'
|
|
43
|
+
},
|
|
44
|
+
json: true,
|
|
45
|
+
maxAttempts: 3,
|
|
46
|
+
retryDelay: 2000,
|
|
47
|
+
timeout: 10 * 1000
|
|
48
|
+
}).catch(e => {
|
|
49
|
+
console.log(e);
|
|
50
|
+
return {
|
|
51
|
+
body: []
|
|
52
|
+
};
|
|
53
|
+
});
|
|
63
54
|
exports.downloadCookies = downloadCookies;
|
|
64
55
|
const uploadCookies = ({
|
|
65
56
|
cookies = [],
|
|
66
57
|
profileId,
|
|
67
58
|
ACCESS_TOKEN,
|
|
68
|
-
API_BASE_URL
|
|
69
|
-
}) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
console.log(e);
|
|
83
|
-
return e;
|
|
84
|
-
});
|
|
59
|
+
API_BASE_URL
|
|
60
|
+
}) => _requestretry.default.post(`${API_BASE_URL}/browser/${profileId}/cookies?encrypted=true`, {
|
|
61
|
+
headers: {
|
|
62
|
+
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
63
|
+
'User-Agent': 'gologin-api'
|
|
64
|
+
},
|
|
65
|
+
json: cookies,
|
|
66
|
+
maxAttempts: 3,
|
|
67
|
+
retryDelay: 2000,
|
|
68
|
+
timeout: 20 * 1000
|
|
69
|
+
}).catch(e => {
|
|
70
|
+
console.log(e);
|
|
71
|
+
return e;
|
|
72
|
+
});
|
|
85
73
|
exports.uploadCookies = uploadCookies;
|
|
86
74
|
const downloadFonts = async (fontsList = [], profilePath) => {
|
|
87
75
|
if (!fontsList.length) {
|
|
@@ -89,159 +77,107 @@ const downloadFonts = async (fontsList = [], profilePath) => {
|
|
|
89
77
|
}
|
|
90
78
|
const browserFontsPath = (0, _path.join)(BROWSER_PATH, FONTS_DIR_NAME);
|
|
91
79
|
await mkdir(browserFontsPath, {
|
|
92
|
-
recursive: true
|
|
80
|
+
recursive: true
|
|
93
81
|
});
|
|
94
82
|
const files = await readdir(browserFontsPath);
|
|
95
|
-
const fontsToDownload = fontsList.filter(
|
|
96
|
-
let promises = fontsToDownload.map((font
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
timeout: 30 * 1000,
|
|
102
|
-
})
|
|
103
|
-
.pipe((0, _fs.createWriteStream)((0, _path.join)(browserFontsPath, font)))
|
|
104
|
-
);
|
|
83
|
+
const fontsToDownload = fontsList.filter(font => !files.includes(font));
|
|
84
|
+
let promises = fontsToDownload.map(font => _requestretry.default.get(FONTS_URL + font, {
|
|
85
|
+
maxAttempts: 5,
|
|
86
|
+
retryDelay: 2000,
|
|
87
|
+
timeout: 30 * 1000
|
|
88
|
+
}).pipe((0, _fs.createWriteStream)((0, _path.join)(browserFontsPath, font))));
|
|
105
89
|
if (promises.length) {
|
|
106
90
|
await Promise.all(promises);
|
|
107
91
|
}
|
|
108
|
-
promises = fontsList.map((font)
|
|
109
|
-
copyFile(
|
|
110
|
-
(0, _path.join)(browserFontsPath, font),
|
|
111
|
-
(0, _path.join)(profilePath, FONTS_DIR_NAME, font)
|
|
112
|
-
)
|
|
113
|
-
);
|
|
92
|
+
promises = fontsList.map(font => copyFile((0, _path.join)(browserFontsPath, font), (0, _path.join)(profilePath, FONTS_DIR_NAME, font)));
|
|
114
93
|
await Promise.all(promises);
|
|
115
94
|
};
|
|
116
95
|
exports.downloadFonts = downloadFonts;
|
|
117
|
-
const composeFonts = async (
|
|
118
|
-
fontsList = [],
|
|
119
|
-
profilePath,
|
|
120
|
-
differentOs = false
|
|
121
|
-
) => {
|
|
96
|
+
const composeFonts = async (fontsList = [], profilePath, differentOs = false) => {
|
|
122
97
|
if (!(fontsList.length && profilePath)) {
|
|
123
98
|
return;
|
|
124
99
|
}
|
|
125
|
-
const fontsToDownload = _fonts.fontsCollection
|
|
126
|
-
.filter((elem) => fontsList.includes(elem.value))
|
|
127
|
-
.reduce((res, elem) => res.concat(elem.fileNames || []), []);
|
|
100
|
+
const fontsToDownload = _fonts.fontsCollection.filter(elem => fontsList.includes(elem.value)).reduce((res, elem) => res.concat(elem.fileNames || []), []);
|
|
128
101
|
if (differentOs && !fontsToDownload.length) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
"No fonts to download found. Use getAvailableFonts() method and set some fonts from this list"
|
|
131
|
-
);
|
|
102
|
+
throw new Error('No fonts to download found. Use getAvailableFonts() method and set some fonts from this list');
|
|
132
103
|
}
|
|
133
|
-
fontsToDownload.push(
|
|
134
|
-
fontsToDownload.push(
|
|
104
|
+
fontsToDownload.push('LICENSE.txt');
|
|
105
|
+
fontsToDownload.push('OFL.txt');
|
|
135
106
|
const pathToFontsDir = (0, _path.join)(profilePath, FONTS_DIR_NAME);
|
|
136
|
-
const fontsDirExists = await access(pathToFontsDir).then(
|
|
137
|
-
() => true,
|
|
138
|
-
() => false
|
|
139
|
-
);
|
|
107
|
+
const fontsDirExists = await access(pathToFontsDir).then(() => true, () => false);
|
|
140
108
|
if (fontsDirExists) {
|
|
141
109
|
(0, _fs.rmdirSync)(pathToFontsDir, {
|
|
142
|
-
recursive: true
|
|
110
|
+
recursive: true
|
|
143
111
|
});
|
|
144
112
|
}
|
|
145
113
|
await mkdir(pathToFontsDir, {
|
|
146
|
-
recursive: true
|
|
114
|
+
recursive: true
|
|
147
115
|
});
|
|
148
116
|
await downloadFonts(fontsToDownload, profilePath);
|
|
149
|
-
if (OS_PLATFORM ===
|
|
117
|
+
if (OS_PLATFORM === 'linux') {
|
|
150
118
|
await copyFontsConfigFile(profilePath);
|
|
151
119
|
}
|
|
152
120
|
};
|
|
153
121
|
exports.composeFonts = composeFonts;
|
|
154
|
-
const copyFontsConfigFile = async
|
|
122
|
+
const copyFontsConfigFile = async profilePath => {
|
|
155
123
|
if (!profilePath) {
|
|
156
124
|
return;
|
|
157
125
|
}
|
|
158
|
-
const fileContent = await readFile(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
);
|
|
162
|
-
const result = fileContent.replace(
|
|
163
|
-
/\$\$GOLOGIN_FONTS\$\$/g,
|
|
164
|
-
(0, _path.join)(profilePath, FONTS_DIR_NAME)
|
|
165
|
-
);
|
|
166
|
-
const defaultFolderPath = (0, _path.join)(profilePath, "Default");
|
|
126
|
+
const fileContent = await readFile((0, _path.resolve)(_dirname, '..', '..', 'fonts_config'), 'utf-8');
|
|
127
|
+
const result = fileContent.replace(/\$\$GOLOGIN_FONTS\$\$/g, (0, _path.join)(profilePath, FONTS_DIR_NAME));
|
|
128
|
+
const defaultFolderPath = (0, _path.join)(profilePath, 'Default');
|
|
167
129
|
await mkdir(defaultFolderPath, {
|
|
168
|
-
recursive: true
|
|
130
|
+
recursive: true
|
|
169
131
|
});
|
|
170
|
-
await writeFile((0, _path.join)(defaultFolderPath,
|
|
132
|
+
await writeFile((0, _path.join)(defaultFolderPath, 'fonts_config'), result);
|
|
171
133
|
};
|
|
172
134
|
exports.copyFontsConfigFile = copyFontsConfigFile;
|
|
173
|
-
const setExtPathsAndRemoveDeleted = (
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
path: el,
|
|
187
|
-
originalId,
|
|
188
|
-
};
|
|
189
|
-
})
|
|
190
|
-
.filter(Boolean);
|
|
135
|
+
const setExtPathsAndRemoveDeleted = (settings = {}, profileExtensionsCheckRes = [], profileId = '') => {
|
|
136
|
+
const formattedLocalExtArray = profileExtensionsCheckRes.map(el => {
|
|
137
|
+
const [extFolderName = ''] = el.split(_path.sep).reverse();
|
|
138
|
+
const [originalId] = extFolderName.split('@');
|
|
139
|
+
if (!originalId) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
path: el,
|
|
144
|
+
originalId
|
|
145
|
+
};
|
|
146
|
+
}).filter(Boolean);
|
|
191
147
|
const extensionsSettings = settings.extensions?.settings || {};
|
|
192
148
|
const extensionsEntries = Object.entries(extensionsSettings);
|
|
193
|
-
const promises = extensionsEntries.map(async
|
|
149
|
+
const promises = extensionsEntries.map(async extensionObj => {
|
|
194
150
|
let [extensionId, currentExtSettings = {}] = extensionObj;
|
|
195
|
-
const extName = currentExtSettings.manifest?.name ||
|
|
196
|
-
let extPath = currentExtSettings.path ||
|
|
197
|
-
let originalId =
|
|
198
|
-
const isExtensionToBeDeleted =
|
|
199
|
-
(["resources", "passwords-ext", "cookies-ext"].some((substring) =>
|
|
200
|
-
extPath.includes(substring)
|
|
201
|
-
) &&
|
|
202
|
-
[GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some((substring) =>
|
|
203
|
-
extPath.includes(substring)
|
|
204
|
-
)) ||
|
|
205
|
-
(DEFAULT_ORBITA_EXTENSIONS_NAMES.includes(extName) &&
|
|
206
|
-
[GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some((substring) =>
|
|
207
|
-
extPath.includes(substring)
|
|
208
|
-
));
|
|
151
|
+
const extName = currentExtSettings.manifest?.name || '';
|
|
152
|
+
let extPath = currentExtSettings.path || '';
|
|
153
|
+
let originalId = '';
|
|
154
|
+
const isExtensionToBeDeleted = ['resources', 'passwords-ext', 'cookies-ext'].some(substring => extPath.includes(substring)) && [GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some(substring => extPath.includes(substring)) || DEFAULT_ORBITA_EXTENSIONS_NAMES.includes(extName) && [GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some(substring => extPath.includes(substring));
|
|
209
155
|
if (isExtensionToBeDeleted) {
|
|
210
156
|
delete extensionsSettings[extensionId];
|
|
211
157
|
return;
|
|
212
158
|
}
|
|
213
|
-
if (osPlatform ===
|
|
214
|
-
extPath = extPath.replace(/\//g,
|
|
159
|
+
if (osPlatform === 'win32') {
|
|
160
|
+
extPath = extPath.replace(/\//g, '\\');
|
|
215
161
|
} else {
|
|
216
|
-
extPath = extPath.replace(/\\/g,
|
|
162
|
+
extPath = extPath.replace(/\\/g, '/');
|
|
217
163
|
}
|
|
218
164
|
extensionsSettings[extensionId].path = extPath;
|
|
219
165
|
const splittedPath = extPath.split(_path.sep);
|
|
220
|
-
const isExtensionManageable =
|
|
221
|
-
["chrome-extensions", "user-extensions"].some((substring) =>
|
|
222
|
-
extPath.includes(substring)
|
|
223
|
-
) &&
|
|
224
|
-
[GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some((substring) =>
|
|
225
|
-
extPath.includes(substring)
|
|
226
|
-
);
|
|
166
|
+
const isExtensionManageable = ['chrome-extensions', 'user-extensions'].some(substring => extPath.includes(substring)) && [GOLOGIN_BASE_FOLDER_NAME, GOLOGIN_TEST_FOLDER_NAME].some(substring => extPath.includes(substring));
|
|
227
167
|
if (isExtensionManageable) {
|
|
228
168
|
const [extFolderName] = extPath.split(_path.sep).reverse();
|
|
229
|
-
[originalId] = extFolderName.split(
|
|
169
|
+
[originalId] = extFolderName.split('@');
|
|
230
170
|
} else if (splittedPath.length === 2) {
|
|
231
171
|
[originalId] = splittedPath;
|
|
232
172
|
}
|
|
233
173
|
if (isExtensionManageable || splittedPath.length === 2) {
|
|
234
|
-
const isExtensionInProfileSettings = formattedLocalExtArray.find(
|
|
235
|
-
el.path.includes(originalId)
|
|
236
|
-
);
|
|
174
|
+
const isExtensionInProfileSettings = formattedLocalExtArray.find(el => el.path.includes(originalId));
|
|
237
175
|
if (!isExtensionInProfileSettings) {
|
|
238
176
|
delete extensionsSettings[extensionId];
|
|
239
177
|
return;
|
|
240
178
|
}
|
|
241
179
|
}
|
|
242
|
-
const localExtObj =
|
|
243
|
-
originalId &&
|
|
244
|
-
formattedLocalExtArray.find((el) => el.path.includes(originalId));
|
|
180
|
+
const localExtObj = originalId && formattedLocalExtArray.find(el => el.path.includes(originalId));
|
|
245
181
|
if (!localExtObj) {
|
|
246
182
|
return;
|
|
247
183
|
}
|
|
@@ -250,82 +186,62 @@ const setExtPathsAndRemoveDeleted = (
|
|
|
250
186
|
localExtObj,
|
|
251
187
|
extensionId,
|
|
252
188
|
extensionsSettings,
|
|
253
|
-
currentExtSettings
|
|
189
|
+
currentExtSettings
|
|
254
190
|
});
|
|
255
191
|
if (initialExtName !== extensionId) {
|
|
256
|
-
const profilePath = (0, _path.join)(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
);
|
|
260
|
-
const extSyncFolder = (0, _path.join)(
|
|
261
|
-
profilePath,
|
|
262
|
-
"Default",
|
|
263
|
-
"Sync Extension Settings",
|
|
264
|
-
initialExtName
|
|
265
|
-
);
|
|
266
|
-
const newSyncFolder = (0, _path.join)(
|
|
267
|
-
profilePath,
|
|
268
|
-
"Default",
|
|
269
|
-
"Sync Extension Settings",
|
|
270
|
-
extensionId
|
|
271
|
-
);
|
|
192
|
+
const profilePath = (0, _path.join)((0, _os.tmpdir)(), `gologin_profile_${profileId}`);
|
|
193
|
+
const extSyncFolder = (0, _path.join)(profilePath, 'Default', 'Sync Extension Settings', initialExtName);
|
|
194
|
+
const newSyncFolder = (0, _path.join)(profilePath, 'Default', 'Sync Extension Settings', extensionId);
|
|
272
195
|
await rename(extSyncFolder, newSyncFolder).catch(() => null);
|
|
273
196
|
}
|
|
274
|
-
if (localExtObj.path.endsWith(
|
|
275
|
-
localExtObj.path = localExtObj.path.replace(
|
|
197
|
+
if (localExtObj.path.endsWith('.zip')) {
|
|
198
|
+
localExtObj.path = localExtObj.path.replace('.zip', '');
|
|
276
199
|
}
|
|
277
|
-
extensionsSettings[extensionId].path = localExtObj.path ||
|
|
200
|
+
extensionsSettings[extensionId].path = localExtObj.path || '';
|
|
278
201
|
});
|
|
279
202
|
return Promise.all(promises).then(() => extensionsSettings);
|
|
280
203
|
};
|
|
281
204
|
exports.setExtPathsAndRemoveDeleted = setExtPathsAndRemoveDeleted;
|
|
282
|
-
const setOriginalExtPaths = async (
|
|
283
|
-
settings = {},
|
|
284
|
-
originalExtensionsFolder = ""
|
|
285
|
-
) => {
|
|
205
|
+
const setOriginalExtPaths = async (settings = {}, originalExtensionsFolder = '') => {
|
|
286
206
|
if (!originalExtensionsFolder) {
|
|
287
207
|
return null;
|
|
288
208
|
}
|
|
289
209
|
const extensionsSettings = settings.extensions?.settings || {};
|
|
290
210
|
const extensionsEntries = Object.entries(extensionsSettings);
|
|
291
|
-
const originalExtensionsList = await readdir(originalExtensionsFolder).catch(
|
|
292
|
-
() => []
|
|
293
|
-
);
|
|
211
|
+
const originalExtensionsList = await readdir(originalExtensionsFolder).catch(() => []);
|
|
294
212
|
if (!originalExtensionsList.length) {
|
|
295
213
|
return null;
|
|
296
214
|
}
|
|
297
|
-
const promises = originalExtensionsList.map(async
|
|
215
|
+
const promises = originalExtensionsList.map(async originalId => {
|
|
298
216
|
const extFolderPath = (0, _path.join)(originalExtensionsFolder, originalId);
|
|
299
217
|
const extFolderContent = await readdir(extFolderPath);
|
|
300
218
|
if (!extFolderPath.length) {
|
|
301
219
|
return {};
|
|
302
220
|
}
|
|
303
|
-
if (extFolderContent.includes(
|
|
221
|
+
if (extFolderContent.includes('manifest.json')) {
|
|
304
222
|
return {
|
|
305
223
|
originalId,
|
|
306
|
-
path: (0, _path.join)(originalExtensionsFolder, originalId)
|
|
224
|
+
path: (0, _path.join)(originalExtensionsFolder, originalId)
|
|
307
225
|
};
|
|
308
226
|
}
|
|
309
227
|
const [version] = extFolderContent;
|
|
310
228
|
return {
|
|
311
229
|
originalId,
|
|
312
|
-
path: (0, _path.join)(originalExtensionsFolder, originalId, version)
|
|
230
|
+
path: (0, _path.join)(originalExtensionsFolder, originalId, version)
|
|
313
231
|
};
|
|
314
232
|
});
|
|
315
233
|
const originalExtPaths = await Promise.all(promises);
|
|
316
|
-
extensionsEntries.forEach(
|
|
234
|
+
extensionsEntries.forEach(extensionObj => {
|
|
317
235
|
const [extensionsId] = extensionObj;
|
|
318
236
|
const extPath = extensionsSettings[extensionsId].path;
|
|
319
237
|
if (!/chrome-extensions/.test(extPath)) {
|
|
320
238
|
return;
|
|
321
239
|
}
|
|
322
|
-
const originalExtPath = originalExtPaths.find(
|
|
323
|
-
(el) => el.originalId === extensionsId
|
|
324
|
-
);
|
|
240
|
+
const originalExtPath = originalExtPaths.find(el => el.originalId === extensionsId);
|
|
325
241
|
if (!originalExtPath) {
|
|
326
242
|
return;
|
|
327
243
|
}
|
|
328
|
-
extensionsSettings[extensionsId].path = originalExtPath.path ||
|
|
244
|
+
extensionsSettings[extensionsId].path = originalExtPath.path || '';
|
|
329
245
|
});
|
|
330
246
|
return extensionsSettings;
|
|
331
247
|
};
|
|
@@ -334,14 +250,14 @@ const recalculateId = async ({
|
|
|
334
250
|
localExtObj,
|
|
335
251
|
extensionId,
|
|
336
252
|
extensionsSettings,
|
|
337
|
-
currentExtSettings
|
|
253
|
+
currentExtSettings
|
|
338
254
|
}) => {
|
|
339
255
|
if (currentExtSettings.manifest?.key) {
|
|
340
256
|
return extensionId;
|
|
341
257
|
}
|
|
342
|
-
const manifestFilePath = (0, _path.join)(localExtObj.path,
|
|
258
|
+
const manifestFilePath = (0, _path.join)(localExtObj.path, 'manifest.json');
|
|
343
259
|
const manifestString = await readFile(manifestFilePath, {
|
|
344
|
-
encoding:
|
|
260
|
+
encoding: 'utf8'
|
|
345
261
|
}).catch(() => ({}));
|
|
346
262
|
if (!manifestString) {
|
|
347
263
|
return extensionId;
|
|
@@ -355,19 +271,13 @@ const recalculateId = async ({
|
|
|
355
271
|
if (manifestObject.key) {
|
|
356
272
|
return extensionId;
|
|
357
273
|
}
|
|
358
|
-
let encoding =
|
|
359
|
-
if (osPlatform ===
|
|
360
|
-
encoding =
|
|
274
|
+
let encoding = 'utf8';
|
|
275
|
+
if (osPlatform === 'win32') {
|
|
276
|
+
encoding = 'utf16le';
|
|
361
277
|
}
|
|
362
278
|
const extPathToEncode = Buffer.from(localExtObj.path, encoding);
|
|
363
|
-
const hexEncodedPath = (0, _crypto.createHash)(
|
|
364
|
-
|
|
365
|
-
.digest("hex");
|
|
366
|
-
const newId = hexEncodedPath
|
|
367
|
-
.split("")
|
|
368
|
-
.slice(0, 32)
|
|
369
|
-
.map((symbol) => extIdEncoding[symbol])
|
|
370
|
-
.join("");
|
|
279
|
+
const hexEncodedPath = (0, _crypto.createHash)('sha256').update(extPathToEncode).digest('hex');
|
|
280
|
+
const newId = hexEncodedPath.split('').slice(0, 32).map(symbol => extIdEncoding[symbol]).join('');
|
|
371
281
|
if (extensionId !== newId) {
|
|
372
282
|
delete extensionsSettings[extensionId];
|
|
373
283
|
extensionsSettings[newId] = currentExtSettings;
|
|
@@ -377,20 +287,20 @@ const recalculateId = async ({
|
|
|
377
287
|
};
|
|
378
288
|
exports.recalculateId = recalculateId;
|
|
379
289
|
const extIdEncoding = {
|
|
380
|
-
0:
|
|
381
|
-
1:
|
|
382
|
-
2:
|
|
383
|
-
3:
|
|
384
|
-
4:
|
|
385
|
-
5:
|
|
386
|
-
6:
|
|
387
|
-
7:
|
|
388
|
-
8:
|
|
389
|
-
9:
|
|
390
|
-
a:
|
|
391
|
-
b:
|
|
392
|
-
c:
|
|
393
|
-
d:
|
|
394
|
-
e:
|
|
395
|
-
f:
|
|
396
|
-
};
|
|
290
|
+
0: 'a',
|
|
291
|
+
1: 'b',
|
|
292
|
+
2: 'c',
|
|
293
|
+
3: 'd',
|
|
294
|
+
4: 'e',
|
|
295
|
+
5: 'f',
|
|
296
|
+
6: 'g',
|
|
297
|
+
7: 'h',
|
|
298
|
+
8: 'i',
|
|
299
|
+
9: 'j',
|
|
300
|
+
a: 'k',
|
|
301
|
+
b: 'l',
|
|
302
|
+
c: 'm',
|
|
303
|
+
d: 'n',
|
|
304
|
+
e: 'o',
|
|
305
|
+
f: 'p'
|
|
306
|
+
};
|