🎬 火宝短剧 - 基于AI的一站式短剧生成平台 《一句话生成完整短剧,从剧本到成片全自动化》 Huobao Drama - An AI-Powered End-to-End Short Drama Generator "One Sentence to Complete Drama: Fully Automated from Script to Final Video"
TypeScript
fix: replace .returning() with .run() + lastInsertRowid
Connor9fd1c0323698
diff --git a/backend/src/routes/aiConfigs.ts b/backend/src/routes/aiConfigs.tsindex 0786db5..0def942 100644--- a/backend/src/routes/aiConfigs.ts+++ b/backend/src/routes/aiConfigs.ts@@ -29,7 +29,7 @@ app.post('/', async (c) => {return badRequest(c, 'service_type and provider are required')}- const [result] = db.insert(schema.aiServiceConfigs).values({+ const res = db.insert(schema.aiServiceConfigs).values({serviceType: body.service_type,provider: body.provider,name: body.name || `${body.provider}-${body.service_type}`,@@ -40,11 +40,14 @@ app.post('/', async (c) => {isActive: true,createdAt: ts,updatedAt: ts,- }).returning()+ }).run()++ const [row] = db.select().from(schema.aiServiceConfigs)+ .where(eq(schema.aiServiceConfigs.id, Number(res.lastInsertRowid))).all()return created(c, {- ...toSnakeCase(result),- model: result.model ? JSON.parse(result.model) : [],+ ...toSnakeCase(row),+ model: row.model ? JSON.parse(row.model) : [],})})diff --git a/backend/src/routes/dramas.ts b/backend/src/routes/dramas.tsindex de711cc..197b2aa 100644--- a/backend/src/routes/dramas.ts+++ b/backend/src/routes/dramas.ts@@ -51,28 +51,32 @@ app.get('/', async (c) => {app.post('/', async (c) => {const body = await c.req.json()const ts = now()- const [result] = await db.insert(schema.dramas).values({+ const res = db.insert(schema.dramas).values({title: body.title,description: body.description,genre: body.genre,style: body.style,tags: body.tags ? JSON.stringify(body.tags) : null,+ metadata: body.metadata,status: 'draft',createdAt: ts,updatedAt: ts,- }).returning()+ }).run()++ const [result] = db.select().from(schema.dramas)+ .where(eq(schema.dramas.id, Number(res.lastInsertRowid))).all()// Create default episodesconst totalEpisodes = body.total_episodes || 1for (let i = 1; i <= totalEpisodes; i++) {- await db.insert(schema.episodes).values({+ db.insert(schema.episodes).values({dramaId: result.id,episodeNumber: i,title: `第${i}集`,status: 'draft',createdAt: ts,updatedAt: ts,- })+ }).run()}return created(c, result)diff --git a/backend/src/routes/scenes.ts b/backend/src/routes/scenes.tsindex 32426a3..4e6f740 100644--- a/backend/src/routes/scenes.ts+++ b/backend/src/routes/scenes.ts@@ -1,7 +1,7 @@import { Hono } from 'hono'import { eq } from 'drizzle-orm'-import { db, schema } from '../db'-import { success, notFound, created, now } from '../utils/response'+import { db, schema } from '../db/index.js'+import { success, created, now } from '../utils/response.js'const app = new Hono()@@ -9,18 +9,17 @@ const app = new Hono()app.post('/', async (c) => {const body = await c.req.json()const ts = now()- const [result] = await db.insert(schema.scenes).values({+ const res = db.insert(schema.scenes).values({dramaId: body.drama_id,episodeId: body.episode_id,location: body.location,- time: body.time,- prompt: body.prompt,- description: body.description,- imageUrl: body.image_url,- localPath: body.local_path,+ time: body.time || '',+ prompt: body.prompt || body.location,createdAt: ts,updatedAt: ts,- }).returning()+ }).run()+ const [result] = db.select().from(schema.scenes)+ .where(eq(schema.scenes.id, Number(res.lastInsertRowid))).all()return created(c, result)})@@ -28,22 +27,18 @@ app.post('/', async (c) => {app.put('/:id', async (c) => {const id = Number(c.req.param('id'))const body = await c.req.json()- await db.update(schema.scenes).set({- location: body.location,- time: body.time,- prompt: body.prompt,- description: body.description,- imageUrl: body.image_url,- localPath: body.local_path,- updatedAt: now(),- }).where(eq(schema.scenes.id, id))+ const updates: Record<string, any> = { updatedAt: now() }+ if (body.location !== undefined) updates.location = body.location+ if (body.time !== undefined) updates.time = body.time+ if (body.prompt !== undefined) updates.prompt = body.prompt+ db.update(schema.scenes).set(updates).where(eq(schema.scenes.id, id)).run()return success(c)})// DELETE /scenes/:idapp.delete('/:id', async (c) => {const id = Number(c.req.param('id'))- await db.delete(schema.scenes).where(eq(schema.scenes.id, id))+ db.delete(schema.scenes).where(eq(schema.scenes.id, id)).run()return success(c)})diff --git a/backend/src/routes/storyboards.ts b/backend/src/routes/storyboards.tsindex fa70c26..ea3a448 100644--- a/backend/src/routes/storyboards.ts+++ b/backend/src/routes/storyboards.ts@@ -1,15 +1,15 @@import { Hono } from 'hono'import { eq } from 'drizzle-orm'-import { db, schema } from '../db'-import { success, notFound, badRequest, created, now } from '../utils/response'+import { db, schema } from '../db/index.js'+import { success, created, now } from '../utils/response.js'const app = new Hono()-// POST /storyboards - Create storyboard+// POST /storyboardsapp.post('/', async (c) => {const body = await c.req.json()const ts = now()- const [result] = await db.insert(schema.storyboards).values({+ const res = db.insert(schema.storyboards).values({episodeId: body.episode_id,storyboardNumber: body.storyboard_number || 1,title: body.title,@@ -20,11 +20,13 @@ app.post('/', async (c) => {duration: body.duration || 10,createdAt: ts,updatedAt: ts,- }).returning()+ }).run()+ const [result] = db.select().from(schema.storyboards)+ .where(eq(schema.storyboards.id, Number(res.lastInsertRowid))).all()return created(c, result)})-// PUT /storyboards/:id - Update storyboard+// PUT /storyboards/:idapp.put('/:id', async (c) => {const id = Number(c.req.param('id'))const body = await c.req.json()@@ -43,14 +45,14 @@ app.put('/:id', async (c) => {if (snakeKey in body) updates[camelKey] = body[snakeKey]}- await db.update(schema.storyboards).set(updates).where(eq(schema.storyboards.id, id))+ db.update(schema.storyboards).set(updates).where(eq(schema.storyboards.id, id)).run()return success(c)})// DELETE /storyboards/:idapp.delete('/:id', async (c) => {const id = Number(c.req.param('id'))- await db.delete(schema.storyboards).where(eq(schema.storyboards.id, id))+ db.delete(schema.storyboards).where(eq(schema.storyboards.id, id)).run()return success(c)})diff --git a/backend/src/services/image-generation.ts b/backend/src/services/image-generation.tsindex 72500d0..46bda05 100644--- a/backend/src/services/image-generation.ts+++ b/backend/src/services/image-generation.ts@@ -39,14 +39,16 @@ export async function generateImage(params: GenerateImageParams): Promise<numberstatus: 'processing',createdAt: ts,updatedAt: ts,- }).returning()+ }).run()++ const lastId = Number(db.select().from(schema.imageGenerations).all().pop()?.id || 0)// 异步处理- processImageGeneration(record.id, config).catch(err => {- console.error(`Image generation ${record.id} failed:`, err)+ processImageGeneration(lastId, config).catch(err => {+ console.error(`Image generation ${lastId} failed:`, err)})- return record.id+ return lastId}async function processImageGeneration(id: number, config: { baseUrl: string; apiKey: string; model: string }) {diff --git a/backend/src/services/video-generation.ts b/backend/src/services/video-generation.tsindex 8122993..820b036 100644--- a/backend/src/services/video-generation.ts+++ b/backend/src/services/video-generation.ts@@ -42,14 +42,16 @@ export async function generateVideo(params: GenerateVideoParams): Promise<numberstatus: 'processing',createdAt: ts,updatedAt: ts,- }).returning()+ }).run()++ const lastId = Number(db.select().from(schema.videoGenerations).all().pop()?.id || 0)// 异步处理- processVideoGeneration(record.id, config).catch(err => {- console.error(`Video generation ${record.id} failed:`, err)+ processVideoGeneration(lastId, config).catch(err => {+ console.error(`Video generation ${lastId} failed:`, err)})- return record.id+ return lastId}async function processVideoGeneration(id: number, config: { baseUrl: string; apiKey: string; model: string }) {