insta-api-wrapper 1.1.4 → 1.2.1

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.
@@ -341,7 +341,8 @@ export function bloksDetectAirwave(rawStr) {
341
341
  rawStr.includes('AIRWAVE') || rawStr.includes('airwave');
342
342
  }
343
343
  export function bloksExtractSession(rawStr) {
344
- const idx = rawStr.indexOf('IGT:2:');
344
+ const igtMarker = 'IGT:2:';
345
+ const idx = rawStr.indexOf(igtMarker);
345
346
  if (idx === -1)
346
347
  return null;
347
348
  let end = rawStr.length;
@@ -351,15 +352,28 @@ export function bloksExtractSession(rawStr) {
351
352
  break;
352
353
  }
353
354
  }
354
- const authorization = `Bearer ${rawStr.slice(idx, end)}`;
355
- const uidMarker = '"ds_user_id":"';
356
- const uidIdx = rawStr.indexOf(uidMarker);
355
+ const token = rawStr.slice(idx, end);
356
+ const authorization = `Bearer ${token}`;
357
357
  let userId = '';
358
- if (uidIdx !== -1) {
359
- const uStart = uidIdx + uidMarker.length;
360
- const uEnd = rawStr.indexOf('"', uStart);
361
- if (uEnd > uStart)
362
- userId = rawStr.slice(uStart, uEnd);
358
+ const lastColon = token.lastIndexOf(':');
359
+ if (lastColon > 0) {
360
+ try {
361
+ const decoded = Buffer.from(token.slice(lastColon + 1), 'base64').toString('utf-8');
362
+ const parsed = JSON.parse(decoded);
363
+ if (parsed.ds_user_id)
364
+ userId = String(parsed.ds_user_id);
365
+ }
366
+ catch (_) { }
367
+ }
368
+ if (!userId) {
369
+ const uidMarker = '"ds_user_id":"';
370
+ const uidIdx = rawStr.indexOf(uidMarker);
371
+ if (uidIdx !== -1) {
372
+ const uStart = uidIdx + uidMarker.length;
373
+ const uEnd = rawStr.indexOf('"', uStart);
374
+ if (uEnd > uStart)
375
+ userId = rawStr.slice(uStart, uEnd);
376
+ }
363
377
  }
364
378
  return { authorization, userId };
365
379
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insta-api-wrapper",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "description": "Anonymous Stories, Search & Download reels, posts, highlights... on Insta",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",