superbrain-server 1.0.25 → 1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/payload/api.py +16 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superbrain-server",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "1-Line Auto-Installer and Server Execution wrapper for SuperBrain",
5
5
  "main": "index.js",
6
6
  "bin": {
package/payload/api.py CHANGED
@@ -1662,20 +1662,33 @@ async def set_instagram_credentials(
1662
1662
 
1663
1663
  # Authenticate with Instagram first
1664
1664
  import instaloader
1665
+ import httpx
1666
+ import urllib.parse
1667
+
1665
1668
  L = instaloader.Instaloader()
1666
1669
  try:
1667
1670
  session_file = Path(__file__).parent / ".instaloader_session"
1668
1671
  if sessionid:
1669
- L.context._session.cookies.set("sessionid", sessionid, domain=".instagram.com")
1672
+ # Decode if URL-encoded (common from browser)
1673
+ clean_session = urllib.parse.unquote(sessionid.strip())
1674
+
1675
+ # Fast HTTP verification before committing to instaloader
1676
+ # so we avoid slow retries and BadResponseException
1677
+ async with httpx.AsyncClient(timeout=15.0, follow_redirects=False) as client:
1678
+ verify_resp = await client.get("https://www.instagram.com/", cookies={"sessionid": clean_session})
1679
+ if verify_resp.status_code == 302:
1680
+ raise HTTPException(status_code=401, detail="Invalid or expired Session ID")
1681
+
1682
+ L.context._session.cookies.set("sessionid", clean_session, domain=".instagram.com")
1670
1683
  L.context.username = username_to_use
1671
- # To verify sessionid, attempt to get a profile or just save it directly.
1672
- L.get_profile("instagram")
1673
1684
  else:
1674
1685
  L.login(data.username, data.password)
1675
1686
  username_to_use = data.username
1676
1687
 
1677
1688
  L.save_session_to_file(str(session_file))
1678
1689
  logger.info(f"🍪 Instagram session successfully verified and saved for {username_to_use}")
1690
+ except HTTPException:
1691
+ raise
1679
1692
  except instaloader.exceptions.BadCredentialsException:
1680
1693
  raise HTTPException(status_code=401, detail="Invalid username or password")
1681
1694
  except instaloader.exceptions.TwoFactorAuthRequiredException: