gologin 2.1.7 → 2.1.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 +1 -1
- package/src/cookies/cookies-manager.js +7 -0
- package/src/gologin.js +12 -13
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';
|
|
@@ -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
|
]);
|
|
@@ -609,6 +610,7 @@ export class GoLogin {
|
|
|
609
610
|
gologin.screenHeight = this.resolution.height;
|
|
610
611
|
debug('writeCookiesFromServer', this.writeCookiesFromServer);
|
|
611
612
|
this.cookiesFilePath = await getCookiesFilePath(this.profile_id, this.tmpdir);
|
|
613
|
+
|
|
612
614
|
if (this.writeCookiesFromServer) {
|
|
613
615
|
await this.writeCookiesToFile(profile.cookies?.cookies);
|
|
614
616
|
}
|
|
@@ -1360,25 +1362,22 @@ export class GoLogin {
|
|
|
1360
1362
|
const resultCookies = cookies.map((el) => ({ ...el, value: Buffer.from(el.value) }));
|
|
1361
1363
|
let db;
|
|
1362
1364
|
const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
|
|
1363
|
-
|
|
1365
|
+
|
|
1364
1366
|
const defaultFilePath = _resolve(profilePath, 'Default');
|
|
1365
|
-
const cookiesFilePath = _resolve(defaultFilePath, '
|
|
1366
|
-
const secondCookiesFilePath = _resolve(defaultFilePath, 'Cookies');
|
|
1367
|
+
const cookiesFilePath = _resolve(defaultFilePath, 'Cookies');
|
|
1368
|
+
const secondCookiesFilePath = _resolve(defaultFilePath, 'Network', 'Cookies');
|
|
1367
1369
|
try {
|
|
1368
1370
|
db = await getDB(cookiesFilePath, false);
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1371
|
+
const cookiesToInsert = await getUniqueCookies(resultCookies, cookiesFilePath);
|
|
1372
|
+
// console.log('cookiesToInsert', cookiesToInsert);
|
|
1373
|
+
if (cookiesToInsert.length) {
|
|
1374
|
+
const chunckInsertValues = getChunckedInsertValues(cookiesToInsert);
|
|
1375
|
+
console.log('chunckInsertValues', chunckInsertValues);
|
|
1372
1376
|
for (const [query, queryParams] of chunckInsertValues) {
|
|
1373
1377
|
const insertStmt = await db.prepare(query);
|
|
1374
1378
|
await insertStmt.run(queryParams);
|
|
1375
1379
|
await insertStmt.finalize();
|
|
1376
1380
|
}
|
|
1377
|
-
} else {
|
|
1378
|
-
const query = 'delete from cookies';
|
|
1379
|
-
const insertStmt = await db.prepare(query);
|
|
1380
|
-
await insertStmt.run();
|
|
1381
|
-
await insertStmt.finalize();
|
|
1382
1381
|
}
|
|
1383
1382
|
} catch (error) {
|
|
1384
1383
|
console.log(error.message);
|