Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
254a939f55 |
No files matched your search
@@ -136,6 +136,7 @@ router.post(
|
|||||||
voice = 'zh-CN-XiaoxiaoNeural',
|
voice = 'zh-CN-XiaoxiaoNeural',
|
||||||
resolution = '1920x1080',
|
resolution = '1920x1080',
|
||||||
extraPrompt = '',
|
extraPrompt = '',
|
||||||
|
saveDir = '',
|
||||||
subtitleStyle = {}
|
subtitleStyle = {}
|
||||||
} = req.body || {};
|
} = req.body || {};
|
||||||
|
|
||||||
@@ -426,6 +427,7 @@ router.post(
|
|||||||
voice = 'zh-CN-XiaoxiaoNeural',
|
voice = 'zh-CN-XiaoxiaoNeural',
|
||||||
resolution = '1920x1080',
|
resolution = '1920x1080',
|
||||||
extraPrompt = '',
|
extraPrompt = '',
|
||||||
|
saveDir = '',
|
||||||
subtitleStyle = {}
|
subtitleStyle = {}
|
||||||
} = req.body || {};
|
} = req.body || {};
|
||||||
if (!libraryId) throw new ValidationError('缺少 libraryId');
|
if (!libraryId) throw new ValidationError('缺少 libraryId');
|
||||||
@@ -453,14 +455,14 @@ router.post(
|
|||||||
textTasks.set(id, task);
|
textTasks.set(id, task);
|
||||||
setTimeout(() => textTasks.delete(id), 30 * 60 * 1000);
|
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);
|
task.status = 'error'; task.error = err.message || String(err);
|
||||||
});
|
});
|
||||||
res.json({ success: true, taskId: id });
|
res.json({ success: true, taskId: id });
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
async function runTextVideo(ctx) {
|
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-'));
|
const work = fs.mkdtempSync(path.join(os.tmpdir(), 'flypic-tv-'));
|
||||||
try {
|
try {
|
||||||
// 生成背景图(若无图片)
|
// 生成背景图(若无图片)
|
||||||
@@ -522,10 +524,14 @@ async function runTextVideo(ctx) {
|
|||||||
const finalTmp = path.join(work, 'final.mp4');
|
const finalTmp = path.join(work, 'final.mp4');
|
||||||
await videotool.concatSegments(segFiles, finalTmp);
|
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视频';
|
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;
|
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);
|
fs.copyFileSync(finalTmp, target);
|
||||||
await reindex(req, library.path, target);
|
await reindex(req, library.path, target);
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
|||||||
const [keyword, setKeyword] = useState('');
|
const [keyword, setKeyword] = useState('');
|
||||||
const [picked, setPicked] = useState([]);
|
const [picked, setPicked] = useState([]);
|
||||||
const [taskId, setTaskId] = useState('');
|
const [taskId, setTaskId] = useState('');
|
||||||
|
const [folders, setFolders] = useState([]);
|
||||||
|
const [saveDir, setSaveDir] = useState('');
|
||||||
const [task, setTask] = useState(null);
|
const [task, setTask] = useState(null);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [starting, setStarting] = useState(false);
|
const [starting, setStarting] = useState(false);
|
||||||
@@ -92,6 +94,26 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
|||||||
|
|
||||||
useEffect(() => { if (libraryId) loadImages(''); }, [libraryId]);
|
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) => {
|
const togglePick = (img) => {
|
||||||
setPicked((list) => {
|
setPicked((list) => {
|
||||||
const i = list.findIndex((x) => x.path === img.path);
|
const i = list.findIndex((x) => x.path === img.path);
|
||||||
@@ -109,7 +131,6 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
|||||||
setTask(d);
|
setTask(d);
|
||||||
if (d.status === 'done' || d.status === 'error') {
|
if (d.status === 'done' || d.status === 'error') {
|
||||||
clearInterval(iv);
|
clearInterval(iv);
|
||||||
if (d.status === 'done') setTimeout(() => { onDone && onDone(d.resultPath); onClose(); }, 1200);
|
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}, 1500);
|
}, 1500);
|
||||||
@@ -157,7 +178,7 @@ export default function AIVideoStudioModal({ libraryId, onClose, onDone }) {
|
|||||||
libraryId, title: title.trim(),
|
libraryId, title: title.trim(),
|
||||||
content: content.trim(),
|
content: content.trim(),
|
||||||
images: imgs,
|
images: imgs,
|
||||||
voice, resolution, extraPrompt: '',
|
voice, resolution, extraPrompt: '', saveDir,
|
||||||
subtitleStyle: { position: subtitlePos, color: subtitleColor, fontSizePct: subtitleSize }
|
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) });
|
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>
|
</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">
|
<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" />
|
<Settings className="w-3.5 h-3.5 mt-0.5 flex-shrink-0" />
|
||||||
<span>提供商 / 模型 / KEY 在右上角「设置 → AI 视频」里配置,普通文本模型即可;配音与字幕由本地合成。</span>
|
<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>}
|
{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">
|
<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">
|
<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 ? '关闭' : '取消'}
|
{done ? '关闭并刷新' : '取消'}
|
||||||
</button>
|
</button>
|
||||||
{!running && !done && (
|
{!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">
|
<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">
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ const ImageCell = ({
|
|||||||
height: `${image.calculatedHeight}px`
|
height: `${image.calculatedHeight}px`
|
||||||
}}
|
}}
|
||||||
onClick={(e) => onImageClick(image, e, flatIndex)}
|
onClick={(e) => onImageClick(image, e, flatIndex)}
|
||||||
onDoubleClick={() => onImageDoubleClick(image, flatIndex)}
|
onDoubleClick={(e) => { e.preventDefault(); onImageDoubleClick(image, flatIndex); }}
|
||||||
onContextMenu={(e) => onContextMenu(e, image)}
|
onContextMenu={(e) => onContextMenu(e, image)}
|
||||||
draggable={true}
|
draggable={true}
|
||||||
onDragStart={(e) => onDragStart(e, image)}
|
onDragStart={(e) => onDragStart(e, image)}
|
||||||
|
|||||||
Reference in new issue
Block a user