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.

Kiểm bản mới trước khi chạy: npm start hỏi cập nhật (git pull --ff-only, npm install nếu thư viện đổi); giao diện báo có bản mới

Lumtek3ee7c8a0b052
diff --git a/package.json b/package.json
index a09929a..d2e7965 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"type": "module",
"description": "Nội dung chữ + mẫu video -> AI viết cảnh HTML -> MP4 dọc 1080x1920",
"scripts": {
+ "prestart": "node scripts/update.mjs",
"start": "node server/server.mjs",
"postinstall": "node engine/setup.mjs",
"make": "node cli.mjs make",
diff --git a/scripts/update.mjs b/scripts/update.mjs
new file mode 100644
index 0000000..a49b2bb
--- /dev/null
+++ b/scripts/update.mjs
@@ -0,0 +1,78 @@
+#!/usr/bin/env node
+// Kiểm bản mới trên GitHub trước khi chạy app (npm start gọi qua "prestart").
+// node scripts/update.mjs : kiểm, có bản mới thì hỏi cập nhật (mặc định Có)
+// node scripts/update.mjs --json : chỉ kiểm, in JSON (server dùng để hiện thông báo trong giao diện)
+// node scripts/update.mjs --yes : có bản mới thì cập nhật luôn, không hỏi
+// Bỏ qua: LUMREELS_SKIP_UPDATE=1. Máy không có mạng / không phải bản clone git thì bỏ qua êm, app vẫn chạy.
+import fs from 'node:fs';
+import path from 'node:path';
+import readline from 'node:readline';
+import { spawnSync } from 'node:child_process';
+import { fileURLToPath } from 'node:url';
+
+const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const git = (args, timeout = 15000) => spawnSync('git', args, { cwd: ROOT, encoding: 'utf8', timeout, windowsHide: true });
+
+export function checkUpdate({ fetch = true } = {}) {
+ if (!fs.existsSync(path.join(ROOT, '.git'))) return { ok: false, reason: 'Không phải bản clone git (tải zip?), không tự kiểm được bản mới' };
+ if (git(['--version'], 5000).status !== 0) return { ok: false, reason: 'Máy chưa có git' };
+ const up = git(['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'], 5000);
+ if (up.status !== 0) return { ok: false, reason: 'Nhánh hiện tại không theo dõi nhánh nào trên GitHub' };
+ if (fetch) {
+ const f = git(['fetch', '--quiet', '--no-tags'], 20000);
+ if (f.status !== 0) return { ok: false, reason: 'Không kết nối được GitHub (mất mạng?)' };
+ }
+ const behind = Number(git(['rev-list', '--count', 'HEAD..@{u}']).stdout.trim()) || 0;
+ const ahead = Number(git(['rev-list', '--count', '@{u}..HEAD']).stdout.trim()) || 0;
+ const dirty = git(['status', '--porcelain', '--untracked-files=no']).stdout.trim().length > 0;
+ const changes = behind ? git(['log', '--format=%s', '-n', '8', 'HEAD..@{u}']).stdout.trim().split(/\r?\n/).filter(Boolean) : [];
+ return { ok: true, behind, ahead, dirty, upstream: up.stdout.trim(), changes, checkedAt: new Date().toISOString() };
+}
+
+export function applyUpdate(log = console.log) {
+ const before = git(['rev-parse', 'HEAD']).stdout.trim();
+ const pull = git(['pull', '--ff-only', '--quiet'], 120000);
+ if (pull.status !== 0) return { ok: false, error: (pull.stderr || pull.stdout || '').trim().slice(-400) };
+ const changed = git(['diff', '--name-only', before, 'HEAD']).stdout.split(/\r?\n/);
+ if (changed.some((f) => f === 'package.json' || f === 'package-lock.json')) {
+ log('Thư viện thay đổi, đang chạy npm install…');
+ const npm = spawnSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['install', '--no-audit', '--no-fund'], { cwd: ROOT, stdio: 'inherit', shell: process.platform === 'win32', timeout: 15 * 60 * 1000 });
+ if (npm.status !== 0) return { ok: false, error: 'npm install lỗi, chạy tay: npm install' };
+ }
+ return { ok: true, files: changed.filter(Boolean).length };
+}
+
+function ask(q) {
+ return new Promise((resolve) => {
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
+ const t = setTimeout(() => { rl.close(); console.log('(không trả lời sau 30 giây, chạy bản hiện tại)'); resolve(false); }, 30000);
+ rl.question(q, (a) => { clearTimeout(t); rl.close(); resolve(!/^\s*(n|no|k|không|khong)\s*$/i.test(a)); });
+ });
+}
+
+async function main() {
+ const argv = process.argv.slice(2);
+ if (argv.includes('--json')) { process.stdout.write(JSON.stringify(checkUpdate())); return; }
+ if (process.env.LUMREELS_SKIP_UPDATE === '1') return;
+ console.log('LumReels: đang kiểm bản mới trên GitHub…');
+ const r = checkUpdate();
+ if (!r.ok) { console.log(` Bỏ qua kiểm bản mới: ${r.reason}.`); return; }
+ if (!r.behind) { console.log(' Đang dùng bản mới nhất.'); return; }
+ console.log(`\n ★ Có ${r.behind} cập nhật mới:`);
+ for (const c of r.changes) console.log(' • ' + c);
+ if (r.behind > r.changes.length) console.log(` • … và ${r.behind - r.changes.length} thay đổi khác`);
+ if (r.dirty || r.ahead) {
+ console.log(`\n Máy có ${r.dirty ? 'file đã sửa tay' : ''}${r.dirty && r.ahead ? ' và ' : ''}${r.ahead ? 'commit riêng chưa có trên GitHub' : ''}, nên không tự cập nhật.`);
+ console.log(' Tự gộp bằng: git stash && git pull && git stash pop (rồi npm install nếu cần)\n');
+ return;
+ }
+ const yes = argv.includes('--yes') || process.env.LUMREELS_AUTO_UPDATE === '1' || (process.stdin.isTTY ? await ask('\n Cập nhật ngay trước khi chạy? [Y/n] ') : false);
+ if (!yes) { console.log(' Chạy bản hiện tại. Cập nhật sau bằng: git pull && npm install\n'); return; }
+ const u = applyUpdate();
+ if (u.ok) console.log(` Đã cập nhật (${u.files} file). Đang khởi động bản mới…\n`);
+ else console.log(` Cập nhật lỗi: ${u.error}\n Chạy bản hiện tại. Cập nhật tay: git pull && npm install\n`);
+}
+
+if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ main().catch((e) => { console.log(' Bỏ qua kiểm bản mới: ' + e.message); });
+}
diff --git a/server/public/app.js b/server/public/app.js
index 230acba..fb62327 100644
--- a/server/public/app.js
+++ b/server/public/app.js
@@ -41,6 +41,26 @@
let showAll = false;
let allJobsCount = 0;
+ // ---------- bản mới ----------
+ async function checkVersion(retry = 3) {
+ let d;
+ try { d = await (await fetch('/api/version')).json(); } catch { return; }
+ const u = d && d.update;
+ if (!u) { if (retry > 0) setTimeout(() => checkVersion(retry - 1), 8000); return; }
+ const box = $('#update-banner');
+ if (!box || !u.ok || !u.behind) return;
+ const key = 'lumreels-hide-update-' + (u.upstream || '') + '-' + u.behind;
+ try { if (localStorage.getItem(key)) return; } catch { /* bỏ qua */ }
+ const t = box.querySelector('.ub-text');
+ t.textContent = '';
+ t.append(`Có ${u.behind} cập nhật mới cho LumReels${u.changes && u.changes[0] ? ' (' + u.changes[0] + (u.behind > 1 ? ', …' : '') + ')' : ''}. Tắt app rồi chạy lại `);
+ const c = document.createElement('code'); c.textContent = 'npm start';
+ t.append(c, ' để cập nhật.');
+ box.hidden = false;
+ box.querySelector('.ub-close').onclick = () => { box.hidden = true; try { localStorage.setItem(key, '1'); } catch { /* bỏ qua */ } };
+ }
+ setTimeout(checkVersion, 1500);
+
// ---------- mẫu ----------
async function loadTemplates() {
$('#grid').innerHTML = '<div class="empty-grid">Đang tải mẫu…</div>';
diff --git a/server/public/index.html b/server/public/index.html
index 4257e3d..d482865 100644
--- a/server/public/index.html
+++ b/server/public/index.html
@@ -12,6 +12,10 @@
<div class="brand"><span class="mark" aria-hidden="true"></span>LumReels</div>
<p class="tag">Chọn mẫu, dán nội dung, AI dựng cảnh, ra MP4 dọc 1080×1920.</p>
</header>
+<div id="update-banner" class="update-banner" role="status" hidden>
+ <span class="ub-text"></span>
+ <button type="button" class="ub-close" aria-label="Ẩn thông báo">×</button>
+</div>
<main class="layout">
<section class="pick" aria-labelledby="h-pick">
diff --git a/server/public/style.css b/server/public/style.css
index dca3e8d..57b2f17 100644
--- a/server/public/style.css
+++ b/server/public/style.css
@@ -150,3 +150,9 @@ dialog a { color: var(--accent); }
.job { grid-template-columns: 110px minmax(0, 1fr); gap: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
+.update-banner { display: flex; align-items: center; gap: 12px; margin: 0 0 18px; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--accent, #ff6a3d); background: color-mix(in srgb, var(--accent, #ff6a3d) 12%, transparent); color: var(--ink); font-size: 15px; line-height: 1.45; }
+.update-banner[hidden] { display: none; }
+.update-banner code { font: 400 13px/1.4 var(--mono); background: var(--bg); padding: 2px 6px; border-radius: 6px; }
+.update-banner .ub-text { flex: 1; }
+.update-banner .ub-close { background: none; border: 0; color: var(--ink-2); font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
+.update-banner .ub-close:hover { color: var(--ink); background: var(--line); }
diff --git a/server/server.mjs b/server/server.mjs
index b5a022e..219737a 100644
--- a/server/server.mjs
+++ b/server/server.mjs
@@ -3,6 +3,7 @@ import http from 'node:http';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
+import { spawn } from 'node:child_process';
import {
ROOT, JOBS, TEMPLATES, loadCatalog, templateName, hasGuidance, createJob, runJob, renderJob, readJob, listJobs, readLog, markStale,
dueJobs, resolveMode, submitScene, previewJob,
@@ -194,6 +195,7 @@ const server = http.createServer(async (req, res) => {
try {
// ---- API ----
if (p === '/api/templates' && req.method === 'GET') return send(res, 200, templateList());
+ if (p === '/api/version' && req.method === 'GET') return send(res, 200, { version: PKG_VERSION, update: updateState });
if (p === '/api/config' && req.method === 'GET') {
return send(res, 200, { defaultMode: DEFAULT_MODE, autoResolves: resolveMode('auto'), claudeAvailable: !!findClaude(), apiAvailable: config.hasApiKey(), outputDir: !!config.outputDir(), rewriteEngine: resolveRewriteEngine() });
}
@@ -300,6 +302,20 @@ function tick() { for (const j of dueJobs()) enqueueJob(j.id, () => runJob(j.id,
setInterval(tick, 15000);
tick();
+// Kiểm bản mới trên GitHub (chạy nền, không chặn app): lúc khởi động và 6 giờ/lần. Giao diện đọc qua /api/version.
+const PKG_VERSION = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
+let updateState = null;
+function checkUpdateBg() {
+ if (process.env.LUMREELS_SKIP_UPDATE === '1') return;
+ const p = spawn(process.execPath, [fileURLToPath(new URL('../scripts/update.mjs', import.meta.url)), '--json'], { windowsHide: true });
+ let out = '';
+ p.stdout.on('data', (d) => { out += d; });
+ p.on('error', () => {});
+ p.on('close', () => { try { updateState = JSON.parse(out); } catch { /* bỏ qua */ } });
+}
+setTimeout(checkUpdateBg, 3000);
+setInterval(checkUpdateBg, 6 * 3600 * 1000).unref();
+
server.listen(PORT, HOST, () => {
console.log(`LumReels: http://${HOST}:${PORT} (chế độ mặc định: ${DEFAULT_MODE} → ${resolveMode(DEFAULT_MODE)}; OUTPUT_DIR ${config.outputDir() ? 'có' : 'chưa đặt'})`);
});