🎬 火宝短剧 - 基于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
feat(desktop): 后端路径全面接入环境变量注入
Connor1e73b2908c6d
diff --git a/backend/src/agents/skills.ts b/backend/src/agents/skills.tsindex 82369a7..4ca958c 100644--- a/backend/src/agents/skills.ts+++ b/backend/src/agents/skills.ts@@ -12,11 +12,19 @@ import { Workspace, LocalFilesystem } from '@mastra/core/workspace'const __filename = fileURLToPath(import.meta.url)const __dirname = path.dirname(__filename)-const WORKSPACE_DIR = path.resolve(__dirname, '../../workspace')+// 桌面版由 Electron 主进程注入 WORKSPACE_PATH(userData 下的可写副本);dev 锚定 backend/workspace+const WORKSPACE_DIR = process.env.WORKSPACE_PATH+ ? path.resolve(process.env.WORKSPACE_PATH)+ : path.resolve(__dirname, '../../workspace')const SKILLS_DIR = path.join(WORKSPACE_DIR, 'skills')// 启动时确保工作目录存在(Agent 文件读写的 jail 根)-fs.mkdirSync(SKILLS_DIR, { recursive: true })+// 桌面版打包后模块可能仍从只读位置加载,失败不阻断启动(路由层会给出明确报错)+try {+ fs.mkdirSync(SKILLS_DIR, { recursive: true })+} catch (err) {+ console.warn(`[skills] 工作目录创建失败(只读环境?): ${(err as Error).message}`)+}/** 每个 Agent 注册的 skill 目录(相对 workspace/skills/,含子规范目录;目录名需符合 Agent Skills 规范:小写+连字符) */const AGENT_SKILL_MAP: Record<string, string[]> = {diff --git a/backend/src/index.ts b/backend/src/index.tsindex b0a84b5..c11f272 100644--- a/backend/src/index.ts+++ b/backend/src/index.ts@@ -24,6 +24,7 @@ import { requestLogger, errorHandler } from './middleware/logger.js'import { db, schema } from './db/index.js'import { eq } from 'drizzle-orm'import { now } from './utils/response.js'+import { DATA_ROOT } from './utils/paths.js'const __dirname = path.dirname(fileURLToPath(import.meta.url))const projectRoot = path.resolve(__dirname, '../..')@@ -67,10 +68,10 @@ app.use('/static/*', async (c, next) => {await next()if (c.res.ok) c.header('Cache-Control', 'public, max-age=31536000, immutable')})-app.use('/static/*', serveStatic({ root: path.join(projectRoot, 'data') }))+app.use('/static/*', serveStatic({ root: DATA_ROOT }))-// Serve frontend (production build)-const distPath = path.join(projectRoot, 'frontend', 'dist')+// Serve frontend (production build) — 桌面版由主进程注入 FRONTEND_DIST(resources/frontend)+const distPath = process.env.FRONTEND_DIST || path.join(projectRoot, 'frontend', 'dist')app.use('*', serveStatic({ root: distPath }))app.get('*', serveStatic({ root: distPath, path: 'index.html' }))diff --git a/backend/src/utils/ffmpeg.ts b/backend/src/utils/ffmpeg.tsindex 2545027..7994f01 100644--- a/backend/src/utils/ffmpeg.ts+++ b/backend/src/utils/ffmpeg.ts@@ -17,8 +17,9 @@ import { createRequire } from 'module'const ffprobeStatic = createRequire(import.meta.url)('ffprobe-static') as { path: string }// ffmpeg-static 类型声明为 string,实际平台不支持时为 null-const ffmpegPath = ffmpegPathImport as string | null-const ffprobePath = (ffprobeStatic?.path as string | null) || null+// 桌面版通过 FFMPEG_BIN/FFPROBE_BIN 指向随包二进制(resources/bin),优先于 npm 内置+const ffmpegPath = process.env.FFMPEG_BIN || (ffmpegPathImport as string | null)+const ffprobePath = process.env.FFPROBE_BIN || (ffprobeStatic?.path as string | null) || null// 系统未安装 ffmpeg 时使用项目内置二进制if (ffmpegPath) ffmpeg.setFfmpegPath(ffmpegPath)@@ -72,7 +73,7 @@ export async function checkFfmpegSuite(): Promise<FfmpegSuite> {console.warn(`[ffmpeg] 内置二进制不可用 (ffmpeg=${ffmpegOk ? 'ok' : 'FAIL'}, ffprobe=${ffprobeOk ? 'ok' : 'FAIL'})。` +`海报帧提取与视频拼接将跳过/失败。修复:删除 node_modules 后在本机重新 npm install,` +- `或设置 FFMPEG_BIN 指向有效的 ffmpeg 可执行文件`+ `或设置 FFMPEG_BIN/FFPROBE_BIN 指向有效的可执行文件`)}return suite