fix(instagram): scope saved sessions to the configured account

This commit is contained in:
hh committed 2026-09-06 23:06:34 +02:00
1 parent 28f25c9011
commit 1cc2c502c0
1 file changed
+18 -4
+18 -4
View File
@@ -69,18 +69,32 @@ class SessionPool:
self._totp_secret = totp_secret
self._live.extend(Session(s) for s in self._load() if s not in sids)
@staticmethod
def _load() -> list[str]:
def _load(self) -> list[str]:
try:
with open(STORE, "rb") as f:
return orjson.loads(f.read())
saved = orjson.loads(f.read())
except Exception:
return []
# Sessions are tied to the account that minted them. Swapping
# IG_USERNAME must not silently keep serving from the old one.
if isinstance(saved, dict):
if saved.get("user") != self._username:
return []
return saved.get("sids") or []
return saved if isinstance(saved, list) and not self._username else []
def _save(self) -> None:
try:
with open(STORE, "wb") as f:
f.write(orjson.dumps([s.sid for s in self._live]))
f.write(
orjson.dumps(
{
"user": self._username,
"sids": [s.sid for s in self._live],
}
)
)
except Exception:
pass