fix: paginar asset_group_asset de Google para no perder vídeos/imágenes

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-23 18:40:39 +02:00
parent 8091498508
commit 8c11291396

View File

@@ -146,17 +146,32 @@ async function searchGoogle(
]; ];
let lastErr = ''; let lastErr = '';
for (const headers of attempts) { for (const headers of attempts) {
const r = await fetch(`${GADS_API}/customers/${cid}/googleAds:search`, { const out: GaqlRow[] = [];
method: 'POST', let pageToken: string | undefined;
headers, let ok = false;
body: JSON.stringify({ query }), for (let page = 0; page < 20; page++) {
cache: 'no-store', const body: { query: string; pageToken?: string } = { query };
}); if (pageToken) body.pageToken = pageToken;
if (r.ok) { const r = await fetch(`${GADS_API}/customers/${cid}/googleAds:search`, {
const j = (await r.json()) as { results?: GaqlRow[] }; method: 'POST',
return j.results || []; headers,
body: JSON.stringify(body),
cache: 'no-store',
});
if (!r.ok) {
lastErr = await r.text();
break;
}
ok = true;
const j = (await r.json()) as {
results?: GaqlRow[];
nextPageToken?: string;
};
out.push(...(j.results || []));
pageToken = j.nextPageToken;
if (!pageToken) break;
} }
lastErr = await r.text(); if (ok) return out;
} }
throw new Error(`Google Ads ${cid}: ${lastErr.slice(0, 220)}`); throw new Error(`Google Ads ${cid}: ${lastErr.slice(0, 220)}`);
} }