gologin-commonjs 1.2.6 → 1.2.8

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.
@@ -236,17 +236,23 @@ class BrowserChecker {
236
236
  }
237
237
  return;
238
238
  }
239
- const hashFileContent = await exec(`cat ${(0, _path.join)(this.#browserPath, DEB_HASH_FILE)}`);
240
- let serverRes = (hashFileContent.stdout || '').toString().trim();
241
- serverRes = serverRes.split(' ')[0];
242
- const calculateLocalBrowserHash = await exec(`cd ${(0, _path.join)(this.#browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
243
- xargs -0 sha256sum > ${this.#browserPath}/calculatedFolderSha.txt`);
244
- const localHashContent = await exec(`cd ${this.#browserPath} && sha256sum calculatedFolderSha.txt`);
245
- let userRes = (localHashContent.stdout || '').toString().trim();
246
- userRes = userRes.split(' ')[0];
247
- if (userRes !== serverRes) {
248
- throw new Error('Error in sum matching. Please run script again.');
249
- }
239
+ return Promise.resolve();
240
+
241
+ // const hashFileContent = await exec(`cat ${join(this.#browserPath, DEB_HASH_FILE)}`);
242
+ // let serverRes = (hashFileContent.stdout || '').toString().trim();
243
+ // serverRes = serverRes.split(' ')[0];
244
+
245
+ // const calculateLocalBrowserHash = await exec(
246
+ // `cd ${join(this.#browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
247
+ // xargs -0 sha256sum > ${this.#browserPath}/calculatedFolderSha.txt`,
248
+ // );
249
+
250
+ // const localHashContent = await exec(`cd ${this.#browserPath} && sha256sum calculatedFolderSha.txt`);
251
+ // let userRes = (localHashContent.stdout || '').toString().trim();
252
+ // userRes = userRes.split(' ')[0];
253
+ // if (userRes !== serverRes) {
254
+ // throw new Error('Error in sum matching. Please run script again.');
255
+ // }
250
256
  }
251
257
  async replaceBrowser() {
252
258
  console.log('Copy Orbita to target path');
@@ -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
- return e && e.__esModule ? e : { default: e };
24
- }
25
- const { access, readFile, writeFile, mkdir, readdir, copyFile, rename } =
26
- _fs.promises;
27
- const _filename = (0, _url.fileURLToPath)(
28
- require("url").pathToFileURL(__filename).toString()
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 = "https://fonts.gologin.com/";
32
- const FONTS_DIR_NAME = "fonts";
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, ".gologin", "browser");
29
+ const BROWSER_PATH = (0, _path.join)(HOMEDIR, '.gologin', 'browser');
35
30
  const OS_PLATFORM = process.platform;
