1 Commits
Author SHA1 Message Date
jinghui 254a939f55 v1.4.16: AI视频生成完成不再自动关闭弹窗 + 支持选择保存目录
- 生成完成后弹窗保持打开(原 1.2s 后自动 onClose 移除),手动「关闭并刷新」
- 新增「保存到目录」下拉(素材库根目录+全部子文件夹),后端按 saveDir 落库
- 双击图片灯箱:onDoubleClick 增加 preventDefault 防浏览器吞双击事件
2026-11-22 12:00:08 +08:00
3 changed files with 44 additions and 9 deletions

No files matched your search

+10 -4
View File
@@ -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);
+33 -4
View File
@@ -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 }) {
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">保存到目录</label>
<select className={input} value={saveDir} onChange={(e) => setSaveDir(e.target.value)} disabled={running||done}>
<option value="">素材库根目录</option>
{folders.map((p) => <option key={p} value={p}>{p}</option>)}
</select>
</div>
<div className="flex items-start gap-2 rounded-lg bg-gray-50 dark:bg-gray-900/50 border border-gray-200 dark:border-gray-700 px-3 py-2 text-xs text-gray-600 dark:text-gray-400">
<Settings className="w-3.5 h-3.5 mt-0.5 flex-shrink-0" />
<span>提供商 / 模型 / KEY 在右上角「设置 → AI 视频」里配置,普通文本模型即可;配音与字幕由本地合成。</span>
@@ -374,8 +403,8 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
{error && <div className="text-sm text-red-600 bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-800 rounded-lg px-3 py-2">{error}</div>}
<div className="flex justify-end gap-3 pt-1">
<button onClick={onClose} disabled={running||starting} className="px-4 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50">
{done ? '关闭' : '取消'}
<button onClick={() => (done ? (onDone && onDone(task?.resultPath)) : onClose())} disabled={running||starting} className="px-4 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-50">
{done ? '关闭并刷新' : '取消'}
</button>
{!running && !done && (
<button onClick={handleStart} disabled={starting} className="px-5 py-2 text-sm rounded-lg bg-purple-600 hover:bg-purple-700 text-white font-medium disabled:opacity-50 flex items-center gap-2">
+1 -1
View File
@@ -58,7 +58,7 @@ const ImageCell = ({
height: `${image.calculatedHeight}px`
}}
onClick={(e) => onImageClick(image, e, flatIndex)}
onDoubleClick={() => onImageDoubleClick(image, flatIndex)}
onDoubleClick={(e) => { e.preventDefault(); onImageDoubleClick(image, flatIndex); }}
onContextMenu={(e) => onContextMenu(e, image)}
draggable={true}
onDragStart={(e) => onDragStart(e, image)}