gologin 2.1.10 → 2.1.11
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/gologin.js +22 -12
package/package.json
CHANGED
package/src/gologin.js
CHANGED
|
@@ -194,23 +194,24 @@ export class GoLogin {
|
|
|
194
194
|
const token = this.access_token;
|
|
195
195
|
debug('getProfileS3 token=', token, 'profile=', this.profile_id);
|
|
196
196
|
const downloadURL = `${STORAGE_GATEWAY_BASE_URL}/download`;
|
|
197
|
-
|
|
198
197
|
debug('loading profile from public s3 bucket, url=', downloadURL);
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
|
|
199
|
+
const profileResponse = await fetch(downloadURL, {
|
|
201
200
|
headers: {
|
|
202
201
|
Authorization: `Bearer ${token}`,
|
|
203
202
|
browserId: this.profile_id,
|
|
204
203
|
},
|
|
205
204
|
});
|
|
206
205
|
|
|
207
|
-
|
|
206
|
+
const profileResponseBody = await profileResponse.arrayBuffer();
|
|
207
|
+
|
|
208
|
+
if (profileResponse.status !== 200) {
|
|
208
209
|
debug(`Gologin S3 BUCKET ${downloadURL} response error ${profileResponse.statusCode} - use empty`);
|
|
209
210
|
|
|
210
211
|
return '';
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
return Buffer.from(
|
|
214
|
+
return Buffer.from(profileResponseBody);
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
async postFile(fileName, fileBuff) {
|
|
@@ -1351,6 +1352,18 @@ export class GoLogin {
|
|
|
1351
1352
|
return response.body;
|
|
1352
1353
|
}
|
|
1353
1354
|
|
|
1355
|
+
getCookiePath(defaultFilePath) {
|
|
1356
|
+
let primary = join(defaultFilePath, 'Cookies');
|
|
1357
|
+
let secondary = join(defaultFilePath, 'Network', 'Cookies');
|
|
1358
|
+
|
|
1359
|
+
if (!existsSync(primary)) {
|
|
1360
|
+
primary = join(defaultFilePath, 'Network', 'Cookies');
|
|
1361
|
+
secondary = join(defaultFilePath, 'Cookies');
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
return { primary, secondary };
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1354
1367
|
async writeCookiesToFile(cookies) {
|
|
1355
1368
|
if (!cookies) {
|
|
1356
1369
|
cookies = await this.getCookies(this.profile_id);
|
|
@@ -1365,15 +1378,12 @@ export class GoLogin {
|
|
|
1365
1378
|
const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
|
|
1366
1379
|
|
|
1367
1380
|
const defaultFilePath = _resolve(profilePath, 'Default');
|
|
1368
|
-
const
|
|
1369
|
-
const secondCookiesFilePath = _resolve(defaultFilePath, 'Network', 'Cookies');
|
|
1381
|
+
const cookiesPaths = this.getCookiePath(defaultFilePath);
|
|
1370
1382
|
try {
|
|
1371
|
-
db = await getDB(
|
|
1372
|
-
const cookiesToInsert = await getUniqueCookies(resultCookies,
|
|
1373
|
-
// console.log('cookiesToInsert', cookiesToInsert);
|
|
1383
|
+
db = await getDB(cookiesPaths.primary, false);
|
|
1384
|
+
const cookiesToInsert = await getUniqueCookies(resultCookies, cookiesPaths.primary);
|
|
1374
1385
|
if (cookiesToInsert.length) {
|
|
1375
1386
|
const chunckInsertValues = getChunckedInsertValues(cookiesToInsert);
|
|
1376
|
-
console.log('chunckInsertValues', chunckInsertValues);
|
|
1377
1387
|
for (const [query, queryParams] of chunckInsertValues) {
|
|
1378
1388
|
const insertStmt = await db.prepare(query);
|
|
1379
1389
|
await insertStmt.run(queryParams);
|
|
@@ -1384,7 +1394,7 @@ export class GoLogin {
|
|
|
1384
1394
|
console.log(error.message);
|
|
1385
1395
|
} finally {
|
|
1386
1396
|
db && await db.close();
|
|
1387
|
-
await copyFile(
|
|
1397
|
+
await copyFile(cookiesPaths.primary, cookiesPaths.secondary).catch(console.log);
|
|
1388
1398
|
}
|
|
1389
1399
|
}
|
|
1390
1400
|
|