gologin-commonjs 1.2.8 → 1.2.9
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/examples/puppeter/cloud-browser.js +27 -0
- package/dist/examples/puppeter/headless.js +27 -0
- package/dist/examples/puppeter/local-browser.js +26 -0
- package/dist/examples/puppeter/one-time-use-profile.js +29 -0
- package/dist/src/browser/browser-api.js +21 -22
- package/dist/src/browser/browser-checker.js +126 -118
- package/dist/src/browser/browser-download-manager.js +199 -0
- package/dist/src/browser/browser-user-data-manager.js +22 -19
- package/dist/src/cookies/cookies-manager.js +25 -5
- package/dist/src/extensions/extensions-manager.js +22 -27
- package/dist/src/extensions/user-extensions-manager.js +9 -10
- package/dist/src/gologin-api.js +198 -34
- package/dist/src/gologin.js +596 -578
- package/dist/src/utils/browser.js +47 -3
- package/dist/src/utils/common.js +19 -1
- package/dist/src/utils/constants.js +1 -1
- package/dist/src/utils/http.js +71 -0
- package/dist/src/utils/sentry.js +99 -0
- package/dist/src/utils/utils.js +4 -2
- package/dist/test/e2e/run-tests.js +69 -0
- package/gologin/examples/puppeter/cloud-browser.js +30 -0
- package/gologin/examples/puppeter/headless.js +30 -0
- package/gologin/examples/puppeter/local-browser.js +29 -0
- package/gologin/examples/puppeter/one-time-use-profile.js +31 -0
- package/gologin/index.d.ts +68 -24
- package/gologin/src/browser/browser-api.js +22 -23
- package/gologin/src/browser/browser-checker.js +129 -124
- package/gologin/src/browser/browser-download-manager.js +222 -0
- package/gologin/src/browser/browser-user-data-manager.js +21 -18
- package/gologin/src/cookies/cookies-manager.js +30 -5
- package/gologin/src/extensions/extensions-manager.js +21 -26
- package/gologin/src/extensions/user-extensions-manager.js +9 -10
- package/gologin/src/gologin-api.js +182 -32
- package/gologin/src/gologin.js +657 -933
- package/gologin/src/utils/browser.js +61 -3
- package/gologin/src/utils/common.js +16 -1
- package/gologin/src/utils/constants.js +1 -1
- package/gologin/src/utils/http.js +72 -0
- package/gologin/src/utils/sentry.js +73 -0
- package/gologin/src/utils/utils.js +1 -0
- package/gologin/test/e2e/run-tests.js +73 -0
- package/gologin/types/profile-params.d.ts +126 -0
- package/package.json +3 -3
- package/tes.js +2 -2
- package/types/src/browser/browser-api.d.ts +3 -3
- package/types/src/browser/browser-checker.d.ts +21 -13
- package/types/src/browser/browser-download-manager.d.ts +13 -0
- package/types/src/browser/browser-user-data-manager.d.ts +3 -3
- package/types/src/cookies/cookies-manager.d.ts +2 -15
- package/types/src/extensions/extensions-extractor.d.ts +2 -2
- package/types/src/extensions/extensions-manager.d.ts +4 -4
- package/types/src/extensions/user-extensions-manager.d.ts +3 -3
- package/types/src/gologin-api.d.ts +14 -8
- package/types/src/gologin.d.ts +120 -28
- package/types/src/utils/browser.d.ts +2 -1
- package/types/src/utils/common.d.ts +6 -4
- package/types/src/utils/constants.d.ts +1 -1
- package/types/src/utils/http.d.ts +2 -0
- package/types/src/utils/sentry.d.ts +1 -0
- package/types/src/utils/utils.d.ts +3 -2
- package/gologin/examples/example-amazon-cloud-browser.js +0 -37
- package/gologin/examples/example-amazon-headless.js +0 -50
- package/gologin/examples/example-amazon.js +0 -47
- package/gologin/examples/example-create-custom-profile.js +0 -39
- package/gologin/examples/example-create-profile.js +0 -40
- package/gologin/examples/example-custom-args.js +0 -34
- package/gologin/examples/example-fast-profile-settings.js +0 -69
- package/gologin/examples/example-gmail.js +0 -67
- package/gologin/examples/example-iphey.js +0 -17
- package/gologin/examples/example-local-profile.js +0 -26
- package/gologin/examples/example-login-walmart.js +0 -35
- package/gologin/examples/example-stopremote.js +0 -20
- package/gologin/examples/example-timezone.js +0 -44
- package/gologin/src/utils/timezone.js +0 -470
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _gologin = require("gologin");
|
|
4
|
+
// Gologin provides a cloud browser that can be used to run puppeteer aytomation.
|
|
5
|
+
// It will handle the browser start and close management - you just need to control the browser with pupputter
|
|
6
|
+
|
|
7
|
+
const token = process.env.GL_API_TOKEN || 'your dev token here';
|
|
8
|
+
const gologin = (0, _gologin.GologinApi)({
|
|
9
|
+
token
|
|
10
|
+
});
|
|
11
|
+
async function main() {
|
|
12
|
+
const {
|
|
13
|
+
browser
|
|
14
|
+
} = await gologin.launch({
|
|
15
|
+
cloud: true
|
|
16
|
+
// pass profileId parameter if you want to run particular profile
|
|
17
|
+
// profileId: 'your profileId here',
|
|
18
|
+
});
|
|
19
|
+
const page = await browser.newPage();
|
|
20
|
+
await page.goto('https://iphey.com/', {
|
|
21
|
+
waitUntil: 'networkidle2'
|
|
22
|
+
});
|
|
23
|
+
const status = await page.$eval('.trustworthy:not(.hide)', elt => elt?.innerText?.trim());
|
|
24
|
+
console.log('status', status);
|
|
25
|
+
return status;
|
|
26
|
+
}
|
|
27
|
+
main().catch(console.error).finally(gologin.exit);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _gologin = require("gologin");
|
|
4
|
+
// SDK will prepare the browser and will start it on your machine then you can control it with puppeteer
|
|
5
|
+
|
|
6
|
+
const token = process.env.GL_API_TOKEN || 'your dev token here';
|
|
7
|
+
const gologin = (0, _gologin.GologinApi)({
|
|
8
|
+
token
|
|
9
|
+
});
|
|
10
|
+
async function main() {
|
|
11
|
+
const {
|
|
12
|
+
browser
|
|
13
|
+
} = await gologin.launch({
|
|
14
|
+
extra_params: ['--headless']
|
|
15
|
+
// pass profileId parameter if you want to run particular profile
|
|
16
|
+
// profileId: 'your profileId here',
|
|
17
|
+
});
|
|
18
|
+
const page = await browser.newPage();
|
|
19
|
+
await page.goto('https://iphey.com/', {
|
|
20
|
+
waitUntil: 'networkidle2'
|
|
21
|
+
});
|
|
22
|
+
const status = await page.$eval('.trustworthy:not(.hide)', elt => elt?.innerText?.trim());
|
|
23
|
+
await new Promise(resolve => setTimeout(resolve, 10000));
|
|
24
|
+
console.log('status', status);
|
|
25
|
+
return status;
|
|
26
|
+
}
|
|
27
|
+
main().catch(console.error).finally(gologin.exit);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _gologin = require("gologin");
|
|
4
|
+
// SDK will prepare the browser and will start it on your machine then you can control it with puppeteer
|
|
5
|
+
|
|
6
|
+
const token = process.env.GL_API_TOKEN || 'your dev token here';
|
|
7
|
+
const gologin = (0, _gologin.GologinApi)({
|
|
8
|
+
token
|
|
9
|
+
});
|
|
10
|
+
async function main() {
|
|
11
|
+
const {
|
|
12
|
+
browser
|
|
13
|
+
} = await gologin.launch({
|
|
14
|
+
// pass profileId parameter if you want to run particular profile
|
|
15
|
+
// profileId: 'your profileId here',
|
|
16
|
+
});
|
|
17
|
+
const page = await browser.newPage();
|
|
18
|
+
await page.goto('https://iphey.com/', {
|
|
19
|
+
waitUntil: 'networkidle2'
|
|
20
|
+
});
|
|
21
|
+
const status = await page.$eval('.trustworthy:not(.hide)', elt => elt?.innerText?.trim());
|
|
22
|
+
await new Promise(resolve => setTimeout(resolve, 10000));
|
|
23
|
+
console.log('status', status);
|
|
24
|
+
return status;
|
|
25
|
+
}
|
|
26
|
+
main().catch(console.error).finally(gologin.exit);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _gologinApi = require("../../src/gologin-api.js");
|
|
4
|
+
// You need to create profile add proxy, use it with puppetter and then delete it
|
|
5
|
+
|
|
6
|
+
const token = process.env.GL_API_TOKEN || 'your dev token here';
|
|
7
|
+
const gologin = (0, _gologinApi.GologinApi)({
|
|
8
|
+
token
|
|
9
|
+
});
|
|
10
|
+
async function main() {
|
|
11
|
+
const profile = await gologin.createProfileRandomFingerprint();
|
|
12
|
+
const profileId = profile.id;
|
|
13
|
+
await gologin.addGologinProxyToProfile(profileId, 'US');
|
|
14
|
+
const {
|
|
15
|
+
browser
|
|
16
|
+
} = await gologin.launch({
|
|
17
|
+
profileId
|
|
18
|
+
});
|
|
19
|
+
const page = await browser.newPage();
|
|
20
|
+
await page.goto('https://iphey.com/', {
|
|
21
|
+
waitUntil: 'networkidle2'
|
|
22
|
+
});
|
|
23
|
+
const status = await page.$eval('.trustworthy:not(.hide)', elt => elt?.innerText?.trim());
|
|
24
|
+
await new Promise(resolve => setTimeout(resolve, 10000));
|
|
25
|
+
console.log('status', status);
|
|
26
|
+
await gologin.deleteProfile(profileId);
|
|
27
|
+
return status;
|
|
28
|
+
}
|
|
29
|
+
main().catch(console.error).finally(gologin.exit);
|
|
@@ -4,25 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.updateProfileUserAgent = exports.updateProfileResolution = exports.updateProfileProxy = exports.updateProfileBookmarks = void 0;
|
|
7
|
-
var _requestretry = _interopRequireDefault(require("requestretry"));
|
|
8
7
|
var _common = require("../utils/common.js");
|
|
9
|
-
|
|
8
|
+
var _http = require("../utils/http.js");
|
|
10
9
|
/**
|
|
11
10
|
* @param {string} profileId
|
|
12
11
|
* @param {string} ACCESS_TOKEN
|
|
13
12
|
* @param {string} resolution
|
|
14
13
|
*/
|
|
15
|
-
const updateProfileResolution = (profileId, ACCESS_TOKEN, resolution) =>
|
|
16
|
-
|
|
17
|
-
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
18
|
-
'user-agent': 'gologin-api'
|
|
19
|
-
},
|
|
14
|
+
const updateProfileResolution = (profileId, ACCESS_TOKEN, resolution) => (0, _http.makeRequest)(`${_common.API_URL}/browser/${profileId}/resolution`, {
|
|
15
|
+
method: 'PATCH',
|
|
20
16
|
json: {
|
|
21
17
|
resolution
|
|
22
18
|
},
|
|
23
19
|
maxAttempts: 3,
|
|
24
20
|
retryDelay: 2000,
|
|
25
21
|
timeout: 10 * 1000
|
|
22
|
+
}, {
|
|
23
|
+
token: ACCESS_TOKEN,
|
|
24
|
+
fallbackUrl: `${_common.FALLBACK_API_URL}/browser/${profileId}/resolution`
|
|
26
25
|
}).catch(e => {
|
|
27
26
|
console.log(e);
|
|
28
27
|
return {
|
|
@@ -36,17 +35,17 @@ const updateProfileResolution = (profileId, ACCESS_TOKEN, resolution) => _reques
|
|
|
36
35
|
* @param {string} userAgent
|
|
37
36
|
*/
|
|
38
37
|
exports.updateProfileResolution = updateProfileResolution;
|
|
39
|
-
const updateProfileUserAgent = (profileId, ACCESS_TOKEN, userAgent) =>
|
|
40
|
-
|
|
41
|
-
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
42
|
-
'user-agent': 'gologin-api'
|
|
43
|
-
},
|
|
38
|
+
const updateProfileUserAgent = (profileId, ACCESS_TOKEN, userAgent) => (0, _http.makeRequest)(`${_common.API_URL}/browser/${profileId}/ua`, {
|
|
39
|
+
method: 'PATCH',
|
|
44
40
|
json: {
|
|
45
41
|
userAgent
|
|
46
42
|
},
|
|
47
43
|
maxAttempts: 3,
|
|
48
44
|
retryDelay: 2000,
|
|
49
45
|
timeout: 10 * 1000
|
|
46
|
+
}, {
|
|
47
|
+
token: ACCESS_TOKEN,
|
|
48
|
+
fallbackUrl: `${_common.FALLBACK_API_URL}/browser/${profileId}/ua`
|
|
50
49
|
}).catch(e => {
|
|
51
50
|
console.log(e);
|
|
52
51
|
return {
|
|
@@ -65,15 +64,15 @@ const updateProfileUserAgent = (profileId, ACCESS_TOKEN, userAgent) => _requestr
|
|
|
65
64
|
* @param {string} [browserProxyData.password]
|
|
66
65
|
*/
|
|
67
66
|
exports.updateProfileUserAgent = updateProfileUserAgent;
|
|
68
|
-
const updateProfileProxy = (profileId, ACCESS_TOKEN, browserProxyData) =>
|
|
69
|
-
|
|
70
|
-
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
71
|
-
'user-agent': 'gologin-api'
|
|
72
|
-
},
|
|
67
|
+
const updateProfileProxy = (profileId, ACCESS_TOKEN, browserProxyData) => (0, _http.makeRequest)(`${_common.API_URL}/browser/${profileId}/proxy`, {
|
|
68
|
+
method: 'PATCH',
|
|
73
69
|
json: browserProxyData,
|
|
74
70
|
maxAttempts: 3,
|
|
75
71
|
retryDelay: 2000,
|
|
76
72
|
timeout: 10 * 1000
|
|
73
|
+
}, {
|
|
74
|
+
token: ACCESS_TOKEN,
|
|
75
|
+
fallbackUrl: `${_common.FALLBACK_API_URL}/browser/${profileId}/proxy`
|
|
77
76
|
}).catch(e => {
|
|
78
77
|
console.log(e);
|
|
79
78
|
return {
|
|
@@ -92,15 +91,15 @@ const updateProfileBookmarks = async (profileIds, ACCESS_TOKEN, bookmarks) => {
|
|
|
92
91
|
profileIds,
|
|
93
92
|
bookmarks
|
|
94
93
|
};
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
Authorization: `Bearer ${ACCESS_TOKEN}`,
|
|
98
|
-
'user-agent': 'gologin-api'
|
|
99
|
-
},
|
|
94
|
+
return (0, _http.makeRequest)(`${_common.API_URL}/browser/bookmarks/many`, {
|
|
95
|
+
method: 'PATCH',
|
|
100
96
|
json: params,
|
|
101
97
|
maxAttempts: 3,
|
|
102
98
|
retryDelay: 2000,
|
|
103
99
|
timeout: 10 * 1000
|
|
100
|
+
}, {
|
|
101
|
+
token: ACCESS_TOKEN,
|
|
102
|
+
fallbackUrl: `${_common.FALLBACK_API_URL}/browser/bookmarks/many`
|
|
104
103
|
}).catch(error => console.log(error));
|
|
105
104
|
};
|
|
106
105
|
exports.updateProfileBookmarks = updateProfileBookmarks;
|
|
@@ -12,10 +12,9 @@ var _https = require("https");
|
|
|
12
12
|
var _os = require("os");
|
|
13
13
|
var _path = require("path");
|
|
14
14
|
var _progress = _interopRequireDefault(require("progress"));
|
|
15
|
-
var _readline = require("readline");
|
|
16
15
|
var _util = _interopRequireDefault(require("util"));
|
|
17
|
-
var _utils = require("../utils/utils.js");
|
|
18
16
|
var _common = require("../utils/common.js");
|
|
17
|
+
var _browserDownloadManager = _interopRequireDefault(require("./browser-download-manager.js"));
|
|
19
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
19
|
const exec = _util.default.promisify(_child_process.exec);
|
|
21
20
|
const {
|
|
@@ -29,101 +28,117 @@ const {
|
|
|
29
28
|
symlink,
|
|
30
29
|
lstat,
|
|
31
30
|
rename,
|
|
32
|
-
writeFile
|
|
31
|
+
writeFile,
|
|
32
|
+
readFile
|
|
33
33
|
} = _fs.promises;
|
|
34
34
|
const PLATFORM = process.platform;
|
|
35
35
|
const ARCH = process.arch;
|
|
36
36
|
const VERSION_FILE = 'latest-version.txt';
|
|
37
|
-
const WIN_FOLDERSIZE_FILE = 'foldersize.txt';
|
|
38
|
-
const WIN_FOLDERSIZE_FILE_LINK = `https://orbita-browser-windows.gologin.com/${WIN_FOLDERSIZE_FILE}`;
|
|
39
37
|
const BROWSER_ARCHIVE_NAME = `orbita-browser-latest.${PLATFORM === 'win32' ? 'zip' : 'tar.gz'}`;
|
|
40
38
|
const MAC_HASH_FILE = 'hashfile.mtree';
|
|
41
39
|
const DEB_HASH_FILE = 'hashfile.txt';
|
|
42
|
-
const WIN_HASH_FILE = DEB_HASH_FILE;
|
|
43
40
|
const MAC_HASHFILE_LINK = `https://orbita-browser-mac.gologin.com/${MAC_HASH_FILE}`;
|
|
44
41
|
const DEB_HASHFILE_LINK = `https://orbita-browser-linux.gologin.com/${DEB_HASH_FILE}`;
|
|
45
|
-
const WIN_HASHFILE_LINK = `https://orbita-browser-windows.gologin.com/${WIN_HASH_FILE}`;
|
|
46
42
|
const MAC_ARM_HASHFILE_LINK = `https://orbita-browser-mac-arm.gologin.com/${MAC_HASH_FILE}`;
|
|
47
43
|
const FAIL_SUM_MATCH_MESSAGE = 'hash_sum_not_matched';
|
|
48
44
|
const EXTRACTED_FOLDER = 'extracted-browser';
|
|
49
45
|
class BrowserChecker {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this
|
|
56
|
-
this
|
|
57
|
-
this.#browserPath = (0, _path.join)(this.#homedir, '.gologin', 'browser');
|
|
58
|
-
let executableFilePath = (0, _path.join)(this.#browserPath, 'orbita-browser', 'chrome');
|
|
59
|
-
if (PLATFORM === 'darwin') {
|
|
60
|
-
const orbitaFolderName = (0, _utils.findLatestBrowserVersionDirectory)(this.#browserPath);
|
|
61
|
-
if (orbitaFolderName === 'error') {
|
|
62
|
-
throw Error('Orbita folder not found in this directory: ' + this.#browserPath);
|
|
63
|
-
}
|
|
64
|
-
executableFilePath = (0, _path.join)(this.#browserPath, orbitaFolderName, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
|
|
65
|
-
} else if (PLATFORM === 'win32') {
|
|
66
|
-
executableFilePath = (0, _path.join)(this.#browserPath, 'orbita-browser', 'chrome.exe');
|
|
67
|
-
}
|
|
68
|
-
this.#executableFilePath = executableFilePath;
|
|
69
|
-
// console.log('executableFilePath:', executableFilePath);
|
|
46
|
+
constructor() {
|
|
47
|
+
this.homedir = (0, _os.homedir)();
|
|
48
|
+
this.browserPath = (0, _path.join)(this.homedir, '.gologin', 'browser');
|
|
49
|
+
this.executableFilePath = null;
|
|
50
|
+
this.skipOrbitaHashChecking = false;
|
|
51
|
+
this.downloadManager = _browserDownloadManager.default.getInstance();
|
|
52
|
+
this.downloadManager.cleanupStaleLocks().catch(console.warn);
|
|
70
53
|
}
|
|
71
|
-
async checkBrowser(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return this.
|
|
79
|
-
}
|
|
80
|
-
const currentVersionReq = await this.getCurrentVersion();
|
|
81
|
-
const currentVersion = (currentVersionReq?.stdout || '').replace(/(\r\n|\n|\r)/gm, '');
|
|
82
|
-
if (browserLatestVersion === currentVersion || !checkBrowserUpdate) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (autoUpdateBrowser) {
|
|
86
|
-
return this.downloadBrowser(browserLatestVersion, browserDownloadUrl);
|
|
54
|
+
async checkBrowser({
|
|
55
|
+
autoUpdateBrowser,
|
|
56
|
+
majorVersion
|
|
57
|
+
}) {
|
|
58
|
+
const isBrowserFolderExists = await access((0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`)).then(() => true).catch(() => false);
|
|
59
|
+
if (!isBrowserFolderExists || autoUpdateBrowser) {
|
|
60
|
+
await this.downloadManager.ensureBrowserDownload(majorVersion, () => this.downloadBrowser(majorVersion));
|
|
61
|
+
return this.getBrowserExecutablePath(majorVersion);
|
|
87
62
|
}
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
63
|
+
return this.getBrowserExecutablePath(majorVersion);
|
|
64
|
+
|
|
65
|
+
// TO DO: add check for browser update
|
|
66
|
+
// const { latestVersion: browserLatestVersion } = await this.getLatestBrowserVersion();
|
|
67
|
+
// const [latestBrowserMajorVersion] = browserLatestVersion.split('.');
|
|
68
|
+
// const currentVersion = await this.getCurrentVersion(majorVersion);
|
|
69
|
+
|
|
70
|
+
// const isCurrentVersionsLatest = majorVersion === latestBrowserMajorVersion;
|
|
71
|
+
// console.log('browserLatestVersion', browserLatestVersion);
|
|
72
|
+
// console.log('currentVersion', currentVersion);
|
|
73
|
+
// console.log('isCurrentVersionsLatest', isCurrentVersionsLatest);
|
|
74
|
+
// console.log('checkBrowserUpdate', checkBrowserUpdate);
|
|
75
|
+
// console.log('autoUpdateBrowser', autoUpdateBrowser);
|
|
76
|
+
// if (browserLatestVersion === currentVersion || !(checkBrowserUpdate && isCurrentVersionsLatest)) {
|
|
77
|
+
// return this.getBrowserExecutablePath(majorVersion);
|
|
78
|
+
// }
|
|
79
|
+
|
|
80
|
+
// return new Promise(resolve => {
|
|
81
|
+
// const rl = createInterface(process.stdin, process.stdout);
|
|
82
|
+
// const timeout = setTimeout(() => {
|
|
83
|
+
// console.log(`\nContinue with current ${currentVersion} version.`);
|
|
84
|
+
// resolve();
|
|
85
|
+
// }, 10000);
|
|
86
|
+
|
|
87
|
+
// rl.question(`New Orbita ${browserLatestVersion} is available. Update? [y/n] `, (answer) => {
|
|
88
|
+
// clearTimeout(timeout);
|
|
89
|
+
// rl.close();
|
|
90
|
+
// if (answer && answer[0].toString().toLowerCase() === 'y') {
|
|
91
|
+
// return this.downloadBrowser(majorVersion).then(() => resolve(this.getBrowserExecutablePath(majorVersion)));
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
// console.log(`Continue with current ${currentVersion} version.`);
|
|
95
|
+
// resolve(this.getBrowserExecutablePath(majorVersion));
|
|
96
|
+
// });
|
|
97
|
+
// });
|
|
104
98
|
}
|
|
105
|
-
async downloadBrowser(
|
|
106
|
-
await this.
|
|
107
|
-
await mkdir(this.#browserPath, {
|
|
99
|
+
async downloadBrowser(majorVersion) {
|
|
100
|
+
await mkdir(this.browserPath, {
|
|
108
101
|
recursive: true
|
|
109
102
|
});
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
await this.
|
|
103
|
+
const browserPath = (0, _path.join)(this.browserPath, BROWSER_ARCHIVE_NAME);
|
|
104
|
+
const browserDownloadUrl = this.getBrowserDownloadUrl(majorVersion);
|
|
105
|
+
await this.downloadBrowserArchive(browserDownloadUrl, browserPath);
|
|
113
106
|
await this.extractBrowser();
|
|
114
|
-
await this.
|
|
115
|
-
console.log('Orbita hash checked successfully');
|
|
116
|
-
await this.replaceBrowser();
|
|
117
|
-
await this.addLatestVersion(latestVersion).catch(() => null);
|
|
107
|
+
await this.replaceBrowser(majorVersion);
|
|
118
108
|
await this.deleteOldArchives();
|
|
119
|
-
|
|
109
|
+
}
|
|
110
|
+
getBrowserExecutablePath(majorVersion) {
|
|
111
|
+
const os = (0, _common.getOS)();
|
|
112
|
+
switch (os) {
|
|
113
|
+
case 'mac':
|
|
114
|
+
return (0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
|
|
115
|
+
case 'win':
|
|
116
|
+
return (0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`, 'chrome.exe');
|
|
117
|
+
case 'macM1':
|
|
118
|
+
return (0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`, 'Orbita-Browser.app', 'Contents', 'MacOS', 'Orbita');
|
|
119
|
+
default:
|
|
120
|
+
return (0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`, 'chrome');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
getBrowserDownloadUrl(majorVersion) {
|
|
124
|
+
const os = (0, _common.getOS)();
|
|
125
|
+
switch (os) {
|
|
126
|
+
case 'mac':
|
|
127
|
+
return `https://orbita-browser-mac.gologin.com/orbita-browser-latest-${majorVersion}.tar.gz`;
|
|
128
|
+
case 'win':
|
|
129
|
+
return `https://orbita-browser-windows.gologin.com/orbita-browser-latest-${majorVersion}.zip`;
|
|
130
|
+
case 'macM1':
|
|
131
|
+
return `https://orbita-browser-mac-arm.gologin.com/orbita-browser-latest-${majorVersion}.tar.gz`;
|
|
132
|
+
default:
|
|
133
|
+
return `https://orbita-browser-linux.gologin.com/orbita-browser-latest-${majorVersion}.tar.gz`;
|
|
134
|
+
}
|
|
120
135
|
}
|
|
121
136
|
addLatestVersion(latestVersion) {
|
|
122
|
-
return mkdir((0, _path.join)(this
|
|
137
|
+
return mkdir((0, _path.join)(this.browserPath, 'orbita-browser', 'version'), {
|
|
123
138
|
recursive: true
|
|
124
|
-
}).then(() => writeFile((0, _path.join)(this
|
|
139
|
+
}).then(() => writeFile((0, _path.join)(this.browserPath, 'orbita-browser', 'version', 'latest-version.txt'), latestVersion));
|
|
125
140
|
}
|
|
126
|
-
downloadBrowserArchive(link, pathStr) {
|
|
141
|
+
async downloadBrowserArchive(link, pathStr) {
|
|
127
142
|
return new Promise((resolve, reject) => {
|
|
128
143
|
const writableStream = (0, _fs.createWriteStream)(pathStr);
|
|
129
144
|
writableStream.on('error', async err => {
|
|
@@ -136,6 +151,10 @@ class BrowserChecker {
|
|
|
136
151
|
}, res => {
|
|
137
152
|
const len = parseInt(res.headers['content-length'], 10);
|
|
138
153
|
const formattedLen = len / 1024 / 1024;
|
|
154
|
+
if (isNaN(formattedLen)) {
|
|
155
|
+
reject(new Error('Error downloading browser'));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
139
158
|
const bar = new _progress.default('Orbita downloading [:bar] :rate/mps :downloadedMb/:fullMbMB :percent :etas', {
|
|
140
159
|
complete: '=',
|
|
141
160
|
incomplete: ' ',
|
|
@@ -175,26 +194,26 @@ class BrowserChecker {
|
|
|
175
194
|
}
|
|
176
195
|
async extractBrowser() {
|
|
177
196
|
console.log('Extracting Orbita');
|
|
178
|
-
await mkdir((0, _path.join)(this
|
|
197
|
+
await mkdir((0, _path.join)(this.browserPath, EXTRACTED_FOLDER), {
|
|
179
198
|
recursive: true
|
|
180
199
|
});
|
|
181
200
|
if (PLATFORM === 'win32') {
|
|
182
|
-
return (0, _decompress.default)((0, _path.join)(this
|
|
201
|
+
return (0, _decompress.default)((0, _path.join)(this.browserPath, BROWSER_ARCHIVE_NAME), (0, _path.join)(this.browserPath, EXTRACTED_FOLDER), {
|
|
183
202
|
plugins: [(0, _decompressUnzip.default)()],
|
|
184
203
|
filter: file => !file.path.endsWith('/')
|
|
185
204
|
});
|
|
186
205
|
}
|
|
187
|
-
return exec(`tar xzf ${(0, _path.join)(this
|
|
206
|
+
return exec(`tar xzf ${(0, _path.join)(this.browserPath, BROWSER_ARCHIVE_NAME)} --directory ${(0, _path.join)(this.browserPath, EXTRACTED_FOLDER)}`);
|
|
188
207
|
}
|
|
189
208
|
async downloadHashFile(latestVersion) {
|
|
190
209
|
let hashLink = DEB_HASHFILE_LINK;
|
|
191
|
-
let resultPath = (0, _path.join)(this
|
|
210
|
+
let resultPath = (0, _path.join)(this.browserPath, DEB_HASH_FILE);
|
|
192
211
|
if (PLATFORM === 'darwin') {
|
|
193
212
|
hashLink = MAC_HASHFILE_LINK;
|
|
194
213
|
if (ARCH === 'arm64') {
|
|
195
214
|
hashLink = MAC_ARM_HASHFILE_LINK;
|
|
196
215
|
}
|
|
197
|
-
resultPath = (0, _path.join)(this
|
|
216
|
+
resultPath = (0, _path.join)(this.browserPath, MAC_HASH_FILE);
|
|
198
217
|
}
|
|
199
218
|
if (latestVersion) {
|
|
200
219
|
const [majorVer] = latestVersion.split('.');
|
|
@@ -216,11 +235,11 @@ class BrowserChecker {
|
|
|
216
235
|
res.pipe(writableStream);
|
|
217
236
|
}).on('error', err => writableStream.destroy(err)));
|
|
218
237
|
const hashFile = PLATFORM === 'darwin' ? MAC_HASH_FILE : DEB_HASH_FILE;
|
|
219
|
-
const hashFilePath = (0, _path.join)(this
|
|
238
|
+
const hashFilePath = (0, _path.join)(this.browserPath, hashFile);
|
|
220
239
|
return access(hashFilePath);
|
|
221
240
|
}
|
|
222
241
|
async checkBrowserSum(latestVersion) {
|
|
223
|
-
if (this
|
|
242
|
+
if (this.skipOrbitaHashChecking) {
|
|
224
243
|
return Promise.resolve();
|
|
225
244
|
}
|
|
226
245
|
console.log('Orbita hash checking');
|
|
@@ -229,50 +248,41 @@ class BrowserChecker {
|
|
|
229
248
|
}
|
|
230
249
|
await this.downloadHashFile(latestVersion);
|
|
231
250
|
if (PLATFORM === 'darwin') {
|
|
232
|
-
const calculatedHash = await exec(`mtree -p ${(0, _path.join)(this
|
|
251
|
+
const calculatedHash = await exec(`mtree -p ${(0, _path.join)(this.browserPath, EXTRACTED_FOLDER, 'Orbita-Browser.app')} < ${(0, _path.join)(this.browserPath, MAC_HASH_FILE)} || echo ${FAIL_SUM_MATCH_MESSAGE}`);
|
|
233
252
|
const checkedRes = (calculatedHash || '').toString().trim();
|
|
234
253
|
if (checkedRes.includes(FAIL_SUM_MATCH_MESSAGE)) {
|
|
235
254
|
throw new Error('Error in sum matching. Please run script again.');
|
|
236
255
|
}
|
|
237
256
|
return;
|
|
238
257
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
// }
|
|
258
|
+
const hashFileContent = await exec(`cat ${(0, _path.join)(this.browserPath, DEB_HASH_FILE)}`);
|
|
259
|
+
let serverRes = (hashFileContent.stdout || '').toString().trim();
|
|
260
|
+
serverRes = serverRes.split(' ')[0];
|
|
261
|
+
const calculateLocalBrowserHash = await exec(`cd ${(0, _path.join)(this.browserPath, EXTRACTED_FOLDER)} && find orbita-browser -type f -print0 | sort -z | \
|
|
262
|
+
xargs -0 sha256sum > ${this.browserPath}/calculatedFolderSha.txt`);
|
|
263
|
+
const localHashContent = await exec(`cd ${this.browserPath} && sha256sum calculatedFolderSha.txt`);
|
|
264
|
+
let userRes = (localHashContent.stdout || '').toString().trim();
|
|
265
|
+
userRes = userRes.split(' ')[0];
|
|
266
|
+
if (userRes !== serverRes) {
|
|
267
|
+
throw new Error('Error in sum matching. Please run script again.');
|
|
268
|
+
}
|
|
256
269
|
}
|
|
257
|
-
async replaceBrowser() {
|
|
270
|
+
async replaceBrowser(majorVersion) {
|
|
258
271
|
console.log('Copy Orbita to target path');
|
|
272
|
+
const targetBrowserPath = (0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`);
|
|
273
|
+
await this.deleteDir(targetBrowserPath);
|
|
259
274
|
if (PLATFORM === 'darwin') {
|
|
260
|
-
return rename((0, _path.join)(this
|
|
275
|
+
return rename((0, _path.join)(this.browserPath, EXTRACTED_FOLDER), targetBrowserPath);
|
|
261
276
|
}
|
|
262
|
-
|
|
263
|
-
await this.deleteDir(targetBrowserPath);
|
|
264
|
-
await this.copyDir((0, _path.join)(this.#browserPath, EXTRACTED_FOLDER, 'orbita-browser'), targetBrowserPath);
|
|
277
|
+
await this.copyDir((0, _path.join)(this.browserPath, EXTRACTED_FOLDER, 'orbita-browser'), targetBrowserPath);
|
|
265
278
|
}
|
|
266
|
-
async deleteOldArchives(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
await this.deleteDir((0, _path.join)(this.#browserPath, EXTRACTED_FOLDER));
|
|
271
|
-
return readdir(this.#browserPath).then(files => {
|
|
279
|
+
async deleteOldArchives() {
|
|
280
|
+
await this.deleteDir((0, _path.join)(this.browserPath, EXTRACTED_FOLDER));
|
|
281
|
+
return readdir(this.browserPath).then(files => {
|
|
272
282
|
const promises = [];
|
|
273
283
|
files.forEach(filename => {
|
|
274
284
|
if (filename.match(/(txt|dylib|mtree)/)) {
|
|
275
|
-
promises.push(unlink((0, _path.join)(this
|
|
285
|
+
promises.push(unlink((0, _path.join)(this.browserPath, filename)));
|
|
276
286
|
}
|
|
277
287
|
});
|
|
278
288
|
return Promise.all(promises);
|
|
@@ -296,14 +306,12 @@ class BrowserChecker {
|
|
|
296
306
|
}
|
|
297
307
|
}
|
|
298
308
|
}
|
|
299
|
-
getCurrentVersion() {
|
|
300
|
-
let
|
|
301
|
-
if (PLATFORM === '
|
|
302
|
-
|
|
303
|
-
} else if (PLATFORM === 'darwin') {
|
|
304
|
-
command = `if [ -f ${(0, _path.join)(this.#browserPath, 'orbita-browser', 'version', VERSION_FILE)} ]; then cat ${(0, _path.join)(this.#browserPath, 'orbita-browser', 'version', VERSION_FILE)}; else echo 0.0.0; fi`;
|
|
309
|
+
async getCurrentVersion(majorVersion) {
|
|
310
|
+
let versionFilePath = (0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`, 'version');
|
|
311
|
+
if (PLATFORM === 'darwin') {
|
|
312
|
+
versionFilePath = (0, _path.join)(this.browserPath, `orbita-browser-${majorVersion}`, 'version', VERSION_FILE);
|
|
305
313
|
}
|
|
306
|
-
return
|
|
314
|
+
return (await readFile(versionFilePath, 'utf8').catch(() => '0.0.0')).replace(/[\r\n\t\f\v\x00-\x1F\x7F]/g, '');
|
|
307
315
|
}
|
|
308
316
|
getLatestBrowserVersion() {
|
|
309
317
|
const userOs = (0, _common.getOS)();
|
|
@@ -323,7 +331,7 @@ class BrowserChecker {
|
|
|
323
331
|
}).on('error', err => resolve('')));
|
|
324
332
|
}
|
|
325
333
|
get getOrbitaPath() {
|
|
326
|
-
return this
|
|
334
|
+
return this.executableFilePath;
|
|
327
335
|
}
|
|
328
336
|
async deleteDir(path = '') {
|
|
329
337
|
if (!path) {
|