gologin 2.1.7 → 2.1.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/package.json +1 -1
- package/src/cookies/cookies-manager.js +7 -0
- package/src/gologin.js +16 -15
package/package.json
CHANGED
|
@@ -57,6 +57,13 @@ export const createDBFile = async ({
|
|
|
57
57
|
cookiesFileSecondPath && await fsPromises.copyFile(cookiesFilePath, cookiesFileSecondPath).catch(console.log);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
+
export const getUniqueCookies = async (cookiesArr, cookiesFilePath) => {
|
|
61
|
+
const cookiesInFile = await loadCookiesFromFile(cookiesFilePath);
|
|
62
|
+
const existingCookieNames = new Set(cookiesInFile.map(c => `${c.name}-${c.value.toString('base64')}`));
|
|
63
|
+
|
|
64
|
+
return cookiesArr.filter(cookie => !existingCookieNames.has(`${cookie.name}-${cookie.value.toString('base64')}`));
|
|
65
|
+
};
|
|
66
|
+
|
|
60
67
|
export const getChunckedInsertValues = (cookiesArr) => {
|
|
61
68
|
const todayUnix = Math.floor(new Date().getTime() / 1000.0);
|
|
62
69
|
const chunckedCookiesArr = chunk(cookiesArr, MAX_SQLITE_VARIABLES);
|
package/src/gologin.js
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
getChunckedInsertValues,
|
|
23
23
|
getCookiesFilePath,
|
|
24
24
|
getDB,
|
|
25
|
+
getUniqueCookies,
|
|
25
26
|
loadCookiesFromFile,
|
|
26
27
|
} from './cookies/cookies-manager.js';
|
|
27
28
|
import ExtensionsManager from './extensions/extensions-manager.js';
|
|
@@ -59,7 +60,7 @@ export class GoLogin {
|
|
|
59
60
|
this.profileOs = 'lin';
|
|
60
61
|
this.waitWebsocket = options.waitWebsocket ?? true;
|
|
61
62
|
this.isEmptyFonts = false;
|
|
62
|
-
|
|
63
|
+
this.isFirstSession = false;
|
|
63
64
|
this.isCloudHeadless = options.isCloudHeadless ?? true;
|
|
64
65
|
|
|
65
66
|
this.tmpdir = tmpdir();
|
|
@@ -397,7 +398,7 @@ export class GoLogin {
|
|
|
397
398
|
const preferencesFilePath = _resolve(defaultFilePath, 'Preferences');
|
|
398
399
|
const bookmarksFilePath = _resolve(defaultFilePath, 'Bookmarks');
|
|
399
400
|
const cookiesFilePath = _resolve(defaultFilePath, 'Network', 'Cookies');
|
|
400
|
-
const
|
|
401
|
+
const cookiesFileSecondPath = _resolve(defaultFilePath, 'Cookies');
|
|
401
402
|
|
|
402
403
|
await mkdir(_resolve(defaultFilePath, 'Network'), { recursive: true }).catch(console.log);
|
|
403
404
|
|
|
@@ -406,7 +407,7 @@ export class GoLogin {
|
|
|
406
407
|
writeFile(bookmarksFilePath, JSON.stringify(zeroProfileBookmarks), { mode: 0o666 }),
|
|
407
408
|
createDBFile({
|
|
408
409
|
cookiesFilePath,
|
|
409
|
-
|
|
410
|
+
cookiesFileSecondPath,
|
|
410
411
|
createCookiesTableQuery,
|
|
411
412
|
}),
|
|
412
413
|
]);
|
|
@@ -439,8 +440,10 @@ export class GoLogin {
|
|
|
439
440
|
height: parseInt(screenHeight, 10),
|
|
440
441
|
};
|
|
441
442
|
if (profile.storageInfo.isNewProfile) {
|
|
443
|
+
this.isFirstSession = true;
|
|
442
444
|
await this.createZeroProfile(profile.createCookiesTableQuery);
|
|
443
445
|
} else {
|
|
446
|
+
this.isFirstSession = false;
|
|
444
447
|
await this.downloadProfileAndExtract(profile, local);
|
|
445
448
|
}
|
|
446
449
|
|
|
@@ -609,6 +612,7 @@ export class GoLogin {
|
|
|
609
612
|
gologin.screenHeight = this.resolution.height;
|
|
610
613
|
debug('writeCookiesFromServer', this.writeCookiesFromServer);
|
|
611
614
|
this.cookiesFilePath = await getCookiesFilePath(this.profile_id, this.tmpdir);
|
|
615
|
+
|
|
612
616
|
if (this.writeCookiesFromServer) {
|
|
613
617
|
await this.writeCookiesToFile(profile.cookies?.cookies);
|
|
614
618
|
}
|
|
@@ -922,7 +926,7 @@ export class GoLogin {
|
|
|
922
926
|
params = params.concat(this.extra_params);
|
|
923
927
|
}
|
|
924
928
|
|
|
925
|
-
if (this.restoreLastSession) {
|
|
929
|
+
if (!this.isFirstSession && this.restoreLastSession) {
|
|
926
930
|
params.push('--restore-last-session');
|
|
927
931
|
}
|
|
928
932
|
|
|
@@ -1360,25 +1364,22 @@ export class GoLogin {
|
|
|
1360
1364
|
const resultCookies = cookies.map((el) => ({ ...el, value: Buffer.from(el.value) }));
|
|
1361
1365
|
let db;
|
|
1362
1366
|
const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
|
|
1363
|
-
|
|
1367
|
+
|
|
1364
1368
|
const defaultFilePath = _resolve(profilePath, 'Default');
|
|
1365
|
-
const cookiesFilePath = _resolve(defaultFilePath, '
|
|
1366
|
-
const secondCookiesFilePath = _resolve(defaultFilePath, 'Cookies');
|
|
1369
|
+
const cookiesFilePath = _resolve(defaultFilePath, 'Cookies');
|
|
1370
|
+
const secondCookiesFilePath = _resolve(defaultFilePath, 'Network', 'Cookies');
|
|
1367
1371
|
try {
|
|
1368
1372
|
db = await getDB(cookiesFilePath, false);
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1373
|
+
const cookiesToInsert = await getUniqueCookies(resultCookies, cookiesFilePath);
|
|
1374
|
+
// console.log('cookiesToInsert', cookiesToInsert);
|
|
1375
|
+
if (cookiesToInsert.length) {
|
|
1376
|
+
const chunckInsertValues = getChunckedInsertValues(cookiesToInsert);
|
|
1377
|
+
console.log('chunckInsertValues', chunckInsertValues);
|
|
1372
1378
|
for (const [query, queryParams] of chunckInsertValues) {
|
|
1373
1379
|
const insertStmt = await db.prepare(query);
|
|
1374
1380
|
await insertStmt.run(queryParams);
|
|
1375
1381
|
await insertStmt.finalize();
|
|
1376
1382
|
}
|
|
1377
|
-
} else {
|
|
1378
|
-
const query = 'delete from cookies';
|
|
1379
|
-
const insertStmt = await db.prepare(query);
|
|
1380
|
-
await insertStmt.run();
|
|
1381
|
-
await insertStmt.finalize();
|
|
1382
1383
|
}
|
|
1383
1384
|
} catch (error) {
|
|
1384
1385
|
console.log(error.message);
|