gologin 2.0.8 → 2.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./src/gologin.js",
6
6
  "repository": {
@@ -9,6 +9,8 @@ import ProgressBar from 'progress';
9
9
  import { createInterface } from 'readline';
10
10
  import util from 'util';
11
11
 
12
+ import { findLatestBrowserVersionDirectory } from '../utils/utils.js';
13
+
12
14
  const exec = util.promisify(execNonPromise);
13
15
  const { access, mkdir, readdir, rmdir, unlink, copyFile, readlink, symlink, lstat } = _promises;
14
16
 
@@ -50,7 +52,12 @@ export class BrowserChecker {
50
52
 
51
53
  let executableFilePath = join(this.#browserPath, 'orbita-browser', 'chrome');
52
54
  if (PLATFORM === 'darwin') {
53
- executableFilePath = join(this.#browserPath, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
55
+ const orbitaFolderName = findLatestBrowserVersionDirectory(this.#browserPath);
56
+ if (orbitaFolderName === 'error') {
57
+ throw Error('Orbita folder not found in this directory: ' + this.#browserPath);
58
+ }
59
+
60
+ executableFilePath = join(this.#browserPath, orbitaFolderName, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
54
61
  } else if (PLATFORM === 'win32') {
55
62
  executableFilePath = join(this.#browserPath, 'orbita-browser', 'chrome.exe');
56
63
  }
package/src/gologin.js CHANGED
@@ -584,15 +584,15 @@ export class GoLogin {
584
584
  }
585
585
  }
586
586
 
587
- const [languages] = this.language.split(';');
587
+ const languages = this.language.replace(/;|q=[\d\.]+/img, '')
588
588
 
589
589
  if (preferences.gologin==null) {
590
590
  preferences.gologin = {};
591
591
  }
592
592
 
593
593
  preferences.gologin.langHeader = gologin.language;
594
- preferences.gologin.languages = languages;
595
- // debug("convertedPreferences=", preferences.gologin)
594
+ preferences.gologin.language = languages;
595
+
596
596
  await writeFile(join(profilePath, 'Default', 'Preferences'), JSON.stringify(Object.assign(preferences, {
597
597
  gologin,
598
598
  })));
@@ -11,7 +11,7 @@ const DEFAULT_FOLDER_USELESS_FILE = [
11
11
  },
12
12
  {
13
13
  name: 'Service Worker',
14
- subs: ['CacheStorage'],
14
+ subs: ['CacheStorage', 'ScriptCache'],
15
15
  isDirectory: true,
16
16
  },
17
17
  {
@@ -1,4 +1,6 @@
1
+ import { readdirSync, statSync } from 'node:fs';
1
2
  import net from 'node:net';
3
+ import { join } from 'node:path';
2
4
 
3
5
  export const get = (value, path, defaultValue) =>
4
6
  String(path).split('.').reduce((acc, v) => {
@@ -20,3 +22,28 @@ export const isPortReachable = (port) => new Promise(resolve => {
20
22
  .listen(port);
21
23
  });
22
24
 
25
+ export const findLatestBrowserVersionDirectory = (browserPath) => {
26
+ const folderContents = readdirSync(browserPath);
27
+ const directories = folderContents.filter(file => statSync(join(browserPath, file)).isDirectory());
28
+
29
+ const { folderName, version } = directories.reduce((newest, currentFolderName) => {
30
+ const match = currentFolderName.match(/\d+/);
31
+
32
+ if (match) {
33
+ const findedVersion = parseInt(match[0], 10);
34
+
35
+ if (findedVersion > newest.version) {
36
+ return { folderName: currentFolderName, version: findedVersion };
37
+ }
38
+ }
39
+
40
+ return newest;
41
+ }, { folderName: '', version: 0 });
42
+
43
+ if (!version) {
44
+ return 'error';
45
+ }
46
+
47
+ return folderName;
48
+ };
49
+