gologin 1.0.32 → 1.0.33
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/gologin.js +19 -55
- package/package.json +1 -1
package/gologin.js
CHANGED
|
@@ -140,41 +140,29 @@ class GoLogin {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
async getProfileS3(s3path) {
|
|
143
|
+
if (!s3path) {
|
|
144
|
+
throw new Error('s3path not found');
|
|
145
|
+
}
|
|
146
|
+
|
|
143
147
|
const token = this.access_token;
|
|
144
148
|
debug('getProfileS3 token=', token, 'profile=', this.profile_id, 's3path=', s3path);
|
|
145
149
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const profileResponse = await requests.get(s3url, {
|
|
150
|
-
encoding: null
|
|
151
|
-
});
|
|
152
|
-
if (profileResponse.statusCode !== 200) {
|
|
153
|
-
debug(`Gologin S3 BUCKET ${s3url} response error ${profileResponse.statusCode} - use empty`);
|
|
154
|
-
return '';
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return Buffer.from(profileResponse.body);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
debug('old-way loading profile');
|
|
161
|
-
const profileResponse = await requests.get(`${API_URL}/browser/${this.profile_id}/profile-s3`, {
|
|
162
|
-
headers: {
|
|
163
|
-
'Authorization': `Bearer ${token}`,
|
|
164
|
-
},
|
|
150
|
+
const s3url = `https://gprofiles.gologin.com/${s3path}`.replace(/\s+/mg, '+');
|
|
151
|
+
debug('loading profile from public s3 bucket, url=', s3url);
|
|
152
|
+
const profileResponse = await requests.get(s3url, {
|
|
165
153
|
encoding: null
|
|
166
154
|
});
|
|
167
155
|
|
|
168
156
|
if (profileResponse.statusCode !== 200) {
|
|
169
|
-
debug(`Gologin
|
|
157
|
+
debug(`Gologin S3 BUCKET ${s3url} response error ${profileResponse.statusCode} - use empty`);
|
|
170
158
|
return '';
|
|
171
159
|
}
|
|
172
160
|
|
|
173
161
|
return Buffer.from(profileResponse.body);
|
|
174
162
|
}
|
|
175
163
|
|
|
176
|
-
async postFile(fileName,
|
|
177
|
-
debug('POSTING FILE',
|
|
164
|
+
async postFile(fileName, fileBuff) {
|
|
165
|
+
debug('POSTING FILE', fileBuff.length);
|
|
178
166
|
debug('Getting signed URL for S3');
|
|
179
167
|
const apiUrl = `${API_URL}/browser/${this.profile_id}/storage-signature`;
|
|
180
168
|
|
|
@@ -191,25 +179,8 @@ class GoLogin {
|
|
|
191
179
|
|
|
192
180
|
const [uploadedProfileUrl] = signedUrl.split('?');
|
|
193
181
|
|
|
194
|
-
const fd = new FormData();
|
|
195
|
-
const boundary = fd.getBoundary();
|
|
196
|
-
const body = Buffer.concat([
|
|
197
|
-
Buffer.from('--'),
|
|
198
|
-
Buffer.from(boundary),
|
|
199
|
-
Buffer.from('\r\n'),
|
|
200
|
-
Buffer.from(`Content-Disposition: form-data; name="profile"; filename="${fileName}"`),
|
|
201
|
-
Buffer.from('\r\n'),
|
|
202
|
-
Buffer.from('\r\n'),
|
|
203
|
-
Buffer.from(fileBody),
|
|
204
|
-
Buffer.from('\r\n'),
|
|
205
|
-
Buffer.from('--'),
|
|
206
|
-
Buffer.from(boundary),
|
|
207
|
-
Buffer.from('--'),
|
|
208
|
-
Buffer.from('\r\n')
|
|
209
|
-
]);
|
|
210
|
-
|
|
211
182
|
console.log('Uploading profile by signed URL to S3');
|
|
212
|
-
const bodyBufferBiteLength = Buffer.byteLength(
|
|
183
|
+
const bodyBufferBiteLength = Buffer.byteLength(fileBuff);
|
|
213
184
|
console.log('BUFFER SIZE', bodyBufferBiteLength);
|
|
214
185
|
|
|
215
186
|
await requests.put(signedUrl, {
|
|
@@ -217,7 +188,7 @@ class GoLogin {
|
|
|
217
188
|
'Content-Type': 'application/zip',
|
|
218
189
|
'Content-Length': bodyBufferBiteLength,
|
|
219
190
|
},
|
|
220
|
-
body,
|
|
191
|
+
body: fileBuff,
|
|
221
192
|
maxBodyLength: Infinity,
|
|
222
193
|
maxContentLength: Infinity,
|
|
223
194
|
maxAttempts: 3,
|
|
@@ -345,6 +316,7 @@ class GoLogin {
|
|
|
345
316
|
catch (e) {
|
|
346
317
|
debug('Cannot get profile - using empty', e);
|
|
347
318
|
}
|
|
319
|
+
|
|
348
320
|
debug('FILE READY', this.profile_zip_path);
|
|
349
321
|
if (!profile_folder.length) {
|
|
350
322
|
profile_folder = await this.emptyProfileFolder();
|
|
@@ -491,10 +463,10 @@ class GoLogin {
|
|
|
491
463
|
}
|
|
492
464
|
|
|
493
465
|
async commitProfile() {
|
|
494
|
-
const
|
|
466
|
+
const dataBuff = await this.getProfileDataToUpdate();
|
|
495
467
|
|
|
496
|
-
debug('begin updating',
|
|
497
|
-
if (!
|
|
468
|
+
debug('begin updating', dataBuff.length);
|
|
469
|
+
if (!dataBuff.length) {
|
|
498
470
|
debug('WARN: profile zip data empty - SKIPPING PROFILE COMMIT');
|
|
499
471
|
|
|
500
472
|
return;
|
|
@@ -502,7 +474,7 @@ class GoLogin {
|
|
|
502
474
|
|
|
503
475
|
try {
|
|
504
476
|
debug('Patching profile');
|
|
505
|
-
await this.postFile('profile',
|
|
477
|
+
await this.postFile('profile', dataBuff);
|
|
506
478
|
}
|
|
507
479
|
catch (e) {
|
|
508
480
|
debug('CANNOT COMMIT PROFILE', e);
|
|
@@ -838,7 +810,7 @@ class GoLogin {
|
|
|
838
810
|
debug('profile sanitized');
|
|
839
811
|
|
|
840
812
|
const profilePath = this.profilePath();
|
|
841
|
-
await new Promise((resolve, reject) => zipdir(profilePath,
|
|
813
|
+
const fileBuff = await new Promise((resolve, reject) => zipdir(profilePath,
|
|
842
814
|
{
|
|
843
815
|
saveTo: zipPath,
|
|
844
816
|
filter: (path) => !/RunningChromeVersion/.test(path),
|
|
@@ -853,15 +825,7 @@ class GoLogin {
|
|
|
853
825
|
)
|
|
854
826
|
|
|
855
827
|
debug('PROFILE ZIP CREATED', profilePath, zipPath);
|
|
856
|
-
|
|
857
|
-
let data = '';
|
|
858
|
-
try {
|
|
859
|
-
data = await readFile(zipPath);
|
|
860
|
-
} catch (e) {
|
|
861
|
-
debug('saveprofile error', e);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
return data;
|
|
828
|
+
return fileBuff;
|
|
865
829
|
}
|
|
866
830
|
|
|
867
831
|
async profileExists() {
|