Something went wrong. Try again.
AI-organized UGC video generator in a chat box. Cloudflare Workers, Vue, Claude API, ffmpeg.wasm reelity.arjunkrishna.dev
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697export interface GenerationRow { id: string; sessionId?: string; prompt: string; action: "chat" | "generate"; reply?: string; format?: string; productName?: string; siteUrl?: string; concept?: string; caption?: string; spec?: unknown; assets?: unknown; model?: string;}
export async function insertGeneration(db: D1Database, row: GenerationRow): Promise<void> { await db .prepare( `INSERT INTO generations (id, session_id, prompt, action, reply, format, product_name, site_url, concept, caption, spec, assets, model, video_url, created_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, ) .bind( row.id, row.sessionId ?? null, row.prompt, row.action, row.reply ?? null, row.format ?? null, row.productName ?? null, row.siteUrl ?? null, row.concept ?? null, row.caption ?? null, row.spec ? JSON.stringify(row.spec) : null, row.assets ? JSON.stringify(row.assets) : null, row.model ?? null, null, Date.now(), ) .run();}
export async function setVideoUrl(db: D1Database, id: string, videoUrl: string): Promise<void> { await db.prepare(`UPDATE generations SET video_url = ? WHERE id = ?`).bind(videoUrl, id).run();}
export interface ThreadRow { id: string; prompt: string; action: string; reply: string | null; concept: string | null; spec: string | null; assets: string | null; model: string | null; video_url: string | null; created_at: number;}
export async function getThread(db: D1Database, sessionId: string, limit = 100): Promise<ThreadRow[]> { const { results } = await db .prepare( `SELECT id, prompt, action, reply, concept, spec, assets, model, video_url, created_at FROM generations WHERE session_id = ? ORDER BY created_at ASC LIMIT ?`, ) .bind(sessionId, limit) .all<ThreadRow>(); return results;}
export interface GalleryRow { id: string; product_name: string | null; concept: string | null; caption: string | null; format: string | null; model: string | null; spec: string | null; assets: string | null; video_url: string; created_at: number;}
export async function listGallery(db: D1Database, limit = 24, offset = 0): Promise<GalleryRow[]> { const { results } = await db .prepare( `SELECT id, product_name, concept, caption, format, model, spec, assets, video_url, created_at FROM generations WHERE action = 'generate' AND video_url IS NOT NULL ORDER BY product_name COLLATE NOCASE ASC LIMIT ? OFFSET ?`, ) .bind(limit, offset) .all<GalleryRow>(); return results;}