feat: add docker monitoring and ui fixes

This commit is contained in:
mstfyldz
2026-06-03 00:58:54 +03:00
parent e5dc347a0b
commit 29d03604f9
24 changed files with 1682 additions and 553 deletions
+26 -8
View File
@@ -21,6 +21,7 @@ export interface Database {
password: string
ssl: boolean
color: string
db_type: 'postgres' | 'mysql'
}
export interface Service {
@@ -31,10 +32,17 @@ export interface Service {
description: string
}
export interface DockerHost {
id: string
name: string
url: string
}
export interface Config {
sites: Site[]
databases: Database[]
services: Service[]
docker_hosts: DockerHost[]
}
export function generateId(): string {
@@ -54,11 +62,14 @@ export async function readConfig(): Promise<Config> {
await pool.query(`INSERT INTO config_sites (id, name, url, interval_min) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING`, [site.id, site.name, site.url, site.interval_min || 5])
}
for (const db of oldConfig.databases || []) {
await pool.query(`INSERT INTO config_databases (id, name, host, port, database, username, password, ssl, color) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) ON CONFLICT DO NOTHING`, [db.id, db.name, db.host, db.port, db.database, db.username, db.password, db.ssl || false, db.color])
await pool.query(`INSERT INTO config_databases (id, name, host, port, database, username, password, ssl, color, db_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT DO NOTHING`, [db.id, db.name, db.host, db.port, db.database, db.username, db.password, db.ssl || false, db.color, db.db_type || 'postgres'])
}
for (const svc of oldConfig.services || []) {
await pool.query(`INSERT INTO config_services (id, name, url, icon, description) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING`, [svc.id, svc.name, svc.url, svc.icon, svc.description])
}
for (const host of oldConfig.docker_hosts || []) {
await pool.query(`INSERT INTO config_docker_hosts (id, name, url) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING`, [host.id, host.name, host.url])
}
// Dosyanın uzantısını değiştirerek migration'ın bittiğini işaretle
fs.renameSync(CONFIG_PATH, CONFIG_PATH + '.bak')
@@ -69,43 +80,50 @@ export async function readConfig(): Promise<Config> {
}
// DB'den oku
const [sitesRes, dbsRes, svcsRes] = await Promise.all([
const [sitesRes, dbsRes, svcsRes, dockerRes] = await Promise.all([
pool.query(`SELECT * FROM config_sites`),
pool.query(`SELECT * FROM config_databases`),
pool.query(`SELECT * FROM config_services`),
pool.query(`SELECT * FROM config_docker_hosts`),
])
return {
sites: sitesRes.rows as Site[],
databases: dbsRes.rows as Database[],
services: svcsRes.rows as Service[]
services: svcsRes.rows as Service[],
docker_hosts: dockerRes.rows as DockerHost[]
}
}
export async function addConfigItem(type: 'site' | 'database' | 'service', item: any): Promise<any> {
export async function addConfigItem(type: 'site' | 'database' | 'service' | 'docker', item: any): Promise<any> {
const newItem = { ...item, id: generateId() }
if (type === 'site') {
await pool.query(`INSERT INTO config_sites (id, name, url, interval_min) VALUES ($1, $2, $3, $4)`, [newItem.id, newItem.name, newItem.url, newItem.interval_min || 5])
} else if (type === 'database') {
await pool.query(`INSERT INTO config_databases (id, name, host, port, database, username, password, ssl, color) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, [newItem.id, newItem.name, newItem.host, newItem.port, newItem.database, newItem.username, newItem.password, newItem.ssl || false, newItem.color])
await pool.query(`INSERT INTO config_databases (id, name, host, port, database, username, password, ssl, color, db_type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`, [newItem.id, newItem.name, newItem.host, newItem.port, newItem.database, newItem.username, newItem.password, newItem.ssl || false, newItem.color, newItem.db_type || 'postgres'])
} else if (type === 'service') {
await pool.query(`INSERT INTO config_services (id, name, url, icon, description) VALUES ($1, $2, $3, $4, $5)`, [newItem.id, newItem.name, newItem.url, newItem.icon, newItem.description])
} else if (type === 'docker') {
await pool.query(`INSERT INTO config_docker_hosts (id, name, url) VALUES ($1, $2, $3)`, [newItem.id, newItem.name, newItem.url])
}
return newItem
}
export async function updateConfigItem(type: 'site' | 'database' | 'service', id: string, item: any): Promise<void> {
export async function updateConfigItem(type: 'site' | 'database' | 'service' | 'docker', id: string, item: any): Promise<void> {
if (type === 'site') {
await pool.query(`UPDATE config_sites SET name=$1, url=$2, interval_min=$3 WHERE id=$4`, [item.name, item.url, item.interval_min || 5, id])
} else if (type === 'database') {
await pool.query(`UPDATE config_databases SET name=$1, host=$2, port=$3, database=$4, username=$5, password=$6, ssl=$7, color=$8 WHERE id=$9`, [item.name, item.host, item.port, item.database, item.username, item.password, item.ssl || false, item.color, id])
await pool.query(`UPDATE config_databases SET name=$1, host=$2, port=$3, database=$4, username=$5, password=$6, ssl=$7, color=$8, db_type=$9 WHERE id=$10`, [item.name, item.host, item.port, item.database, item.username, item.password, item.ssl || false, item.color, item.db_type || 'postgres', id])
} else if (type === 'service') {
await pool.query(`UPDATE config_services SET name=$1, url=$2, icon=$3, description=$4 WHERE id=$5`, [item.name, item.url, item.icon, item.description, id])
} else if (type === 'docker') {
await pool.query(`UPDATE config_docker_hosts SET name=$1, url=$2 WHERE id=$3`, [item.name, item.url, id])
}
}
export async function deleteConfigItem(type: 'site' | 'database' | 'service', id: string): Promise<void> {
export async function deleteConfigItem(type: 'site' | 'database' | 'service' | 'docker', id: string): Promise<void> {
if (type === 'site') await pool.query(`DELETE FROM config_sites WHERE id=$1`, [id])
else if (type === 'database') await pool.query(`DELETE FROM config_databases WHERE id=$1`, [id])
else if (type === 'service') await pool.query(`DELETE FROM config_services WHERE id=$1`, [id])
else if (type === 'docker') await pool.query(`DELETE FROM config_docker_hosts WHERE id=$1`, [id])
}