From f423e1f79146c183bd98eef7003750e0b166f67b Mon Sep 17 00:00:00 2001 From: canglan Date: Thu, 16 Jul 2026 04:02:19 +0800 Subject: [PATCH] fix: dynamic site name from DB, displayed in header/title/sidebar --- backend/server.js | 17 +++++++++++++++-- public/index.html | 6 +++--- public/js/app.js | 4 ++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/server.js b/backend/server.js index 1dc6d1d..3544b96 100644 --- a/backend/server.js +++ b/backend/server.js @@ -17,6 +17,19 @@ const HTML_PATH = path.join(PUBLIC_DIR, 'index.html'); let cachedHtml = null; let htmlTimestamp = 0; +let cachedSiteName = 'MC举报系统'; + +function getSiteName() { return cachedSiteName; } + +async function refreshSiteName() { + if (!isInstalled()) return; + try { + const { getPool } = require('./db'); + const p = await getPool(); + const [rows] = await p.execute("SELECT v FROM settings WHERE k='site_name'"); + if (rows.length > 0) cachedSiteName = rows[0].v; + } catch {} +} function getHtmlWithKey() { const stat = fs.statSync(HTML_PATH); @@ -26,7 +39,7 @@ function getHtmlWithKey() { const cfg = getConfig(); const key = cfg?.api_key || ''; const redirect = isInstalled() ? '' : ''; - html = html.replace('', `${redirect}`); + html = html.replace('', `${redirect}`); cachedHtml = html; htmlTimestamp = mtime; return html; @@ -135,6 +148,6 @@ app.use((err, req, res, next) => { }); app.listen(PORT, () => { - if (isInstalled()) console.log(`Server running at http://localhost:${PORT}`); + if (isInstalled()) { refreshSiteName().then(() => console.log(`Server running at http://localhost:${PORT}`)); } else console.log(`System not installed. Visit http://localhost:${PORT}/#/install`); }).on('error', (err) => { console.error('Failed to start:', err.message); process.exit(1); }); diff --git a/public/index.html b/public/index.html index 8e8fdec..8b40180 100644 --- a/public/index.html +++ b/public/index.html @@ -3,14 +3,14 @@ - MC举报系统 + MC举报系统
- +
登录 注册 @@ -22,7 +22,7 @@