优化安装脚本

This commit is contained in:
CN-JS-HuiBai
2026-04-05 15:23:08 +08:00
parent d7f8db89a3
commit 035ebd8d40
6 changed files with 181 additions and 23 deletions

View File

@@ -216,12 +216,13 @@ app.post('/api/setup/init', async (req, res) => {
title VARCHAR(255) DEFAULT '数据可视化展示大屏',
logo_url TEXT,
default_theme VARCHAR(20) DEFAULT 'dark',
show_95_bandwidth TINYINT(1) DEFAULT 0,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
`);
await connection.query(`
INSERT IGNORE INTO site_settings (id, page_name, title, default_theme)
VALUES (1, '数据可视化展示大屏', '数据可视化展示大屏', 'dark')
INSERT IGNORE INTO site_settings (id, page_name, title, default_theme, show_95_bandwidth)
VALUES (1, '数据可视化展示大屏', '数据可视化展示大屏', 'dark', 0)
`);
await connection.end();
@@ -487,7 +488,8 @@ app.get('/api/settings', async (req, res) => {
return res.json({
page_name: '数据可视化展示大屏',
title: '数据可视化展示大屏',
logo_url: null
logo_url: null,
show_95_bandwidth: 0
});
}
res.json(rows[0]);
@@ -499,18 +501,19 @@ app.get('/api/settings', async (req, res) => {
// Update site settings
app.post('/api/settings', requireAuth, async (req, res) => {
const { page_name, title, logo_url, default_theme } = req.body;
try {
await db.query(
`INSERT INTO site_settings (id, page_name, title, logo_url, default_theme)
VALUES (1, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
page_name = VALUES(page_name),
title = VALUES(title),
logo_url = VALUES(logo_url),
default_theme = VALUES(default_theme)`,
[page_name, title, logo_url, default_theme]
);
const { page_name, title, logo_url, default_theme, show_95_bandwidth } = req.body;
try {
await db.query(
`INSERT INTO site_settings (id, page_name, title, logo_url, default_theme, show_95_bandwidth)
VALUES (1, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
page_name = VALUES(page_name),
title = VALUES(title),
logo_url = VALUES(logo_url),
default_theme = VALUES(default_theme),
show_95_bandwidth = VALUES(show_95_bandwidth)`,
[page_name, title, logo_url, default_theme, show_95_bandwidth ? 1 : 0]
);
res.json({ success: true });
} catch (err) {
console.error('Error updating settings:', err);