gologin 2.0.6 → 2.0.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.
package/package.json
CHANGED
package/src/gologin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execFile, spawn } from 'child_process';
|
|
2
2
|
import debug from 'debug';
|
|
3
3
|
import decompress from 'decompress';
|
|
4
4
|
import decompressUnzip from 'decompress-unzip';
|
|
@@ -9,7 +9,6 @@ import { join, resolve as _resolve,sep } from 'path';
|
|
|
9
9
|
import requests from 'requestretry';
|
|
10
10
|
import rimraf from 'rimraf';
|
|
11
11
|
import ProxyAgent from 'simple-proxy-agent';
|
|
12
|
-
import util from 'util';
|
|
13
12
|
|
|
14
13
|
import { fontsCollection } from '../fonts.js';
|
|
15
14
|
import { updateProfileProxy, updateProfileResolution, updateProfileUserAgent } from './browser/browser-api.js';
|
|
@@ -19,10 +18,8 @@ import { composeFonts, downloadCookies, setExtPathsAndRemoveDeleted,
|
|
|
19
18
|
import { getChunckedInsertValues, getDB, loadCookiesFromFile } from './cookies/cookies-manager.js';
|
|
20
19
|
import ExtensionsManager from './extensions/extensions-manager.js';
|
|
21
20
|
import { archiveProfile } from './profile/profile-archiver.js';
|
|
21
|
+
import { get, isPortReachable } from './utils/utils.js';
|
|
22
22
|
import { API_URL } from './utils/common.js';
|
|
23
|
-
import { get } from './utils/utils.js';
|
|
24
|
-
|
|
25
|
-
const exec = util.promisify(execNonPromise);
|
|
26
23
|
|
|
27
24
|
const { access, unlink, writeFile, readFile } = _promises;
|
|
28
25
|
|
|
@@ -644,27 +641,27 @@ export class GoLogin {
|
|
|
644
641
|
debug('CHECKING PORT AVAILABLE', port);
|
|
645
642
|
|
|
646
643
|
try {
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
649
|
-
debug(`PORT ${port} IS
|
|
644
|
+
const portAvailable = await isPortReachable(port, { host: 'localhost' });
|
|
645
|
+
if (portAvailable) {
|
|
646
|
+
debug(`PORT ${port} IS OPEN`);
|
|
650
647
|
|
|
651
|
-
return
|
|
648
|
+
return true;
|
|
652
649
|
}
|
|
653
650
|
} catch (e) {
|
|
654
651
|
console.log(e);
|
|
655
652
|
}
|
|
656
653
|
|
|
657
|
-
debug(`PORT ${port} IS
|
|
654
|
+
debug(`PORT ${port} IS BUSY`);
|
|
658
655
|
|
|
659
|
-
return
|
|
656
|
+
return false;
|
|
660
657
|
}
|
|
661
658
|
|
|
662
659
|
async getRandomPort() {
|
|
663
660
|
let port = this.getRandomInt(20000, 40000);
|
|
664
|
-
let
|
|
665
|
-
while (!
|
|
661
|
+
let portAvailable = await this.checkPortAvailable(port);
|
|
662
|
+
while (!portAvailable) {
|
|
666
663
|
port = this.getRandomInt(20000, 40000);
|
|
667
|
-
|
|
664
|
+
portAvailable = await this.checkPortAvailable(port);
|
|
668
665
|
}
|
|
669
666
|
|
|
670
667
|
return port;
|
|
@@ -14,7 +14,12 @@ export const archiveProfile = async (profileFolder = '', tryAgain = true) => {
|
|
|
14
14
|
|
|
15
15
|
const archive = new AdmZip();
|
|
16
16
|
archive.addLocalFolder(path.join(profileFolder, 'Default'), 'Default');
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
archive.addLocalFile(path.join(profileFolder, 'First Run'));
|
|
19
|
+
} catch(e) {
|
|
20
|
+
archive.addFile('First Run', Buffer.from(''));
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
const dirsToRemove = getDirectoriesForArchiver();
|
|
19
24
|
dirsToRemove.forEach(entry => archive.deleteFile(entry));
|
|
20
25
|
|
package/src/utils/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
2
|
+
|
|
1
3
|
export const get = (value, path, defaultValue) =>
|
|
2
4
|
String(path).split('.').reduce((acc, v) => {
|
|
3
5
|
try {
|
|
@@ -9,3 +11,12 @@ export const get = (value, path, defaultValue) =>
|
|
|
9
11
|
return acc;
|
|
10
12
|
}, value);
|
|
11
13
|
|
|
14
|
+
export const isPortReachable = (port) => new Promise(resolve => {
|
|
15
|
+
const checker = net.createServer()
|
|
16
|
+
.once('error', () => {
|
|
17
|
+
resolve(false);
|
|
18
|
+
})
|
|
19
|
+
.once('listening', () => checker.once('close', () => resolve(true)).close())
|
|
20
|
+
.listen(port);
|
|
21
|
+
});
|
|
22
|
+
|