gologin 2.0.23 → 2.0.26

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/.eslintrc.json CHANGED
@@ -30,10 +30,7 @@
30
30
  ]
31
31
  }
32
32
  ],
33
- "linebreak-style": [
34
- "warn",
35
- "windows"
36
- ],
33
+ "linebreak-style": 0,
37
34
  "quotes": [
38
35
  "warn",
39
36
  "single"
@@ -55,12 +52,6 @@
55
52
  "warn",
56
53
  "as-needed"
57
54
  ],
58
- "camelcase": [
59
- "warn",
60
- {
61
- "ignoreGlobals": true
62
- }
63
- ],
64
55
  "curly": [
65
56
  "warn",
66
57
  "all"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "2.0.23",
3
+ "version": "2.0.26",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./src/gologin.js",
6
6
  "repository": {
package/src/gologin.js CHANGED
@@ -5,7 +5,7 @@ import decompressUnzip from 'decompress-unzip';
5
5
  import { existsSync, mkdirSync, promises as _promises } from 'fs';
6
6
  import { get as _get } from 'https';
7
7
  import { tmpdir } from 'os';
8
- import { join, resolve as _resolve,sep } from 'path';
8
+ import { dirname, join, resolve as _resolve, sep } from 'path';
9
9
  import requests from 'requestretry';
10
10
  import rimraf from 'rimraf';
11
11
  import ProxyAgent from 'simple-proxy-agent';
@@ -19,14 +19,15 @@ import {
19
19
  } from './browser/browser-user-data-manager.js';
20
20
  import {
21
21
  getChunckedInsertValues,
22
+ getCookiesFilePath,
22
23
  getDB,
23
24
  loadCookiesFromFile,
24
- getCookiesFilePath,
25
25
  } from './cookies/cookies-manager.js';
26
26
  import ExtensionsManager from './extensions/extensions-manager.js';
27
27
  import { archiveProfile } from './profile/profile-archiver.js';
28
28
  import { checkAutoLang } from './utils/browser.js';
29
29
  import { API_URL } from './utils/common.js';
30
+ import { STORAGE_GATEWAY_BASE_URL } from './utils/constants.js';
30
31
  import { get, isPortReachable } from './utils/utils.js';
31
32
 
32
33
  const { access, unlink, writeFile, readFile } = _promises;
@@ -197,15 +198,19 @@ export class GoLogin {
197
198
 
198
199
  const token = this.access_token;
199
200
  debug('getProfileS3 token=', token, 'profile=', this.profile_id, 's3path=', s3path);
201
+ const downloadURL = `${STORAGE_GATEWAY_BASE_URL}/download`;
200
202
 
201
- const s3url = `https://gprofiles-new.gologin.com/${s3path}`.replace(/\s+/mg, '+');
202
- debug('loading profile from public s3 bucket, url=', s3url);
203
- const profileResponse = await requests.get(s3url, {
203
+ debug('loading profile from public s3 bucket, url=', downloadURL);
204
+ const profileResponse = await requests.get(downloadURL, {
204
205
  encoding: null,
206
+ headers: {
207
+ Authorization: `Bearer ${token}`,
208
+ browserId: this.profile_id,
209
+ },
205
210
  });
206
211
 
207
212
  if (profileResponse.statusCode !== 200) {
208
- debug(`Gologin S3 BUCKET ${s3url} response error ${profileResponse.statusCode} - use empty`);
213
+ debug(`Gologin S3 BUCKET ${downloadURL} response error ${profileResponse.statusCode} - use empty`);
209
214
 
210
215
  return '';
211
216
  }
@@ -216,27 +221,15 @@ export class GoLogin {
216
221
  async postFile(fileName, fileBuff) {
217
222
  debug('POSTING FILE', fileBuff.length);
218
223
  debug('Getting signed URL for S3');
219
- const apiUrl = `${API_URL}/browser/${this.profile_id}/storage-signature`;
220
-
221
- const signedUrl = await requests.get(apiUrl, {
222
- headers: {
223
- Authorization: `Bearer ${this.access_token}`,
224
- 'user-agent': 'gologin-api',
225
- },
226
- maxAttempts: 3,
227
- retryDelay: 2000,
228
- timeout: 10 * 1000,
229
- fullResponse: false,
230
- });
231
-
232
- const [uploadedProfileUrl] = signedUrl.split('?');
224
+ const apiUrl = `${STORAGE_GATEWAY_BASE_URL}/upload`;
233
225
 
234
- console.log('Uploading profile by signed URL to S3');
235
226
  const bodyBufferBiteLength = Buffer.byteLength(fileBuff);
236
227
  console.log('BUFFER SIZE', bodyBufferBiteLength);
237
228
 
238
- await requests.put(signedUrl, {
229
+ await requests.put(apiUrl, {
239
230
  headers: {
231
+ Authorization: `Bearer ${this.access_token}`,
232
+ browserId: this.profile_id,
240
233
  'Content-Type': 'application/zip',
241
234
  'Content-Length': bodyBufferBiteLength,
242
235
  },
@@ -249,25 +242,14 @@ export class GoLogin {
249
242
  fullResponse: false,
250
243
  });
251
244
 
252
- const uploadedProfileMetadata = await requests.head(uploadedProfileUrl, {
253
- maxAttempts: 3,
254
- retryDelay: 2000,
255
- timeout: 10 * 1000,
256
- fullResponse: true,
257
- });
258
-
259
- const uploadedFileLength = +uploadedProfileMetadata.headers['content-length'];
260
- if (uploadedFileLength !== bodyBufferBiteLength) {
261
- console.log('Uploaded file is incorrect. Retry with China File size:', uploadedFileLength);
262
- throw new Error('Uploaded file is incorrect. Retry with China File size: ' + uploadedFileLength);
263
- }
264
-
265
245
  console.log('Profile has been uploaded to S3 successfully');
266
246
  }
267
247
 
268
248
  async emptyProfileFolder() {
269
249
  debug('get emptyProfileFolder');
270
- const profile = await readFile(_resolve(__dirname, 'zero_profile.zip'));
250
+ const currentDir = dirname(new URL(import.meta.url).pathname);
251
+ const zeroProfilePath = join(currentDir, '..', 'zero_profile.zip');
252
+ const profile = await readFile(_resolve(zeroProfilePath));
271
253
  debug('emptyProfileFolder LENGTH ::', profile.length);
272
254
 
273
255
  return profile;
@@ -0,0 +1 @@
1
+ export const STORAGE_GATEWAY_BASE_URL = 'https://files-gateway.gologin.com';
package/zero_profile.zip CHANGED
Binary file