fix: create key requires X-Account-ID + X-Client-Instance after loading /dashboard/keys; document guards
This commit is contained in:
+57
-13
@@ -161,22 +161,66 @@ def farm_one(p, idx, proxy_url, out_path, exe, profiles_dir):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
keyres = page.evaluate("""async () => {
|
||||
const r = await fetch('/api/account/keys', {
|
||||
method: 'POST', credentials: 'include',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({name: 'k' + Date.now()})});
|
||||
return r.status + ' ' + (await r.text()).slice(0, 600); }""")
|
||||
secret = ""
|
||||
if keyres.startswith("201"):
|
||||
try:
|
||||
secret = json.loads(keyres.split(" ", 1)[1]).get("secret", "")
|
||||
except Exception:
|
||||
pass
|
||||
# Гард account_changed: POST /api/account/keys проходит только из
|
||||
# ЗАГРУЖЕННОГО приложения (/dashboard/keys) и с заголовками
|
||||
# X-Account-ID + X-Client-Instance. Со страницы /signup — всегда 409.
|
||||
try:
|
||||
page.goto(SITE + "/dashboard/keys", wait_until="commit", timeout=45000)
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(7)
|
||||
|
||||
me = page.evaluate("""async () => {
|
||||
const r = await fetch('/api/account/me', {credentials: 'include'});
|
||||
return r.status + ' ' + (await r.text()).slice(0, 500); }""")
|
||||
return r.status + ' ' + (await r.text()).slice(0, 4000); }""")
|
||||
acc_id = ""
|
||||
try:
|
||||
acc_id = (json.loads(me.split(" ", 1)[1]).get("user") or {}).get("id", "")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 409 account_changed = отсутствует/не совпадает заголовок X-Account-ID
|
||||
# (см. _app/immutable/chunks/*.js: fetch-обёртка шлёт X-Account-ID + X-Client-Instance)
|
||||
ci = page.evaluate("""() => {
|
||||
try {
|
||||
let e = JSON.parse(localStorage.getItem('ul:security-browser') || 'null');
|
||||
const t = e && /^[a-f0-9-]{36}$/i.test(e.id) && e.expires > Date.now() ? e
|
||||
: {id: crypto.randomUUID(), expires: Date.now() + 2592e6};
|
||||
localStorage.setItem('ul:security-browser', JSON.stringify(t));
|
||||
return t.id;
|
||||
} catch (e) { return ''; } }""")
|
||||
|
||||
keyres = ""
|
||||
secret = ""
|
||||
for attempt in range(3):
|
||||
keyres = page.evaluate("""async (h) => {
|
||||
const r = await fetch('/api/account/keys', {
|
||||
method: 'POST', credentials: 'include',
|
||||
headers: {'Content-Type': 'application/json',
|
||||
'X-Account-ID': h.id, 'X-Client-Instance': h.ci},
|
||||
body: JSON.stringify({name: 'k' + Date.now()})});
|
||||
return r.status + ' ' + (await r.text()).slice(0, 600); }""",
|
||||
{"id": acc_id, "ci": ci})
|
||||
if keyres.startswith("201"):
|
||||
try:
|
||||
secret = json.loads(keyres.split(" ", 1)[1]).get("secret", "")
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
if "account_changed" in keyres:
|
||||
me2 = page.evaluate("""async () => {
|
||||
const r = await fetch('/api/account/me', {credentials: 'include'});
|
||||
return r.status + ' ' + (await r.text()).slice(0, 4000); }""")
|
||||
try:
|
||||
acc_id = (json.loads(me2.split(" ", 1)[1]).get("user") or {}).get("id", "") or acc_id
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(2)
|
||||
continue
|
||||
break
|
||||
if not secret:
|
||||
log(idx, "keyerr:", keyres[:200])
|
||||
|
||||
bal = ""
|
||||
try:
|
||||
bal = json.loads(me.split(" ", 1)[1]).get("wallet", {}).get("balance_nano", "")
|
||||
|
||||
Reference in New Issue
Block a user