const { getAuth } = require('./auth_manager'); async function robustFetch(url, options, maxRetries = 8) { let { token, userId } = await getAuth(); let auth = Buffer.from(userId + ':' + token).toString('base64'); for (let attempt = 1; attempt <= maxRetries; attempt++) { const headers = { ...(options.headers || {}), 'Authorization': 'Basic ' + auth }; const res = await fetch(url, { ...options, headers }); if (res.status === 401 && attempt < maxRetries) { console.log(`[Attempt ${attempt}] Got 401, retrying after 500ms...`); await new Promise(r => setTimeout(r, 600)); continue; } return res; } } async function test() { const { userId } = await getAuth(); console.log('Testing robust POST...'); const res = await robustFetch(`https://registry.ghaymah.systems/v2/${userId}/soc-gateway/blobs/uploads/`, { method: 'POST' }); console.log('Final status:', res.status); const loc = res.headers.get('location'); console.log('Location:', loc?.substring(0, 60)); } test().catch(console.error);