Skip to content

🎬 火宝短剧 - 基于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: resolve 7 code review issues

Connor73b88f94fb78
diff --git a/backend/src/index.ts b/backend/src/index.ts
index 0d6e434..aab7bda 100644
--- a/backend/src/index.ts
+++ b/backend/src/index.ts
@@ -30,8 +30,8 @@ app.use('*', cors({
origin: ['http://localhost:3013', 'http://localhost:5679'],
credentials: true,
}))
-app.use('*', errorHandler)
app.use('*', requestLogger)
+app.use('*', errorHandler)
// Health check
app.get('/api/v1/health', (c) => c.json({ status: 'ok', timestamp: new Date().toISOString() }))
diff --git a/backend/src/routes/dramas.ts b/backend/src/routes/dramas.ts
index 197b2aa..6f1488d 100644
--- a/backend/src/routes/dramas.ts
+++ b/backend/src/routes/dramas.ts
@@ -82,6 +82,18 @@ app.post('/', async (c) => {
return created(c, result)
})
+// GET /dramas/stats — must be before /:id
+app.get('/stats', async (c) => {
+ const all = db.select().from(schema.dramas).where(isNull(schema.dramas.deletedAt)).all()
+ const byStatus = Object.entries(
+ all.reduce((acc, d) => {
+ acc[d.status || 'draft'] = (acc[d.status || 'draft'] || 0) + 1
+ return acc
+ }, {} as Record<string, number>)
+ ).map(([status, count]) => ({ status, count }))
+ return success(c, { total: all.length, by_status: byStatus })
+})
+
// GET /dramas/:id - Get drama detail
app.get('/:id', async (c) => {
const id = Number(c.req.param('id'))
@@ -111,11 +123,15 @@ app.get('/:id', async (c) => {
app.put('/:id', async (c) => {
const id = Number(c.req.param('id'))
const body = await c.req.json()
- await db.update(schema.dramas).set({
- ...body,
- tags: body.tags ? JSON.stringify(body.tags) : undefined,
- updatedAt: now(),
- }).where(eq(schema.dramas.id, id))
+ const updates: Record<string, any> = { updatedAt: now() }
+ if (body.title !== undefined) updates.title = body.title
+ if (body.description !== undefined) updates.description = body.description
+ if (body.genre !== undefined) updates.genre = body.genre
+ if (body.style !== undefined) updates.style = body.style
+ if (body.status !== undefined) updates.status = body.status
+ if (body.tags !== undefined) updates.tags = JSON.stringify(body.tags)
+ if (body.metadata !== undefined) updates.metadata = body.metadata
+ db.update(schema.dramas).set(updates).where(eq(schema.dramas.id, id)).run()
return success(c)
})
@@ -126,18 +142,6 @@ app.delete('/:id', async (c) => {
return success(c)
})
-// GET /dramas/stats
-app.get('/stats', async (c) => {
- const all = await db.select().from(schema.dramas).where(isNull(schema.dramas.deletedAt))
- const byStatus = Object.entries(
- all.reduce((acc, d) => {
- acc[d.status || 'draft'] = (acc[d.status || 'draft'] || 0) + 1
- return acc
- }, {} as Record<string, number>)
- ).map(([status, count]) => ({ status, count }))
- return success(c, { total: all.length, by_status: byStatus })
-})
-
// PUT /dramas/:id/characters - Save characters
app.put('/:id/characters', async (c) => {
const dramaId = Number(c.req.param('id'))
diff --git a/backend/src/services/ai.ts b/backend/src/services/ai.ts
index ace82ce..092e0e8 100644
--- a/backend/src/services/ai.ts
+++ b/backend/src/services/ai.ts
@@ -17,8 +17,10 @@ export function getActiveConfig(serviceType: ServiceType): AIConfig | null {
const rows = db.select().from(schema.aiServiceConfigs)
.where(eq(schema.aiServiceConfigs.serviceType, serviceType))
.all()
+ .filter(r => r.isActive)
+ .sort((a, b) => (b.priority || 0) - (a.priority || 0)) // 高优先级优先
- const active = rows.find(r => r.isActive)
+ const active = rows[0]
if (!active) return null
const models = active.model ? JSON.parse(active.model) : []
diff --git a/backend/src/services/ffmpeg-compose.ts b/backend/src/services/ffmpeg-compose.ts
index 098002b..b383374 100644
--- a/backend/src/services/ffmpeg-compose.ts
+++ b/backend/src/services/ffmpeg-compose.ts
@@ -43,14 +43,11 @@ export async function composeStoryboard(storyboardId: number): Promise<string> {
const match = sb.dialogue.match(/^(.+?)[::]/)
if (match) {
const charName = match[1].replace(/[((].+?[))]/, '').trim()
- const chars = db.select().from(schema.characters)
- .where(eq(schema.characters.dramaId, sb.episodeId)).all() // 近似:通过 episode 找 drama
- // 从 episode 找 drama_id
const [ep] = db.select().from(schema.episodes).where(eq(schema.episodes.id, sb.episodeId)).all()
if (ep) {
- const allChars = db.select().from(schema.characters)
+ const chars = db.select().from(schema.characters)
.where(eq(schema.characters.dramaId, ep.dramaId)).all()
- const found = allChars.find(c => c.name === charName)
+ const found = chars.find(c => c.name === charName)
if (found?.voiceStyle) voiceId = found.voiceStyle
}
}