diff --git a/modules/rsocials/components/folk-campaign-wizard.ts b/modules/rsocials/components/folk-campaign-wizard.ts index 09dbbe3..d12abef 100644 --- a/modules/rsocials/components/folk-campaign-wizard.ts +++ b/modules/rsocials/components/folk-campaign-wizard.ts @@ -133,17 +133,28 @@ export class FolkCampaignWizard extends HTMLElement { return `/${encodeURIComponent(this._space)}/rsocials`; } - private async apiFetch(path: string, opts: RequestInit = {}): Promise { + private async apiFetch(path: string, opts: RequestInit & { timeoutMs?: number } = {}): Promise { let token = ''; try { const s = JSON.parse(localStorage.getItem('encryptid_session') || ''); token = s.accessToken || ''; } catch {} - return fetch(`${this.basePath}${path}`, { - ...opts, - headers: { - 'Content-Type': 'application/json', - ...(token ? { Authorization: `Bearer ${token}` } : {}), - ...(opts.headers || {}), - }, - }); + const { timeoutMs = 120_000, ...fetchOpts } = opts; + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), timeoutMs); + try { + return await fetch(`${this.basePath}${path}`, { + ...fetchOpts, + signal: controller.signal, + headers: { + 'Content-Type': 'application/json', + ...(token ? { Authorization: `Bearer ${token}` } : {}), + ...(fetchOpts.headers || {}), + }, + }); + } catch (e: any) { + if (e.name === 'AbortError') throw new Error('Request timed out — please try again'); + throw e; + } finally { + clearTimeout(timer); + } } private async loadWizard(): Promise { diff --git a/modules/rsocials/mod.ts b/modules/rsocials/mod.ts index b70ec57..07de488 100644 --- a/modules/rsocials/mod.ts +++ b/modules/rsocials/mod.ts @@ -1521,7 +1521,7 @@ routes.post("/api/campaign/wizard/:id/content", async (c) => { const { GoogleGenerativeAI } = await import("@google/generative-ai"); const genAI = new GoogleGenerativeAI(GEMINI_API_KEY); const model = genAI.getGenerativeModel({ - model: "gemini-2.5-pro", + model: "gemini-2.5-flash", generationConfig: { responseMimeType: "application/json" } as any, });