修复项目逻辑错误
新增数据库检查
This commit is contained in:
@@ -148,7 +148,8 @@ function getPublicSiteSettings(settings = {}) {
|
||||
network_data_sources: settings.network_data_sources || null,
|
||||
show_server_ip: settings.show_server_ip ? 1 : 0,
|
||||
ip_metric_name: settings.ip_metric_name || null,
|
||||
ip_label_name: settings.ip_label_name || 'address'
|
||||
ip_label_name: settings.ip_label_name || 'address',
|
||||
custom_metrics: settings.custom_metrics || []
|
||||
};
|
||||
}
|
||||
|
||||
@@ -905,7 +906,7 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
const {
|
||||
page_name, show_page_name, title, logo_url, logo_url_dark, favicon_url,
|
||||
default_theme, show_95_bandwidth, p95_type, require_login_for_server_details,
|
||||
icp_filing, ps_filing, network_data_sources, show_server_ip
|
||||
icp_filing, ps_filing, network_data_sources, show_server_ip, ip_metric_name, ip_label_name, custom_metrics
|
||||
} = req.body;
|
||||
|
||||
// 3. Prepare parameters, prioritizing body but falling back to current
|
||||
@@ -931,7 +932,8 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
network_data_sources: network_data_sources !== undefined ? network_data_sources : (current.network_data_sources || null),
|
||||
show_server_ip: show_server_ip !== undefined ? (show_server_ip ? 1 : 0) : (current.show_server_ip || 0),
|
||||
ip_metric_name: ip_metric_name !== undefined ? ip_metric_name : (current.ip_metric_name || null),
|
||||
ip_label_name: ip_label_name !== undefined ? ip_label_name : (current.ip_label_name || 'address')
|
||||
ip_label_name: ip_label_name !== undefined ? ip_label_name : (current.ip_label_name || 'address'),
|
||||
custom_metrics: custom_metrics !== undefined ? JSON.stringify(custom_metrics) : (current.custom_metrics || '[]')
|
||||
};
|
||||
|
||||
await db.query(`
|
||||
@@ -939,8 +941,8 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
id, page_name, show_page_name, title, logo_url, logo_url_dark, favicon_url,
|
||||
default_theme, show_95_bandwidth, p95_type, require_login_for_server_details,
|
||||
blackbox_source_id, latency_source, latency_dest, latency_target,
|
||||
icp_filing, ps_filing, network_data_sources, show_server_ip
|
||||
) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
icp_filing, ps_filing, network_data_sources, show_server_ip, ip_metric_name, ip_label_name
|
||||
) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
page_name = VALUES(page_name),
|
||||
show_page_name = VALUES(show_page_name),
|
||||
@@ -959,12 +961,15 @@ app.post('/api/settings', requireAuth, async (req, res) => {
|
||||
icp_filing = VALUES(icp_filing),
|
||||
ps_filing = VALUES(ps_filing),
|
||||
network_data_sources = VALUES(network_data_sources),
|
||||
show_server_ip = VALUES(show_server_ip)`,
|
||||
show_server_ip = VALUES(show_server_ip),
|
||||
ip_metric_name = VALUES(ip_metric_name),
|
||||
ip_label_name = VALUES(ip_label_name)`,
|
||||
[
|
||||
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.require_login_for_server_details,
|
||||
settings.blackbox_source_id, settings.latency_source, settings.latency_dest, settings.latency_target,
|
||||
settings.icp_filing, settings.ps_filing, settings.network_data_sources, settings.show_server_ip
|
||||
settings.icp_filing, settings.ps_filing, settings.network_data_sources, settings.show_server_ip,
|
||||
settings.ip_metric_name, settings.ip_label_name
|
||||
]
|
||||
);
|
||||
|
||||
@@ -1421,6 +1426,16 @@ async function start() {
|
||||
const REFRESH_INT = parseInt(process.env.REFRESH_INTERVAL) || 5000;
|
||||
setInterval(broadcastMetrics, REFRESH_INT);
|
||||
|
||||
// Periodic cleanup of rate limit buckets to prevent memory leak
|
||||
setInterval(() => {
|
||||
const now = Date.now();
|
||||
for (const [key, bucket] of requestBuckets.entries()) {
|
||||
if (bucket.resetAt <= now) {
|
||||
requestBuckets.delete(key);
|
||||
}
|
||||
}
|
||||
}, 3600000); // Once per hour
|
||||
|
||||
server.listen(PORT, HOST, () => {
|
||||
console.log(`\n 🚀 Data Visualization Display Wall (WebSocket Enabled)`);
|
||||
console.log(` 📊 Server running at http://${HOST === '0.0.0.0' ? 'localhost' : HOST}:${PORT}`);
|
||||
|
||||
Reference in New Issue
Block a user