优化
This commit is contained in:
@@ -80,6 +80,7 @@ async function checkAndFixDatabase() {
|
||||
}
|
||||
};
|
||||
|
||||
await addColumn('show_page_name', "ALTER TABLE site_settings ADD COLUMN show_page_name TINYINT(1) DEFAULT 1 AFTER page_name");
|
||||
await addColumn('show_95_bandwidth', "ALTER TABLE site_settings ADD COLUMN show_95_bandwidth TINYINT(1) DEFAULT 0 AFTER default_theme");
|
||||
await addColumn('p95_type', "ALTER TABLE site_settings ADD COLUMN p95_type VARCHAR(20) DEFAULT 'tx' AFTER show_95_bandwidth");
|
||||
await addColumn('blackbox_source_id', "ALTER TABLE site_settings ADD COLUMN blackbox_source_id INT AFTER p95_type");
|
||||
@@ -126,6 +127,7 @@ async function createTable(tableName) {
|
||||
CREATE TABLE IF NOT EXISTS site_settings (
|
||||
id INT PRIMARY KEY DEFAULT 1,
|
||||
page_name VARCHAR(255) DEFAULT '数据可视化展示大屏',
|
||||
show_page_name TINYINT(1) DEFAULT 1,
|
||||
title VARCHAR(255) DEFAULT '数据可视化展示大屏',
|
||||
logo_url TEXT,
|
||||
logo_url_dark TEXT,
|
||||
|
||||
@@ -410,6 +410,7 @@ const serveIndex = async (req, res) => {
|
||||
// Fetch settings
|
||||
let settings = {
|
||||
page_name: '数据可视化展示大屏',
|
||||
show_page_name: 1,
|
||||
title: '数据可视化展示大屏',
|
||||
logo_url: null,
|
||||
logo_url_dark: null,
|
||||
@@ -565,6 +566,7 @@ app.get('/api/settings', async (req, res) => {
|
||||
if (rows.length === 0) {
|
||||
return res.json({
|
||||
page_name: '数据可视化展示大屏',
|
||||
show_page_name: 1,
|
||||
title: '数据可视化展示大屏',
|
||||
logo_url: null,
|
||||
logo_url_dark: null,
|
||||
@@ -595,7 +597,7 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
|
||||
// 2. Destructure fields from body
|
||||
const {
|
||||
page_name, title, logo_url, logo_url_dark, favicon_url,
|
||||
page_name, show_page_name, title, logo_url, logo_url_dark, favicon_url,
|
||||
default_theme, show_95_bandwidth, p95_type,
|
||||
icp_filing, ps_filing
|
||||
} = req.body;
|
||||
@@ -603,6 +605,7 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
// 3. Prepare parameters, prioritizing body but falling back to current
|
||||
const settings = {
|
||||
page_name: page_name !== undefined ? page_name : (current.page_name || '数据可视化展示大屏'),
|
||||
show_page_name: show_page_name !== undefined ? (show_page_name ? 1 : 0) : (current.show_page_name !== undefined ? current.show_page_name : 1),
|
||||
title: title !== undefined ? title : (current.title || '数据可视化展示大屏'),
|
||||
logo_url: logo_url !== undefined ? logo_url : (current.logo_url || null),
|
||||
logo_url_dark: logo_url_dark !== undefined ? logo_url_dark : (current.logo_url_dark || null),
|
||||
@@ -621,13 +624,14 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
// 4. Update database
|
||||
await db.query(
|
||||
`INSERT INTO site_settings (
|
||||
id, page_name, title, logo_url, logo_url_dark, favicon_url,
|
||||
id, page_name, show_page_name, title, logo_url, logo_url_dark, favicon_url,
|
||||
default_theme, show_95_bandwidth, p95_type,
|
||||
blackbox_source_id, latency_source, latency_dest, latency_target,
|
||||
icp_filing, ps_filing
|
||||
) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
page_name = VALUES(page_name),
|
||||
show_page_name = VALUES(show_page_name),
|
||||
title = VALUES(title),
|
||||
logo_url = VALUES(logo_url),
|
||||
logo_url_dark = VALUES(logo_url_dark),
|
||||
@@ -642,7 +646,7 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
icp_filing = VALUES(icp_filing),
|
||||
ps_filing = VALUES(ps_filing)`,
|
||||
[
|
||||
settings.page_name, settings.title, settings.logo_url, settings.logo_url_dark, settings.favicon_url,
|
||||
settings.page_name, settings.show_page_name, settings.title, settings.logo_url, settings.logo_url_dark, settings.favicon_url,
|
||||
settings.default_theme, settings.show_95_bandwidth, settings.p95_type,
|
||||
settings.blackbox_source_id, settings.latency_source, settings.latency_dest, settings.latency_target,
|
||||
settings.icp_filing, settings.ps_filing
|
||||
|
||||
Reference in New Issue
Block a user