gologin 2.1.17 → 2.1.19
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 +1 -1
- package/src/cookies/cookies-manager.js +7 -1
- package/src/gologin.js +24 -5
- package/src/utils/common.js +12 -0
package/package.json
CHANGED
|
@@ -3,6 +3,8 @@ import { join } from 'path';
|
|
|
3
3
|
import { open } from 'sqlite';
|
|
4
4
|
import sqlite3 from 'sqlite3';
|
|
5
5
|
|
|
6
|
+
import { ensureDirectoryExists } from '../utils/common.js';
|
|
7
|
+
|
|
6
8
|
const { access } = fsPromises;
|
|
7
9
|
const { Database, OPEN_READONLY } = sqlite3;
|
|
8
10
|
|
|
@@ -44,7 +46,11 @@ export const createDBFile = async ({
|
|
|
44
46
|
await db.run(createCookiesTableQuery);
|
|
45
47
|
await db.close();
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
await ensureDirectoryExists(cookiesFilePath);
|
|
50
|
+
await ensureDirectoryExists(cookiesFileSecondPath);
|
|
51
|
+
cookiesFileSecondPath && await fsPromises.copyFile(cookiesFilePath, cookiesFileSecondPath).catch((error) => {
|
|
52
|
+
console.error('error in copyFile createDBFile', error.message);
|
|
53
|
+
});
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
export const getUniqueCookies = async (cookiesArr, cookiesFilePath) => {
|
package/src/gologin.js
CHANGED
|
@@ -2,7 +2,7 @@ import { execFile, spawn } from 'child_process';
|
|
|
2
2
|
import debugDefault from 'debug';
|
|
3
3
|
import decompress from 'decompress';
|
|
4
4
|
import decompressUnzip from 'decompress-unzip';
|
|
5
|
-
import { existsSync, mkdirSync,promises as _promises } from 'fs';
|
|
5
|
+
import { existsSync, mkdirSync, promises as _promises } from 'fs';
|
|
6
6
|
import { get as _get } from 'https';
|
|
7
7
|
import { tmpdir } from 'os';
|
|
8
8
|
import { dirname, join, resolve as _resolve, sep } from 'path';
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
import ExtensionsManager from './extensions/extensions-manager.js';
|
|
30
30
|
import { archiveProfile } from './profile/profile-archiver.js';
|
|
31
31
|
import { checkAutoLang } from './utils/browser.js';
|
|
32
|
-
import { API_URL, getOsAdvanced } from './utils/common.js';
|
|
32
|
+
import { API_URL, ensureDirectoryExists, getOsAdvanced } from './utils/common.js';
|
|
33
33
|
import { STORAGE_GATEWAY_BASE_URL } from './utils/constants.js';
|
|
34
34
|
import { get, isPortReachable } from './utils/utils.js';
|
|
35
35
|
export { exitAll, GologinApi } from './gologin-api.js';
|
|
@@ -493,6 +493,8 @@ export class GoLogin {
|
|
|
493
493
|
width: parseInt(screenWidth, 10),
|
|
494
494
|
height: parseInt(screenHeight, 10),
|
|
495
495
|
};
|
|
496
|
+
|
|
497
|
+
this.createCookiesTableQuery = profile.createCookiesTableQuery;
|
|
496
498
|
if (profile.storageInfo.isNewProfile) {
|
|
497
499
|
this.isFirstSession = true;
|
|
498
500
|
await this.createZeroProfile(profile.createCookiesTableQuery);
|
|
@@ -507,6 +509,7 @@ export class GoLogin {
|
|
|
507
509
|
const prefFileExists = await access(pref_file_name).then(() => true).catch(() => false);
|
|
508
510
|
if (!prefFileExists) {
|
|
509
511
|
debug('Preferences file not exists waiting', pref_file_name, '. Using empty profile');
|
|
512
|
+
await mkdir(join(profilePath, 'Default'), { recursive: true });
|
|
510
513
|
await writeFile(pref_file_name, '{}');
|
|
511
514
|
}
|
|
512
515
|
|
|
@@ -1383,7 +1386,7 @@ export class GoLogin {
|
|
|
1383
1386
|
return { primary, secondary };
|
|
1384
1387
|
}
|
|
1385
1388
|
|
|
1386
|
-
async writeCookiesToFile(cookies) {
|
|
1389
|
+
async writeCookiesToFile(cookies, isSecondTry = false) {
|
|
1387
1390
|
if (!cookies) {
|
|
1388
1391
|
cookies = await this.getCookies(this.profile_id);
|
|
1389
1392
|
}
|
|
@@ -1410,10 +1413,26 @@ export class GoLogin {
|
|
|
1410
1413
|
}
|
|
1411
1414
|
}
|
|
1412
1415
|
} catch (error) {
|
|
1413
|
-
|
|
1416
|
+
if (!isSecondTry && (error.message.includes('table cookies has no column') || error.message.includes('NOT NULL constraint failed'))) {
|
|
1417
|
+
await _promises.rm(cookiesPaths.primary, { recursive: true, force: true });
|
|
1418
|
+
await createDBFile({
|
|
1419
|
+
cookiesFilePath: cookiesPaths.primary,
|
|
1420
|
+
cookiesFileSecondPath: cookiesPaths.secondary,
|
|
1421
|
+
createCookiesTableQuery: this.createCookiesTableQuery,
|
|
1422
|
+
});
|
|
1423
|
+
await this.writeCookiesToFile(cookies, true);
|
|
1424
|
+
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
console.error(error.message);
|
|
1414
1429
|
} finally {
|
|
1415
1430
|
db && await db.close();
|
|
1416
|
-
await
|
|
1431
|
+
await ensureDirectoryExists(cookiesPaths.primary);
|
|
1432
|
+
await ensureDirectoryExists(cookiesPaths.secondary);
|
|
1433
|
+
await copyFile(cookiesPaths.primary, cookiesPaths.secondary).catch((error) => {
|
|
1434
|
+
console.error('error in copyFile', error.message);
|
|
1435
|
+
});
|
|
1417
1436
|
}
|
|
1418
1437
|
}
|
|
1419
1438
|
|
package/src/utils/common.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { exec } from 'child_process';
|
|
2
|
+
import { promises as fsPromises } from 'fs';
|
|
2
3
|
import { homedir } from 'os';
|
|
3
4
|
import { join, sep } from 'path';
|
|
4
5
|
import { promisify } from 'util';
|
|
@@ -34,6 +35,17 @@ const getMacArmSpec = async () => {
|
|
|
34
35
|
return armVersion;
|
|
35
36
|
};
|
|
36
37
|
|
|
38
|
+
export const ensureDirectoryExists = async (filePath) => {
|
|
39
|
+
try {
|
|
40
|
+
const directory = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
41
|
+
await fsPromises.mkdir(directory, { recursive: true });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error.code !== 'EEXIST') {
|
|
44
|
+
console.error('Error creating directory:', error.message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
37
49
|
const getOsAdvanced = async () => {
|
|
38
50
|
const os = getOS();
|
|
39
51
|
if (!['mac', 'macM1'].includes(os)) {
|