gologin 2.1.17 → 2.1.18
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 +23 -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);
|
|
@@ -1383,7 +1385,7 @@ export class GoLogin {
|
|
|
1383
1385
|
return { primary, secondary };
|
|
1384
1386
|
}
|
|
1385
1387
|
|
|
1386
|
-
async writeCookiesToFile(cookies) {
|
|
1388
|
+
async writeCookiesToFile(cookies, isSecondTry = false) {
|
|
1387
1389
|
if (!cookies) {
|
|
1388
1390
|
cookies = await this.getCookies(this.profile_id);
|
|
1389
1391
|
}
|
|
@@ -1410,10 +1412,26 @@ export class GoLogin {
|
|
|
1410
1412
|
}
|
|
1411
1413
|
}
|
|
1412
1414
|
} catch (error) {
|
|
1413
|
-
|
|
1415
|
+
if (!isSecondTry && (error.message.includes('table cookies has no column') || error.message.includes('NOT NULL constraint failed'))) {
|
|
1416
|
+
await _promises.rm(cookiesPaths.primary, { recursive: true, force: true });
|
|
1417
|
+
await createDBFile({
|
|
1418
|
+
cookiesFilePath: cookiesPaths.primary,
|
|
1419
|
+
cookiesFileSecondPath: cookiesPaths.secondary,
|
|
1420
|
+
createCookiesTableQuery: this.createCookiesTableQuery,
|
|
1421
|
+
});
|
|
1422
|
+
await this.writeCookiesToFile(cookies, true);
|
|
1423
|
+
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
console.error(error.message);
|
|
1414
1428
|
} finally {
|
|
1415
1429
|
db && await db.close();
|
|
1416
|
-
await
|
|
1430
|
+
await ensureDirectoryExists(cookiesPaths.primary);
|
|
1431
|
+
await ensureDirectoryExists(cookiesPaths.secondary);
|
|
1432
|
+
await copyFile(cookiesPaths.primary, cookiesPaths.secondary).catch((error) => {
|
|
1433
|
+
console.error('error in copyFile', error.message);
|
|
1434
|
+
});
|
|
1417
1435
|
}
|
|
1418
1436
|
}
|
|
1419
1437
|
|
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)) {
|