diff --git a/backend/src/routes/video.js b/backend/src/routes/video.js index 2551101..fa2d19b 100644 --- a/backend/src/routes/video.js +++ b/backend/src/routes/video.js @@ -136,6 +136,7 @@ router.post( voice = 'zh-CN-XiaoxiaoNeural', resolution = '1920x1080', extraPrompt = '', + saveDir = '', subtitleStyle = {} } = req.body || {}; @@ -426,6 +427,7 @@ router.post( voice = 'zh-CN-XiaoxiaoNeural', resolution = '1920x1080', extraPrompt = '', + saveDir = '', subtitleStyle = {} } = req.body || {}; if (!libraryId) throw new ValidationError('缺少 libraryId'); @@ -453,14 +455,14 @@ router.post( textTasks.set(id, task); setTimeout(() => textTasks.delete(id), 30 * 60 * 1000); - runTextVideo({ task, library, title: String(title).trim(), content: text, images, url, key, model: mdl, voice, width: Number.isFinite(w)?w:1920, height: Number.isFinite(h)?h:1080, extraPrompt: String(extraPrompt||''), subtitleStyle: subtitleStyle||{}, req }).catch((err) => { + runTextVideo({ task, library, title: String(title).trim(), content: text, images, url, key, model: mdl, voice, width: Number.isFinite(w)?w:1920, height: Number.isFinite(h)?h:1080, extraPrompt: String(extraPrompt||''), saveDir: String(saveDir||''), subtitleStyle: subtitleStyle||{}, req }).catch((err) => { task.status = 'error'; task.error = err.message || String(err); }); res.json({ success: true, taskId: id }); }) ); async function runTextVideo(ctx) { - const { task, library, title, content, images, url, key, model, voice, width, height, extraPrompt, subtitleStyle, req } = ctx; + const { task, library, title, content, images, url, key, model, voice, width, height, extraPrompt, saveDir, subtitleStyle, req } = ctx; const work = fs.mkdtempSync(path.join(os.tmpdir(), 'flypic-tv-')); try { // 生成背景图(若无图片) @@ -522,10 +524,14 @@ async function runTextVideo(ctx) { const finalTmp = path.join(work, 'final.mp4'); await videotool.concatSegments(segFiles, finalTmp); + // 6) 落库:保存到用户选择的目录(默认素材库根目录) + const safeDir = String(saveDir || '').replace(/^\/+/, '').replace(/\.\./g, ''); + const baseDir = safeDir ? path.join(library.path, safeDir) : library.path; + try { fs.mkdirSync(baseDir, { recursive: true }); } catch (_) {} const safeTitle = String(title).replace(/[\\/:*?"<>|]/g, '_').slice(0, 60) || 'AI视频'; - let target = path.join(library.path, `${safeTitle}.mp4`); + let target = path.join(baseDir, `${safeTitle}.mp4`); let n = 1; - while (fs.existsSync(target)) { target = path.join(library.path, `${safeTitle}_${n}.mp4`); n++; } + while (fs.existsSync(target)) { target = path.join(baseDir, `${safeTitle}_${n}.mp4`); n++; } fs.copyFileSync(finalTmp, target); await reindex(req, library.path, target); diff --git a/frontend/src/components/AIVideoStudioModal.jsx b/frontend/src/components/AIVideoStudioModal.jsx index cdd43b9..840d4fa 100644 --- a/frontend/src/components/AIVideoStudioModal.jsx +++ b/frontend/src/components/AIVideoStudioModal.jsx @@ -60,6 +60,8 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) { const [keyword, setKeyword] = useState(''); const [picked, setPicked] = useState([]); const [taskId, setTaskId] = useState(''); + const [folders, setFolders] = useState([]); + const [saveDir, setSaveDir] = useState(''); const [task, setTask] = useState(null); const [error, setError] = useState(''); const [starting, setStarting] = useState(false); @@ -92,6 +94,26 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) { useEffect(() => { if (libraryId) loadImages(''); }, [libraryId]); + const flattenFolders = (nodes, acc = []) => { + for (const n of (nodes || [])) { + if (n && n.path) acc.push(n.path); + if (n && n.children) flattenFolders(n.children, acc); + } + return acc; + }; + + useEffect(() => { + if (!libraryId) return; + (async () => { + try { + const r = await fetch(`/api/image/folders?libraryId=${libraryId}`, { headers: auth }); + const d = await r.json(); + const tree = (d && d.data && d.data.folders) || []; + setFolders(flattenFolders(tree)); + } catch (_) { setFolders([]); } + })(); + }, [libraryId]); + const togglePick = (img) => { setPicked((list) => { const i = list.findIndex((x) => x.path === img.path); @@ -109,7 +131,6 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) { setTask(d); if (d.status === 'done' || d.status === 'error') { clearInterval(iv); - if (d.status === 'done') setTimeout(() => { onDone && onDone(d.resultPath); onClose(); }, 1200); } } catch (_) {} }, 1500); @@ -157,7 +178,7 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) { libraryId, title: title.trim(), content: content.trim(), images: imgs, - voice, resolution, extraPrompt: '', + voice, resolution, extraPrompt: '', saveDir, subtitleStyle: { position: subtitlePos, color: subtitleColor, fontSizePct: subtitleSize } }; const r = await fetch('/api/video/aigenerate-text', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${getToken()}` }, body: JSON.stringify(body) }); @@ -351,6 +372,14 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) { +
+ + +
+
提供商 / 模型 / KEY 在右上角「设置 → AI 视频」里配置,普通文本模型即可;配音与字幕由本地合成。 @@ -374,8 +403,8 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) { {error &&
{error}
}
- {!running && !done && (