Skip to content

Text to vertical video in 100+ styles: AI codes each scene (HTML/SVG/WebGL), renders a 9:16 MP4 with music and English/Vietnamese voice. MCP, CLI and REST for AI agents.

Edit video: nút Cài ngay trong app (chạy edit/setup.mjs nền, hiện tiến độ, báo lỗi dễ hiểu)

Lumtekec68d5238f40
diff --git a/edit/http.mjs b/edit/http.mjs
index 2f4ba05..474f130 100644
--- a/edit/http.mjs
+++ b/edit/http.mjs
@@ -1,6 +1,8 @@
// REST cho Edit video (server/server.mjs gọi handleEditRoute). Chống DNS rebinding đã làm ở server (Host),
// ở đây chặn thêm Origin lạ cho mọi lệnh ghi (trang web khác không gửi form upload/đường dẫn/xoá vào được).
// GET /api/edit-options → {ready, missing, setup, styles[], music[], maxUploadBytes}
+// GET /api/edit-setup → tiến độ cài (nút "Cài ngay"): {running, step, ok, word, hint, elapsedS, log[]}
+// POST /api/edit-setup → chạy node edit/setup.mjs nền (409 nếu đang cài)
// GET /api/edits → danh sách
// POST /api/edits → multipart (video ≤ 2 GB, music?, style, musicStyle?, content?, names?, draft?)
// hoặc JSON {path, style, music?(đường dẫn|tên nhạc tổng hợp), content?, names?, draft?}
@@ -15,6 +17,7 @@ import {
ID_RE, EDITS, editDir, newEditId, createEdit, runEditJob, reviseEditJob, editView, listEdits, editStyles, editReady, readEditJob,
markStaleEdits, deleteEdit,
} from './jobs.mjs';
+import { installStatus, startInstall } from './setup-run.mjs';
export const MAX_UPLOAD = 2 * 1024 ** 3; // 2 GB
const MAX_BODY = MAX_UPLOAD + 200 * 1024 ** 2; // + nhạc + trường chữ
@@ -146,6 +149,12 @@ export async function handleEditRoute(req, res, p, { send, readBody, serveFile,
send(res, 200, { ...editReady(), styles: editStyles(), music: MUSIC_LIST.map((m) => ({ id: m.name, desc: m.desc })), maxUploadBytes: MAX_UPLOAD });
return true;
}
+ if (p === '/api/edit-setup' && req.method === 'GET') { send(res, 200, { ...installStatus(), ready: editReady().ready }); return true; }
+ if (p === '/api/edit-setup' && req.method === 'POST') {
+ const r = startInstall();
+ send(res, r.started ? 202 : 409, r.started ? installStatus() : { error: r.reason });
+ return true;
+ }
if (p === '/api/edits' && req.method === 'GET') { send(res, 200, listEdits()); return true; }
if (p === '/api/edits' && req.method === 'POST') {
const ready = editReady();
diff --git a/edit/setup-run.mjs b/edit/setup-run.mjs
new file mode 100644
index 0000000..386a7f9
--- /dev/null
+++ b/edit/setup-run.mjs
@@ -0,0 +1,78 @@
+// Chạy edit/setup.mjs từ giao diện (nút "Cài ngay"): một lúc chỉ 1 lần cài, giữ ~200 dòng log cuối để trang web xem tiến độ.
+// Dòng cuối của setup là chữ trạng thái: READY | NEED_PYTHON | NEED_FFMPEG | NEED_NETWORK | NEED_NPM.
+import path from 'node:path';
+import { spawn } from 'node:child_process';
+import { EDIT, ROOT } from './env.mjs';
+
+const WORDS = new Set(['READY', 'NEED_PYTHON', 'NEED_FFMPEG', 'NEED_NETWORK', 'NEED_NPM']);
+const MAX_LINES = 200;
+
+// Bước người dùng thấy, đoán theo dòng log setup in ra
+const STEPS = [
+ [/^Thiếu ffmpeg/i, 'Kiểm tra ffmpeg'],
+ [/^Tạo môi trường Python/i, 'Tạo môi trường Python'],
+ [/^Cài gói Python/i, 'Cài gói Python (vài trăm MB)'],
+ [/cuBLAS|cuDNN/i, 'Cài phần chạy bằng GPU (~2 GB)'],
+ [/fetching the .*model/i, 'Tải model nhận mặt, người'],
+ [/fonts ready/i, 'Chuẩn bị font phụ đề'],
+ [/^Model chép lời/i, 'Tải model chép lời (~3 GB, lâu nhất)'],
+ [/^Dung lượng/i, 'Kiểm tra lần cuối'],
+];
+
+let run = null; // {proc, lines[], step, startedAt, endedAt, code, word}
+
+function push(line) {
+ const s = line.replace(/\x1b\[[0-9;]*m/g, '').trimEnd();
+ if (!s.trim()) return;
+ for (const [re, step] of STEPS) if (re.test(s.trim())) run.step = step;
+ const w = s.trim();
+ if (WORDS.has(w)) run.word = w;
+ run.lines.push(s);
+ if (run.lines.length > MAX_LINES) run.lines.splice(0, run.lines.length - MAX_LINES);
+}
+
+function feed(stream) {
+ let buf = '';
+ stream.setEncoding('utf8');
+ stream.on('data', (d) => {
+ buf += d;
+ const parts = buf.split(/\r\n|\n|\r/); // pip vẽ thanh tiến độ bằng \r
+ buf = parts.pop();
+ for (const p of parts) push(p);
+ });
+ stream.on('end', () => { if (buf) push(buf); buf = ''; });
+}
+
+export function installStatus() {
+ if (!run) return { running: false, started: false };
+ const running = run.code === null;
+ // Lỗi cần người dùng tự làm (cài Python/ffmpeg): dòng ngay trước chữ trạng thái là lời hướng dẫn
+ let hint = '';
+ if (!running && run.word && run.word !== 'READY') {
+ const i = run.lines.lastIndexOf(run.word);
+ hint = run.lines.slice(Math.max(0, i - 3), i).join('\n');
+ }
+ return {
+ running, started: true, step: run.step,
+ ok: !running && run.code === 0 && run.word === 'READY',
+ word: run.word, code: run.code, hint,
+ elapsedS: Math.round(((run.endedAt || Date.now()) - run.startedAt) / 1000),
+ log: run.lines.slice(-40),
+ };
+}
+
+/** Bắt đầu cài. Trả {started:true} hoặc {started:false, reason}. */
+export function startInstall() {
+ if (run && run.code === null) return { started: false, reason: 'đang cài rồi' };
+ run = { proc: null, lines: [], step: 'Bắt đầu', startedAt: Date.now(), endedAt: 0, code: null, word: '' };
+ const proc = spawn(process.execPath, [path.join(EDIT, 'setup.mjs')], {
+ cwd: ROOT, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'],
+ env: { ...process.env, PYTHONUNBUFFERED: '1', PIP_PROGRESS_BAR: 'off' },
+ });
+ run.proc = proc;
+ feed(proc.stdout); feed(proc.stderr);
+ const cur = run;
+ proc.on('error', (e) => { push('Không chạy được setup: ' + e.message); cur.code = -1; cur.endedAt = Date.now(); });
+ proc.on('close', (code) => { if (cur.code === null) { cur.code = code ?? -1; cur.endedAt = Date.now(); } });
+ return { started: true };
+}
diff --git a/server/public/edit-panel.css b/server/public/edit-panel.css
index f7d48ea..fea5838 100644
--- a/server/public/edit-panel.css
+++ b/server/public/edit-panel.css
@@ -12,6 +12,23 @@
.ed-setup { grid-column: 1 / -1; border-left: 3px solid var(--warn); }
.ed-setup h3 { margin: 0 0 6px; font: 700 20px/1.2 var(--cond); text-transform: uppercase; letter-spacing: .03em; }
.ed-setup p { margin: 0; color: var(--ink-2); font-size: 15px; }
+.ed-setup-act { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-top: 14px; }
+.ed-install { min-height: 44px; padding: 0 22px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font: 800 18px/1 var(--cond); text-transform: uppercase; letter-spacing: .04em; cursor: pointer; }
+.ed-install:hover:not(:disabled) { filter: brightness(1.08); }
+.ed-install:disabled { opacity: .5; cursor: not-allowed; }
+.ed-install-note { color: var(--ink-3); font-size: 14px; }
+.ed-install-prog { margin-top: 14px; }
+.ed-install-step { font-weight: 600; font-size: 15px; }
+.ed-install-step.ok { color: var(--ok); } .ed-install-step.bad { color: var(--bad); }
+.ed-install-bar { height: 4px; margin: 8px 0 10px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
+.ed-install-bar span { display: block; width: 30%; height: 100%; background: var(--accent); animation: edbar 1.4s ease-in-out infinite; }
+.ed-install-prog.stop .ed-install-bar { display: none; }
+@keyframes edbar { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
+@media (prefers-reduced-motion: reduce) { .ed-install-bar span { animation: none; width: 100%; opacity: .5; } }
+.ed-install-hint { margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; font: 400 13px/1.5 var(--mono); white-space: pre-wrap; color: var(--warn); background: rgba(242,201,76,.08); border: 1px solid rgba(242,201,76,.3); }
+.ed-install-prog summary, .ed-setup-manual summary { cursor: pointer; color: var(--ink-3); font-size: 14px; }
+.ed-install-prog pre { max-height: 220px; overflow: auto; margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--bg); font: 400 12px/1.45 var(--mono); color: var(--ink-2); white-space: pre-wrap; word-break: break-all; }
+.ed-setup-manual { margin-top: 12px; }
.drop { display: grid; place-items: center; text-align: center; gap: 6px; min-height: 150px; padding: 18px; border: 2px dashed var(--line); border-radius: 14px; background: var(--bg); cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--bg)); }
diff --git a/server/public/edit-panel.js b/server/public/edit-panel.js
index d635fc5..1ee754f 100644
--- a/server/public/edit-panel.js
+++ b/server/public/edit-panel.js
@@ -30,7 +30,13 @@
state.opts = await fetch('/api/edit-options').then((r) => r.json());
} catch { $('#edSetup').hidden = false; $('#edSetupText').textContent = 'Không gọi được server.'; return; }
const o = state.opts;
- if (!o.ready) { $('#edSetup').hidden = false; $('#edSetupText').innerHTML = `${esc(o.note)}`; $('#edSetupCmd').textContent = o.setup; }
+ if (!o.ready) {
+ $('#edSetup').hidden = false;
+ $('#edSetupText').textContent = 'Phần Edit video cần thêm Python, model chép lời và model nhận mặt. Bấm Cài ngay, LumReels tự cài hết (chỉ làm một lần).';
+ $('#edSetupCmd').textContent = o.setup;
+ // đang cài dở (vd. tải lại trang giữa chừng) → hiện lại tiến độ
+ fetch('/api/edit-setup').then((r) => r.json()).then((st) => { if (st.running) watchInstall(); }).catch(() => {});
+ } else $('#edSetup').hidden = true;
state.style = o.styles[0]?.id || null;
$('#edStyles').innerHTML = o.styles.map((s, i) => `<button type="button" class="sty" role="radio" aria-checked="${i === 0}" tabindex="${i === 0 ? 0 : -1}" data-id="${esc(s.id)}"><span class="n">${esc(s.name)}</span><span class="d">${esc(s.summary)}</span></button>`).join('');
$('#edMusic').innerHTML = '<option value="none">Không nhạc</option>'
@@ -39,6 +45,58 @@
refreshGo();
loadList();
}
+ // ---- nút "Cài ngay": server chạy edit/setup.mjs, trang hỏi tiến độ mỗi 1,5 giây -----------------------------
+ const INSTALL_FAIL = {
+ NEED_PYTHON: 'Máy chưa có Python 3.10–3.12. Cài theo hướng dẫn dưới rồi bấm Cài lại.',
+ NEED_FFMPEG: 'Máy chưa có ffmpeg. Cài theo hướng dẫn dưới rồi bấm Cài lại.',
+ NEED_NETWORK: 'Tải bị lỗi, kiểm tra mạng rồi bấm Cài lại (phần đã tải xong không phải tải lại).',
+ NEED_NPM: 'Thiếu font của LumReels: chạy npm install ở thư mục LumReels rồi bấm Cài lại.',
+ };
+ let installTimer = null;
+ function paintInstall(st) {
+ const prog = $('#edInstallProg'); const step = $('#edInstallStep'); const btn = $('#edInstall');
+ prog.hidden = false;
+ const mm = (s) => `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
+ step.className = 'ed-install-step';
+ if (st.running) {
+ step.textContent = `${st.step || 'Đang cài'}… (${mm(st.elapsedS || 0)})`;
+ btn.disabled = true; btn.textContent = 'Đang cài…';
+ } else if (st.ok) {
+ step.classList.add('ok'); step.textContent = `Cài xong sau ${mm(st.elapsedS || 0)}. Edit video đã sẵn sàng.`;
+ } else {
+ step.classList.add('bad'); step.textContent = INSTALL_FAIL[st.word] || 'Cài chưa xong. Xem chi tiết bên dưới rồi bấm Cài lại.';
+ btn.disabled = false; btn.textContent = 'Cài lại';
+ }
+ prog.classList.toggle('stop', !st.running);
+ $('#edInstallHint').hidden = !st.hint; $('#edInstallHint').textContent = st.hint || '';
+ const log = $('#edInstallLog'); const atEnd = log.scrollTop + log.clientHeight >= log.scrollHeight - 8;
+ log.textContent = (st.log || []).join(String.fromCharCode(10));
+ if (atEnd) log.scrollTop = log.scrollHeight;
+ }
+ function watchInstall() {
+ clearTimeout(installTimer);
+ const tick = async () => {
+ let st;
+ try { st = await fetch('/api/edit-setup').then((r) => r.json()); } catch { installTimer = setTimeout(tick, 3000); return; }
+ paintInstall(st);
+ if (st.running) { installTimer = setTimeout(tick, 1500); return; }
+ if (st.ok && st.ready) setTimeout(() => { state.opts = null; $('#edSetup').hidden = true; init(); }, 1200);
+ };
+ tick();
+ }
+ $('#edInstall').addEventListener('click', async () => {
+ $('#edInstall').disabled = true;
+ try {
+ const r = await fetch('/api/edit-setup', { method: 'POST' });
+ if (!r.ok && r.status !== 409) throw new Error((await r.json().catch(() => ({}))).error || 'HTTP ' + r.status);
+ watchInstall();
+ } catch (e) {
+ $('#edInstall').disabled = false;
+ $('#edInstallProg').hidden = false; $('#edInstallStep').className = 'ed-install-step bad';
+ $('#edInstallStep').textContent = 'Không bắt đầu cài được: ' + e.message;
+ }
+ });
+
// radiogroup: bấm hoặc mũi tên chọn kiểu; chỉ nút đang chọn nằm trong thứ tự Tab (roving tabindex)
function pickStyle(b, focus) {
state.style = b.dataset.id;
diff --git a/server/public/index.html b/server/public/index.html
index 9a8d64e..52ce52f 100644
--- a/server/public/index.html
+++ b/server/public/index.html
@@ -125,7 +125,17 @@
<div class="ed-card ed-setup" id="edSetup" hidden>
<h3>Chưa cài phần Edit video</h3>
<p id="edSetupText"></p>
- <div class="cmd" id="edSetupCmd">node edit/setup.mjs</div>
+ <div class="ed-setup-act">
+ <button type="button" class="ed-install" id="edInstall">Cài ngay</button>
+ <span class="ed-install-note">Tải khoảng 6 GB, mất 5–20 phút tuỳ mạng. Cứ để trang mở.</span>
+ </div>
+ <div class="ed-install-prog" id="edInstallProg" hidden>
+ <div class="ed-install-step" id="edInstallStep" role="status" aria-live="polite"></div>
+ <div class="ed-install-bar" aria-hidden="true"><span></span></div>
+ <div class="ed-install-hint" id="edInstallHint" hidden></div>
+ <details><summary>Xem chi tiết</summary><pre id="edInstallLog"></pre></details>
+ </div>
+ <details class="ed-setup-manual"><summary>Hoặc tự cài bằng lệnh</summary><div class="cmd" id="edSetupCmd">node edit/setup.mjs</div></details>
</div>
<div class="ed-card">
<h2><span class="step">1</span>Video của bạn</h2>