gologin 2.1.9 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/gologin.js +23 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.1.9",
3
+ "version": "2.1.11",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "types": "./index.d.ts",
6
6
  "main": "./src/gologin.js",
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
- const profileResponse = await requests.get(downloadURL, {
200
- encoding: null,
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
- if (profileResponse.statusCode !== 200) {
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(profileResponse.body);
214
+ return Buffer.from(profileResponseBody);
214
215
  }
215
216
 
216
217
  async postFile(fileName, fileBuff) {
@@ -977,12 +978,11 @@ export class GoLogin {
977
978
  await this.uploadProfileCookiesToServer();
978
979
  }
979
980
 
980
- await this.saveBookmarksToDb();
981
-
982
981
  this.is_stopping = true;
983
982
  await this.sanitizeProfile();
984
983
 
985
984
  if (is_posting) {
985
+ await this.saveBookmarksToDb();
986
986
  await this.commitProfile();
987
987
  }
988
988
 
@@ -1352,6 +1352,18 @@ export class GoLogin {
1352
1352
  return response.body;
1353
1353
  }
1354
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
+
1355
1367
  async writeCookiesToFile(cookies) {
1356
1368
  if (!cookies) {
1357
1369
  cookies = await this.getCookies(this.profile_id);
@@ -1366,15 +1378,12 @@ export class GoLogin {
1366
1378
  const profilePath = join(this.tmpdir, `gologin_profile_${this.profile_id}`);
1367
1379
 
1368
1380
  const defaultFilePath = _resolve(profilePath, 'Default');
1369
- const cookiesFilePath = _resolve(defaultFilePath, 'Cookies');
1370
- const secondCookiesFilePath = _resolve(defaultFilePath, 'Network', 'Cookies');
1381
+ const cookiesPaths = this.getCookiePath(defaultFilePath);
1371
1382
  try {
1372
- db = await getDB(cookiesFilePath, false);
1373
- const cookiesToInsert = await getUniqueCookies(resultCookies, cookiesFilePath);
1374
- // console.log('cookiesToInsert', cookiesToInsert);
1383
+ db = await getDB(cookiesPaths.primary, false);
1384
+ const cookiesToInsert = await getUniqueCookies(resultCookies, cookiesPaths.primary);
1375
1385
  if (cookiesToInsert.length) {
1376
1386
  const chunckInsertValues = getChunckedInsertValues(cookiesToInsert);
1377
- console.log('chunckInsertValues', chunckInsertValues);
1378
1387
  for (const [query, queryParams] of chunckInsertValues) {
1379
1388
  const insertStmt = await db.prepare(query);
1380
1389
  await insertStmt.run(queryParams);
@@ -1385,7 +1394,7 @@ export class GoLogin {
1385
1394
  console.log(error.message);
1386
1395
  } finally {
1387
1396
  db && await db.close();
1388
- await copyFile(cookiesFilePath, secondCookiesFilePath).catch(console.log);
1397
+ await copyFile(cookiesPaths.primary, cookiesPaths.secondary).catch(console.log);
1389
1398
  }
1390
1399
  }
1391
1400