gologin 2.0.5 → 2.0.7
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,13 +1,17 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
2
|
import { createWriteStream, promises as _promises, rmdirSync } from 'fs';
|
|
3
3
|
import { homedir, tmpdir } from 'os';
|
|
4
|
-
import { join, resolve, sep } from 'path';
|
|
4
|
+
import { join, resolve, sep, dirname } from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
5
6
|
import requestretry from 'requestretry';
|
|
6
7
|
|
|
7
8
|
import { fontsCollection } from '../../fonts.js';
|
|
8
9
|
|
|
9
10
|
const { access, readFile, writeFile, mkdir, readdir, copyFile, rename } = _promises;
|
|
10
11
|
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
14
|
+
|
|
11
15
|
const FONTS_URL = 'https://fonts.gologin.com/';
|
|
12
16
|
const FONTS_DIR_NAME = 'fonts';
|
|
13
17
|
|
|
@@ -115,7 +119,7 @@ export const copyFontsConfigFile = async (profilePath) => {
|
|
|
115
119
|
return;
|
|
116
120
|
}
|
|
117
121
|
|
|
118
|
-
const fileContent = await readFile(resolve(__dirname, 'fonts_config'), 'utf-8');
|
|
122
|
+
const fileContent = await readFile(resolve(__dirname, '..', '..', 'fonts_config'), 'utf-8');
|
|
119
123
|
const result = fileContent.replace(/\$\$GOLOGIN_FONTS\$\$/g, join(profilePath, FONTS_DIR_NAME));
|
|
120
124
|
|
|
121
125
|
const defaultFolderPath = join(profilePath, 'Default');
|
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,8 +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
23
|
|
|
25
24
|
const exec = util.promisify(execNonPromise);
|
|
26
25
|
|
|
@@ -644,27 +643,27 @@ export class GoLogin {
|
|
|
644
643
|
debug('CHECKING PORT AVAILABLE', port);
|
|
645
644
|
|
|
646
645
|
try {
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
649
|
-
debug(`PORT ${port} IS
|
|
646
|
+
const portAvailable = await isPortReachable(port, { host: 'localhost' });
|
|
647
|
+
if (portAvailable) {
|
|
648
|
+
debug(`PORT ${port} IS OPEN`);
|
|
650
649
|
|
|
651
|
-
return
|
|
650
|
+
return true;
|
|
652
651
|
}
|
|
653
652
|
} catch (e) {
|
|
654
653
|
console.log(e);
|
|
655
654
|
}
|
|
656
655
|
|
|
657
|
-
debug(`PORT ${port} IS
|
|
656
|
+
debug(`PORT ${port} IS BUSY`);
|
|
658
657
|
|
|
659
|
-
return
|
|
658
|
+
return false;
|
|
660
659
|
}
|
|
661
660
|
|
|
662
661
|
async getRandomPort() {
|
|
663
662
|
let port = this.getRandomInt(20000, 40000);
|
|
664
|
-
let
|
|
665
|
-
while (!
|
|
663
|
+
let portAvailable = await this.checkPortAvailable(port);
|
|
664
|
+
while (!portAvailable) {
|
|
666
665
|
port = this.getRandomInt(20000, 40000);
|
|
667
|
-
|
|
666
|
+
portAvailable = await this.checkPortAvailable(port);
|
|
668
667
|
}
|
|
669
668
|
|
|
670
669
|
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
|
+
|