gologin 2.1.13 → 2.1.14

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 +33 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.1.13",
3
+ "version": "2.1.14",
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
@@ -63,6 +63,7 @@ export class GoLogin {
63
63
  this.isEmptyFonts = false;
64
64
  this.isFirstSession = false;
65
65
  this.isCloudHeadless = options.isCloudHeadless ?? true;
66
+ this.storageGatewayUrl = `${STORAGE_GATEWAY_BASE_URL}/upload`;
66
67
 
67
68
  this.tmpdir = tmpdir();
68
69
  this.autoUpdateBrowser = !!options.autoUpdateBrowser;
@@ -218,12 +219,11 @@ export class GoLogin {
218
219
  async postFile(fileName, fileBuff) {
219
220
  debug('POSTING FILE', fileBuff.length);
220
221
  debug('Getting signed URL for S3');
221
- const apiUrl = `${STORAGE_GATEWAY_BASE_URL}/upload`;
222
222
 
223
223
  const bodyBufferBiteLength = Buffer.byteLength(fileBuff);
224
224
  console.log('BUFFER SIZE', bodyBufferBiteLength);
225
225
 
226
- await requests.put(apiUrl, {
226
+ await requests.put(this.storageGatewayUrl, {
227
227
  headers: {
228
228
  Authorization: `Bearer ${this.access_token}`,
229
229
  browserId: this.profile_id,
@@ -976,14 +976,14 @@ export class GoLogin {
976
976
  false;
977
977
 
978
978
  if (this.uploadCookiesToServer) {
979
- await this.uploadProfileCookiesToServer();
979
+ const updateResult = await this.uploadProfileDataToServer();
980
+ this.storageGatewayUrl = updateResult.storageGateway.url;
980
981
  }
981
982
 
982
983
  this.is_stopping = true;
983
984
  await this.sanitizeProfile();
984
985
 
985
986
  if (is_posting) {
986
- await this.saveBookmarksToDb();
987
987
  await this.commitProfile();
988
988
  }
989
989
 
@@ -1001,6 +1001,35 @@ export class GoLogin {
1001
1001
  return false;
1002
1002
  }
1003
1003
 
1004
+ async uploadProfileDataToServer() {
1005
+ const cookies = await loadCookiesFromFile(this.cookiesFilePath);
1006
+ const bookmarks = await getCurrentProfileBookmarks(this.bookmarksFilePath);
1007
+
1008
+ const body = {
1009
+ cookies,
1010
+ bookmarks,
1011
+ isCookiesEncrypted: true,
1012
+ isStorageGateway: true,
1013
+ };
1014
+
1015
+ const updateResult = await requests.post(`${API_URL}/browser/features/profile/${this.profile_id}/update_after_close`, {
1016
+ headers: {
1017
+ Authorization: `Bearer ${this.access_token}`,
1018
+ 'User-Agent': 'gologin-api',
1019
+ },
1020
+ json: body,
1021
+ maxAttempts: 3,
1022
+ retryDelay: 2000,
1023
+ timeout: 20 * 1000,
1024
+ }).catch((e) => {
1025
+ console.log(e);
1026
+
1027
+ return e;
1028
+ });
1029
+
1030
+ return updateResult.body;
1031
+ }
1032
+
1004
1033
  async stopBrowser() {
1005
1034
  if (!this.port) {
1006
1035
  throw new Error('Empty GoLogin port');