36
- const DEFAULT_ORBITA_EXTENSIONS_NAMES = [
37
- "Google Hangouts",
38
- "Chromium PDF Viewer",
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 = ({ profileId, ACCESS_TOKEN, API_BASE_URL }) =>
46
- _requestretry.default
47
- .get(`${API_BASE_URL}/browser/${profileId}/cookies`, {
48
- headers: {
49
- Authorization: `Bearer ${ACCESS_TOKEN}`,
50
- "user-agent": "gologin-api",
51
- },
52
- json: true,
53
- maxAttempts: 3,
54
- retryDelay: 2000,
55
- timeout: 10 * 1000,
56
- })
57
- .catch((e) => {
58
- console.log(e);
59
- return {
60
- body: [],
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
- _requestretry.default
71
- .post(`${API_BASE_URL}/browser/${profileId}/cookies?encrypted=true`, {
72
- headers: {
73
- Authorization: `Bearer ${ACCESS_TOKEN}`,
74
- "User-Agent": "gologin-api",
75
- },
76
- json: cookies,
77
- maxAttempts: 3,
78
- retryDelay: 2000,
79
- timeout: 20 * 1000,
80
- })
81
- .catch((e) => {
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((font) => !files.includes(font));
96
- let promises = fontsToDownload.map((font) =>
97
- _requestretry.default
98
- .get(FONTS_URL + font, {
99
- maxAttempts: 5,
100
- retryDelay: 2000,
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("LICENSE.txt");
134
- fontsToDownload.push("OFL.txt");
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 === "linux") {
117
+ if (OS_PLATFORM === 'linux') {
150
118
  await copyFontsConfigFile(profilePath);
151
119
  }
152
120
  };
153
121
  exports.composeFonts = composeFonts;
154
- const copyFontsConfigFile = async (profilePath) => {
122
+ const copyFontsConfigFile = async profilePath => {
155
123
  if (!profilePath) {
156
124
  return;
157
125
  }
158
- const fileContent = await readFile(
159
- (0, _path.resolve)(_dirname, "..", "..", "fonts_config"),
160
- "utf-8"
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, "fonts_config"), result);
132
+ await writeFile((0, _path.join)(defaultFolderPath, 'fonts_config'), result);
171
133
  };
172
134
  exports.copyFontsConfigFile = copyFontsConfigFile;
173
- const setExtPathsAndRemoveDeleted = (
174
- settings = {},
175
- profileExtensionsCheckRes = [],
176
- profileId = ""
177
- ) => {
178
- const formattedLocalExtArray = profileExtensionsCheckRes
179
- .map((el) => {
180
- const [extFolderName = ""] = el.split(_path.sep).reverse();
181
- const [originalId] = extFolderName.split("@");
182
- if (!originalId) {
183
- return null;
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 (extensionObj) => {
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 === "win32") {
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((el) =>
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
- (0, _os.tmpdir)(),
258
- `gologin_profile_${profileId}`
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(".zip")) {
275
- localExtObj.path = localExtObj.path.replace(".zip", "");
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 (originalId) => {
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("manifest.json")) {
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((extensionObj) => {
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, "manifest.json");
258
+ const manifestFilePath = (0, _path.join)(localExtObj.path, 'manifest.json');
343
259
  const manifestString = await readFile(manifestFilePath, {
344
- encoding: "utf8",
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 = "utf8";
359
- if (osPlatform === "win32") {
360
- encoding = "utf16le";
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)("sha256")
364
- .update(extPathToEncode)
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: "a",
381
- 1: "b",
382
- 2: "c",
383
- 3: "d",
384
- 4: "e",
385
- 5: "f",
386
- 6: "g",
387
- 7: "h",
388
- 8: "i",
389
- 9: "j",
390
- a: "k",
391
- b: "l",
392
- c: "m",
393
- d: "n",
394
- e: "o",
395
- f: "p",
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
+ };
@@ -470,7 +470,10 @@ class GoLogin {
470
470
  proxy = null;
471
471
  }
472
472
  this.proxy = proxy;
473
- this.getTimeZone(proxy)
473
+ await this.getTimeZone(proxy).catch(e => {
474
+ console.error("Proxy Error. Check it and try again.");
475
+ throw new Error(`Proxy Error. ${e.message}`);
476
+ });
474
477
  const [latitude, longitude] = this._tz.ll;
475
478
  const {
476
479
  accuracy
@@ -618,7 +621,7 @@ class GoLogin {
618
621
  }
619
622
  return port;
620
623
  }
621
- getTimeZone(proxy) {
624
+ async getTimeZone(proxy) {
622
625
  debug("getting timeZone proxy=", proxy);
623
626
  if (this.timezone) {
624
627
  debug("getTimeZone from options", this.timezone);
@@ -626,25 +629,27 @@ class GoLogin {
626
629
  return this._tz.timezone;
627
630
  }
628
631
  let data = null;
629
- // if (proxy && proxy.mode !== PROXY_NONE) {
630
- // if (proxy.mode.includes("socks")) {
631
- // for (let i = 0; i < 5; i++) {
632
- // try {
633
- // debug("getting timeZone socks try", i + 1);
634
- // return this.getTimezoneWithSocks(proxy);
635
- // } catch (e) {
636
- // console.log(e.message);
637
- // }
638
- // }
639
- // throw new Error("Socks proxy connection timed out");
640
- // }
641
- // const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
642
- // debug(`getTimeZone start ${TIMEZONE_URL}`, proxyUrl);
643
- // const response = await _requestretry.default.get(TIMEZONE_URL, {
644
- // proxy: proxyUrl,
645
- // timeout: 20 * 1000,
646
- // maxAttempts: 5
647
- // });
632
+ if (proxy && proxy.mode !== PROXY_NONE) {
633
+ if (proxy.mode.includes("socks")) {
634
+ for (let i = 0; i < 5; i++) {
635
+ try {
636
+ debug("getting timeZone socks try", i + 1);
637
+ return this.getTimezoneWithSocks(proxy);
638
+ } catch (e) {
639
+ console.log(e.message);
640
+ }
641
+ }
642
+ throw new Error("Socks proxy connection timed out");
643
+ }
644
+
645
+ // const proxyUrl = `${proxy.mode}://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`;
646
+ // debug(`getTimeZone start ${TIMEZONE_URL}`, proxyUrl);
647
+ // const response = await requests.get(TIMEZONE_URL, {
648
+ // proxy: proxyUrl,
649
+ // timeout: 20 * 1000,
650
+ // maxAttempts: 5,
651
+ // });
652
+ // const result = JSON.parse(response.body);
648
653
  const result = {
649
654
  country: "ID",
650
655
  stateProv: "Jakarta",
@@ -652,7 +657,7 @@ class GoLogin {
652
657
  timezone: "Asia/Jakarta",
653
658
  ll: ["-6.21462", "106.84513"],
654
659
  languages: "id",
655
- accuracy: 100,
660
+ accuracy: 100
656
661
  };
657
662
  data = {
658
663
  body: {
@@ -665,24 +670,24 @@ class GoLogin {
665
670
  accuracy: 100
666
671
  }
667
672
  };
668
- // } else {
669
- // const response = await _requestretry.default.get(TIMEZONE_URL, {
670
- // timeout: 20 * 1000,
671
- // maxAttempts: 5
672
- // });
673
- // const result = JSON.parse(response.body);
674
- // data = {
675
- // body: {
676
- // country: result.country_code,
677
- // stateProv: result.city,
678
- // city: result.city,
679
- // timezone: (0, _timezone.tzlookup)(result.latitude, result.longitude),
680
- // ll: [result.latitude, result.longitude],
681
- // languages: "en",
682
- // accuracy: 100
683
- // }
684
- // };
685
- // }
673
+ } else {
674
+ const response = await _requestretry.default.get(TIMEZONE_URL, {
675
+ timeout: 20 * 1000,
676
+ maxAttempts: 5
677
+ });
678
+ const result = JSON.parse(response.body);
679
+ data = {
680
+ body: {
681
+ country: result.country_code,
682
+ stateProv: result.city,
683
+ city: result.city,
684
+ timezone: (0, _timezone.tzlookup)(result.latitude, result.longitude),
685
+ ll: [result.latitude, result.longitude],
686
+ languages: "en",
687
+ accuracy: 100
688
+ }
689
+ };
690
+ }
686
691
  debug("getTimeZone finish", data.body);
687
692
  this._tz = data.body;
688
693
  return this._tz.timezone;
@@ -741,7 +746,10 @@ class GoLogin {
741
746
  Object.keys(process.env).forEach(key => {
742
747
  env[key] = process.env[key];
743
748
  });
744
- const tz = this.getTimeZone(this.proxy)
749
+ const tz = await this.getTimeZone(this.proxy).catch(e => {
750
+ console.error("Proxy Error. Check it and try again.");
751
+ throw e;
752
+ });
745
753
  env.TZ = tz;
746
754
  let params = [`--proxy-server=${proxy}`, `--user-data-dir=${profile_path}`, "--password-store=basic", `--tz=${tz}`, "--lang=en"];
747
755
  if (Array.isArray(this.extra_params) && this.extra_params.length) {
@@ -776,7 +784,10 @@ class GoLogin {
776
784
  Object.keys(process.env).forEach(key => {
777
785
  env[key] = process.env[key];
778
786
  });
779
- const tz = this.getTimeZone(this.proxy)
787
+ const tz = await this.getTimeZone(this.proxy).catch(e => {
788
+ console.error("Proxy Error. Check it and try again.");
789
+ throw e;
790
+ });
780
791
  env.TZ = tz;
781
792
  if (this.vnc_port) {
782
793
  const script_path = (0, _path.resolve)(__dirname, "./run.sh");
@@ -265,21 +265,23 @@ export class BrowserChecker {
265
265
  return;
266
266
  }
267
267
 
268
- const hashFileContent = await exec(`cat ${join(this.#browserPath, DEB_HASH_FILE)}`);
269
- let serverRes = (hashFileContent.stdout || '').toString().trim();
270
- serverRes = serverRes.split(' ')[0];
271
-
272
- const calculateLocalBrowserHash = await exec(
273
- `cd ${join(this.#browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
274
- xargs -0 sha256sum > ${this.#browserPath}/calculatedFolderSha.txt`,
275
- );
276
-
277
- const localHashContent = await exec(`cd ${this.#browserPath} && sha256sum calculatedFolderSha.txt`);
278
- let userRes = (localHashContent.stdout || '').toString().trim();
279
- userRes = userRes.split(' ')[0];
280
- if (userRes !== serverRes) {
281
- throw new Error('Error in sum matching. Please run script again.');
282
- }
268
+ return Promise.resolve();
269
+
270
+ // const hashFileContent = await exec(`cat ${join(this.#browserPath, DEB_HASH_FILE)}`);
271
+ // let serverRes = (hashFileContent.stdout || '').toString().trim();
272
+ // serverRes = serverRes.split(' ')[0];
273
+
274
+ // const calculateLocalBrowserHash = await exec(
275
+ // `cd ${join(this.#browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
276
+ // xargs -0 sha256sum > ${this.#browserPath}/calculatedFolderSha.txt`,
277
+ // );
278
+
279
+ // const localHashContent = await exec(`cd ${this.#browserPath} && sha256sum calculatedFolderSha.txt`);
280
+ // let userRes = (localHashContent.stdout || '').toString().trim();
281
+ // userRes = userRes.split(' ')[0];
282
+ // if (userRes !== serverRes) {
283
+ // throw new Error('Error in sum matching. Please run script again.');
284
+ // }
283
285
  }
284
286
 
285
287
  async replaceBrowser() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin-commonjs",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "A Transpiled GoLogin API ESM to CommonJS",
5
5
  "types": "./types/src/gologin.d.ts",
6
6
  "main": "./dist/src/gologin.js",