Revert text editor, move more into config file
This commit is contained in:
@@ -1,69 +0,0 @@
|
|||||||
const express = require('express')
|
|
||||||
const fs = require('fs/promises')
|
|
||||||
const path = require('path')
|
|
||||||
const yaml = require('js-yaml')
|
|
||||||
const cors = require('cors')
|
|
||||||
const bodyParser = require('body-parser')
|
|
||||||
|
|
||||||
const app = express()
|
|
||||||
const PORT = process.env.CONFIG_PORT || 3012
|
|
||||||
|
|
||||||
// CORS configuration
|
|
||||||
app.use(cors({
|
|
||||||
origin: ['https://start.kent.pw', 'https://auth.kent.pw'],
|
|
||||||
credentials: true,
|
|
||||||
methods: ['GET', 'POST', 'OPTIONS'],
|
|
||||||
allowedHeaders: [
|
|
||||||
'Content-Type',
|
|
||||||
'Authorization',
|
|
||||||
'Remote-User',
|
|
||||||
'Remote-Name',
|
|
||||||
'Remote-Email',
|
|
||||||
'Remote-Groups',
|
|
||||||
'X-Requested-With'
|
|
||||||
],
|
|
||||||
exposedHeaders: ['Set-Cookie']
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Options preflight
|
|
||||||
app.options('/api/config/update', cors())
|
|
||||||
|
|
||||||
// Raw body parser for YAML
|
|
||||||
app.use(bodyParser.text({ type: 'text/yaml' }))
|
|
||||||
|
|
||||||
// Authentication middleware
|
|
||||||
const requireAuth = (req, res, next) => {
|
|
||||||
const user = req.headers['remote-user']
|
|
||||||
if (!user) {
|
|
||||||
return res.status(401).json({ error: 'Unauthorized' })
|
|
||||||
}
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
|
|
||||||
app.post('/api/config/update', requireAuth, async (req, res) => {
|
|
||||||
try {
|
|
||||||
// Get the raw YAML content from the request body
|
|
||||||
const yamlContent = req.body
|
|
||||||
|
|
||||||
// Validate the YAML by trying to parse it
|
|
||||||
yaml.load(yamlContent)
|
|
||||||
|
|
||||||
// Write to the config file
|
|
||||||
const configPath = path.join('/var/www/html/homepage/public', 'config.yaml')
|
|
||||||
await fs.writeFile(configPath, yamlContent, 'utf8')
|
|
||||||
|
|
||||||
res.status(200).json({ message: 'Configuration updated successfully' })
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error updating configuration:', error)
|
|
||||||
res.status(500).json({ error: 'Failed to update configuration: ' + error.message })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Health check endpoint
|
|
||||||
app.get('/health', (req, res) => {
|
|
||||||
res.status(200).json({ status: 'ok' })
|
|
||||||
})
|
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
|
||||||
console.log(`Config server listening on port ${PORT}`)
|
|
||||||
})
|
|
||||||
@@ -1,15 +1,64 @@
|
|||||||
|
sections:
|
||||||
|
- id: "system"
|
||||||
|
title: "System"
|
||||||
|
icon: "Server"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-blue-50 dark:bg-blue-950/30"
|
||||||
|
iconColor: "text-blue-600 dark:text-blue-400"
|
||||||
|
|
||||||
|
- id: "media"
|
||||||
|
title: "Media"
|
||||||
|
icon: "Play"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-orange-50 dark:bg-orange-950/30"
|
||||||
|
iconColor: "text-orange-600 dark:text-orange-400"
|
||||||
|
|
||||||
|
- id: "monitoring"
|
||||||
|
title: "Monitoring"
|
||||||
|
icon: "Activity"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-emerald-50 dark:bg-emerald-950/30"
|
||||||
|
iconColor: "text-emerald-600 dark:text-emerald-400"
|
||||||
|
|
||||||
|
- id: "tools"
|
||||||
|
title: "Tools"
|
||||||
|
icon: "Settings"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-purple-50 dark:bg-purple-950/30"
|
||||||
|
iconColor: "text-purple-600 dark:text-purple-400"
|
||||||
|
|
||||||
|
- id: "acot"
|
||||||
|
title: "ACOT"
|
||||||
|
icon: "LayoutDashboard"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-sky-50 dark:bg-sky-950/30"
|
||||||
|
iconColor: "text-sky-600 dark:text-sky-400"
|
||||||
|
|
||||||
|
- id: "home"
|
||||||
|
title: "Home"
|
||||||
|
icon: "Home"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-indigo-50 dark:bg-indigo-950/30"
|
||||||
|
iconColor: "text-indigo-600 dark:text-indigo-400"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: "Portainer"
|
- name: "Portainer"
|
||||||
description: "Container Management"
|
description: "Container Management"
|
||||||
url: "https://portainer.kent.pw"
|
url: "https://portainer.kent.pw"
|
||||||
iconName: "portainer"
|
iconName: "portainer"
|
||||||
category: "system"
|
category: "system"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-blue-50 dark:bg-blue-950/30"
|
||||||
|
iconColor: "text-blue-600 dark:text-blue-400"
|
||||||
|
|
||||||
- name: "Gitea"
|
- name: "Gitea"
|
||||||
description: "Git Server"
|
description: "Git Server"
|
||||||
url: "https://gitea.kent.pw"
|
url: "https://gitea.kent.pw"
|
||||||
iconName: "gitea"
|
iconName: "gitea"
|
||||||
category: "system"
|
category: "system"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-green-50 dark:bg-green-950/30"
|
||||||
|
iconColor: "text-green-600 dark:text-green-400"
|
||||||
|
|
||||||
- name: "Cockpit"
|
- name: "Cockpit"
|
||||||
description: "Server Management"
|
description: "Server Management"
|
||||||
@@ -23,18 +72,27 @@ services:
|
|||||||
iconName: "synology"
|
iconName: "synology"
|
||||||
category: "system"
|
category: "system"
|
||||||
monitorName: "Synology Diskstation"
|
monitorName: "Synology Diskstation"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-slate-50 dark:bg-slate-950/30"
|
||||||
|
iconColor: "text-slate-600 dark:text-slate-400"
|
||||||
|
|
||||||
- name: "Plex"
|
- name: "Plex"
|
||||||
description: "Media Server"
|
description: "Media Server"
|
||||||
url: "https://plex.kent.pw"
|
url: "https://plex.kent.pw"
|
||||||
iconName: "plex"
|
iconName: "plex"
|
||||||
category: "media"
|
category: "media"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-orange-50 dark:bg-orange-950/30"
|
||||||
|
iconColor: "text-orange-600 dark:text-orange-400"
|
||||||
|
|
||||||
- name: "Sonarr"
|
- name: "Sonarr"
|
||||||
description: "TV Show Management"
|
description: "TV Show Management"
|
||||||
url: "https://sonarr.kent.pw"
|
url: "https://sonarr.kent.pw"
|
||||||
iconName: "sonarr"
|
iconName: "sonarr"
|
||||||
category: "media"
|
category: "media"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-blue-50 dark:bg-blue-950/30"
|
||||||
|
iconColor: "text-blue-600 dark:text-blue-400"
|
||||||
|
|
||||||
- name: "Jackett"
|
- name: "Jackett"
|
||||||
description: "Torrent Indexer"
|
description: "Torrent Indexer"
|
||||||
@@ -47,6 +105,9 @@ services:
|
|||||||
url: "https://deluge.kent.pw"
|
url: "https://deluge.kent.pw"
|
||||||
iconName: "deluge"
|
iconName: "deluge"
|
||||||
category: "media"
|
category: "media"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-green-50 dark:bg-green-950/30"
|
||||||
|
iconColor: "text-green-600 dark:text-green-400"
|
||||||
|
|
||||||
- name: "Uptime"
|
- name: "Uptime"
|
||||||
description: "Service Monitoring"
|
description: "Service Monitoring"
|
||||||
@@ -54,6 +115,9 @@ services:
|
|||||||
iconName: "uptime-kuma"
|
iconName: "uptime-kuma"
|
||||||
category: "monitoring"
|
category: "monitoring"
|
||||||
monitorName: "Uptime Kuma"
|
monitorName: "Uptime Kuma"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-emerald-50 dark:bg-emerald-950/30"
|
||||||
|
iconColor: "text-emerald-600 dark:text-emerald-400"
|
||||||
|
|
||||||
- name: "AdGuard"
|
- name: "AdGuard"
|
||||||
description: "Network Ad Blocking"
|
description: "Network Ad Blocking"
|
||||||
@@ -61,6 +125,9 @@ services:
|
|||||||
iconName: "adguard-home"
|
iconName: "adguard-home"
|
||||||
category: "system"
|
category: "system"
|
||||||
monitorName: "Adguard Home"
|
monitorName: "Adguard Home"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-emerald-50 dark:bg-emerald-950/30"
|
||||||
|
iconColor: "text-emerald-600 dark:text-emerald-400"
|
||||||
|
|
||||||
- name: "NocoDB"
|
- name: "NocoDB"
|
||||||
description: "Database Platform"
|
description: "Database Platform"
|
||||||
@@ -81,6 +148,9 @@ services:
|
|||||||
url: "https://firefox.kent.pw"
|
url: "https://firefox.kent.pw"
|
||||||
iconName: "firefox"
|
iconName: "firefox"
|
||||||
category: "tools"
|
category: "tools"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-orange-50 dark:bg-orange-950/30"
|
||||||
|
iconColor: "text-orange-600 dark:text-orange-400"
|
||||||
|
|
||||||
- name: "Speedtest"
|
- name: "Speedtest"
|
||||||
description: "Network Speed Monitor"
|
description: "Network Speed Monitor"
|
||||||
@@ -88,6 +158,9 @@ services:
|
|||||||
iconName: "speedtest-tracker"
|
iconName: "speedtest-tracker"
|
||||||
category: "monitoring"
|
category: "monitoring"
|
||||||
monitorName: "Speedtest Tracker"
|
monitorName: "Speedtest Tracker"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-blue-50 dark:bg-blue-950/30"
|
||||||
|
iconColor: "text-blue-600 dark:text-blue-400"
|
||||||
|
|
||||||
- name: "Netdata"
|
- name: "Netdata"
|
||||||
description: "Monitoring Dashboard"
|
description: "Monitoring Dashboard"
|
||||||
@@ -95,6 +168,9 @@ services:
|
|||||||
iconName: "netdata"
|
iconName: "netdata"
|
||||||
category: "monitoring"
|
category: "monitoring"
|
||||||
monitorName: "Netdata"
|
monitorName: "Netdata"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-purple-50 dark:bg-purple-950/30"
|
||||||
|
iconColor: "text-purple-600 dark:text-purple-400"
|
||||||
|
|
||||||
- name: "Drive"
|
- name: "Drive"
|
||||||
description: "File Storage"
|
description: "File Storage"
|
||||||
@@ -108,6 +184,9 @@ services:
|
|||||||
url: "https://dashboard.kent.pw"
|
url: "https://dashboard.kent.pw"
|
||||||
iconName: "lucide-layout-dashboard"
|
iconName: "lucide-layout-dashboard"
|
||||||
category: "acot"
|
category: "acot"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-sky-50 dark:bg-sky-950/30"
|
||||||
|
iconColor: "text-sky-600 dark:text-sky-400"
|
||||||
|
|
||||||
- name: "Inventory"
|
- name: "Inventory"
|
||||||
description: "ACOT Inventory"
|
description: "ACOT Inventory"
|
||||||
@@ -120,9 +199,15 @@ services:
|
|||||||
url: "https://homebridge.kent.pw"
|
url: "https://homebridge.kent.pw"
|
||||||
iconName: "homebridge"
|
iconName: "homebridge"
|
||||||
category: "home"
|
category: "home"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-purple-50 dark:bg-purple-950/30"
|
||||||
|
iconColor: "text-purple-600 dark:text-purple-400"
|
||||||
|
|
||||||
- name: "Scrypted"
|
- name: "Scrypted"
|
||||||
description: "Smart Home Integration"
|
description: "Smart Home Integration"
|
||||||
url: "https://scrypted.kent.pw"
|
url: "https://scrypted.kent.pw"
|
||||||
iconName: "scrypted"
|
iconName: "scrypted"
|
||||||
category: "home"
|
category: "home"
|
||||||
|
cardStyle:
|
||||||
|
background: "bg-indigo-50 dark:bg-indigo-950/30"
|
||||||
|
iconColor: "text-indigo-600 dark:text-indigo-400"
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
const express = require('express')
|
|
||||||
const fs = require('fs/promises')
|
|
||||||
const path = require('path')
|
|
||||||
const yaml = require('js-yaml')
|
|
||||||
|
|
||||||
const router = express.Router()
|
|
||||||
|
|
||||||
router.post('/api/config', async (req, res) => {
|
|
||||||
try {
|
|
||||||
// Get the raw YAML content from the request body
|
|
||||||
const yamlContent = req.body
|
|
||||||
|
|
||||||
// Validate the YAML by trying to parse it
|
|
||||||
yaml.load(yamlContent)
|
|
||||||
|
|
||||||
// Write to the config file
|
|
||||||
const configPath = path.join(process.cwd(), 'public', 'config.yaml')
|
|
||||||
await fs.writeFile(configPath, yamlContent, 'utf8')
|
|
||||||
|
|
||||||
res.status(200).json({ message: 'Configuration updated successfully' })
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error updating configuration:', error)
|
|
||||||
res.status(500).json({ error: 'Failed to update configuration' })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = router
|
|
||||||
137
src/App.tsx
137
src/App.tsx
@@ -7,11 +7,10 @@ import { useTheme } from "@/components/theme-provider"
|
|||||||
import { useMetrics } from "./hooks/useMetrics"
|
import { useMetrics } from "./hooks/useMetrics"
|
||||||
import { useConfig } from "./hooks/useConfig"
|
import { useConfig } from "./hooks/useConfig"
|
||||||
import { ServiceStatus } from "./types/metrics"
|
import { ServiceStatus } from "./types/metrics"
|
||||||
import { ServiceCard } from "./types/services"
|
import { ServiceCard, Section } from "./types/services"
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
|
||||||
import { AlertCircle } from "lucide-react"
|
import { AlertCircle } from "lucide-react"
|
||||||
import { ConfigEditor } from './components/config-editor'
|
|
||||||
|
|
||||||
const getIconUrl = (name: string | undefined, isDark: boolean = false): string => {
|
const getIconUrl = (name: string | undefined, isDark: boolean = false): string => {
|
||||||
if (!name) return ''
|
if (!name) return ''
|
||||||
@@ -55,18 +54,8 @@ function ServiceIcon({ service, isDark }: { service: ServiceCard, isDark: boolea
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default category icons
|
// Default category icons from section configuration
|
||||||
const categoryIcons: Record<string, string> = {
|
const Icon = (LucideIcons as any)['Box']
|
||||||
system: 'Server',
|
|
||||||
media: 'Play',
|
|
||||||
monitoring: 'Activity',
|
|
||||||
tools: 'Settings',
|
|
||||||
acot: 'LayoutDashboard',
|
|
||||||
home: 'Home'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cast to any to avoid TypeScript complexity with dynamic imports
|
|
||||||
const Icon = (LucideIcons as any)[categoryIcons[service.category] || 'Box']
|
|
||||||
return <Icon className="h-6 w-6" />
|
return <Icon className="h-6 w-6" />
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,8 +131,8 @@ function StatusIndicator({ status, responseTime, certDaysRemaining }: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ServiceSection({ title, services, metrics }: {
|
function ServiceSection({ section, services, metrics }: {
|
||||||
title: string,
|
section: Section,
|
||||||
services: ServiceCard[],
|
services: ServiceCard[],
|
||||||
metrics: Record<string, any>
|
metrics: Record<string, any>
|
||||||
}) {
|
}) {
|
||||||
@@ -153,7 +142,7 @@ function ServiceSection({ title, services, metrics }: {
|
|||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<h2 className="text-2xl font-bold">{title}</h2>
|
<h2 className="text-2xl font-bold">{section.title}</h2>
|
||||||
<Separator className="flex-1 ml-4" />
|
<Separator className="flex-1 ml-4" />
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-4">
|
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-4">
|
||||||
@@ -164,77 +153,8 @@ function ServiceSection({ title, services, metrics }: {
|
|||||||
certDaysRemaining: 0
|
certDaysRemaining: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const bgColor = (() => {
|
// Use service-specific style or fall back to section style
|
||||||
switch (service.name) {
|
const style = service.cardStyle || section.cardStyle
|
||||||
case "Portainer":
|
|
||||||
return "bg-blue-50 dark:bg-blue-950/30"
|
|
||||||
case "Gitea":
|
|
||||||
return "bg-green-50 dark:bg-green-950/30"
|
|
||||||
case "Plex":
|
|
||||||
return "bg-orange-50 dark:bg-orange-950/30"
|
|
||||||
case "Sonarr":
|
|
||||||
return "bg-blue-50 dark:bg-blue-950/30"
|
|
||||||
case "AdGuard":
|
|
||||||
return "bg-emerald-50 dark:bg-emerald-950/30"
|
|
||||||
case "Homebridge":
|
|
||||||
return "bg-purple-50 dark:bg-purple-950/30"
|
|
||||||
case "Scrypted":
|
|
||||||
return "bg-indigo-50 dark:bg-indigo-950/30"
|
|
||||||
case "Dashboard":
|
|
||||||
case "Inventory":
|
|
||||||
return "bg-sky-50 dark:bg-sky-950/30"
|
|
||||||
case "DiskStation":
|
|
||||||
return "bg-slate-50 dark:bg-slate-950/30"
|
|
||||||
case "Deluge":
|
|
||||||
return "bg-green-50 dark:bg-green-950/30"
|
|
||||||
case "Firefox":
|
|
||||||
return "bg-orange-50 dark:bg-orange-950/30"
|
|
||||||
case "Uptime":
|
|
||||||
return "bg-emerald-50 dark:bg-emerald-950/30"
|
|
||||||
case "Speedtest":
|
|
||||||
return "bg-blue-50 dark:bg-blue-950/30"
|
|
||||||
case "Netdata":
|
|
||||||
return "bg-purple-50 dark:bg-purple-950/30"
|
|
||||||
default:
|
|
||||||
return "bg-gray-50 dark:bg-gray-950/30"
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
const iconColor = (() => {
|
|
||||||
switch (service.name) {
|
|
||||||
case "Portainer":
|
|
||||||
return "text-blue-600 dark:text-blue-400"
|
|
||||||
case "Gitea":
|
|
||||||
return "text-green-600 dark:text-green-400"
|
|
||||||
case "Plex":
|
|
||||||
return "text-orange-600 dark:text-orange-400"
|
|
||||||
case "Sonarr":
|
|
||||||
return "text-blue-600 dark:text-blue-400"
|
|
||||||
case "AdGuard":
|
|
||||||
return "text-emerald-600 dark:text-emerald-400"
|
|
||||||
case "Homebridge":
|
|
||||||
return "text-purple-600 dark:text-purple-400"
|
|
||||||
case "Scrypted":
|
|
||||||
return "text-indigo-600 dark:text-indigo-400"
|
|
||||||
case "Dashboard":
|
|
||||||
case "Inventory":
|
|
||||||
return "text-sky-600 dark:text-sky-400"
|
|
||||||
case "DiskStation":
|
|
||||||
return "text-slate-600 dark:text-slate-400"
|
|
||||||
case "Deluge":
|
|
||||||
return "text-green-600 dark:text-green-400"
|
|
||||||
case "Firefox":
|
|
||||||
return "text-orange-600 dark:text-orange-400"
|
|
||||||
case "Uptime":
|
|
||||||
return "text-emerald-600 dark:text-emerald-400"
|
|
||||||
case "Speedtest":
|
|
||||||
return "text-blue-600 dark:text-blue-400"
|
|
||||||
case "Netdata":
|
|
||||||
return "text-purple-600 dark:text-purple-400"
|
|
||||||
default:
|
|
||||||
return "text-gray-600 dark:text-gray-400"
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
@@ -244,10 +164,10 @@ function ServiceSection({ title, services, metrics }: {
|
|||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="transition-transform hover:scale-105"
|
className="transition-transform hover:scale-105"
|
||||||
>
|
>
|
||||||
<Card className={bgColor}>
|
<Card className={style.background}>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className={iconColor}>
|
<div className={style.iconColor}>
|
||||||
<ServiceIcon service={service} isDark={isDark} />
|
<ServiceIcon service={service} isDark={isDark} />
|
||||||
</div>
|
</div>
|
||||||
<CardTitle className="ml-2">{service.name}</CardTitle>
|
<CardTitle className="ml-2">{service.name}</CardTitle>
|
||||||
@@ -272,24 +192,14 @@ function ServiceSection({ title, services, metrics }: {
|
|||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const { metrics } = useMetrics()
|
const { metrics } = useMetrics()
|
||||||
const { config, error, saveConfig } = useConfig()
|
const { config, error } = useConfig()
|
||||||
const services = config.services
|
const { services, sections } = config
|
||||||
|
|
||||||
const systemServices = services.filter(s => s.category === 'system')
|
|
||||||
const mediaServices = services.filter(s => s.category === 'media')
|
|
||||||
const monitoringServices = services.filter(s => s.category === 'monitoring')
|
|
||||||
const toolServices = services.filter(s => s.category === 'tools')
|
|
||||||
const acotServices = services.filter(s => s.category === 'acot')
|
|
||||||
const homeServices = services.filter(s => s.category === 'home')
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen p-8 space-y-8">
|
<div className="min-h-screen p-8 space-y-8">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<h1 className="text-4xl font-bold">Kent.pw Homepage</h1>
|
<h1 className="text-4xl font-bold">Kent.pw Homepage</h1>
|
||||||
<div className="flex items-center gap-2">
|
<ThemeToggle />
|
||||||
<ConfigEditor currentConfig={config} onSave={saveConfig} />
|
|
||||||
<ThemeToggle />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
@@ -302,14 +212,21 @@ function App() {
|
|||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{services.length > 0 ? (
|
{sections?.length > 0 ? (
|
||||||
<>
|
<>
|
||||||
<ServiceSection title="System" services={systemServices} metrics={metrics} />
|
{sections.map((section: Section) => {
|
||||||
<ServiceSection title="Media" services={mediaServices} metrics={metrics} />
|
const sectionServices = services.filter((s: { category: string }) => s.category === section.id)
|
||||||
<ServiceSection title="Monitoring" services={monitoringServices} metrics={metrics} />
|
if (sectionServices.length === 0) return null
|
||||||
<ServiceSection title="Tools" services={toolServices} metrics={metrics} />
|
|
||||||
<ServiceSection title="ACOT" services={acotServices} metrics={metrics} />
|
return (
|
||||||
<ServiceSection title="Home" services={homeServices} metrics={metrics} />
|
<ServiceSection
|
||||||
|
key={section.id}
|
||||||
|
section={section}
|
||||||
|
services={sectionServices}
|
||||||
|
metrics={metrics}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</>
|
</>
|
||||||
) : !error && (
|
) : !error && (
|
||||||
<Alert>
|
<Alert>
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
import { useEffect, useState } from 'react'
|
|
||||||
import Editor from '@monaco-editor/react'
|
|
||||||
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Settings2 } from 'lucide-react'
|
|
||||||
import yaml from 'js-yaml'
|
|
||||||
import { ServiceCard } from '@/types/services'
|
|
||||||
|
|
||||||
interface ConfigEditorProps {
|
|
||||||
currentConfig: { services: ServiceCard[] }
|
|
||||||
onSave: (newConfig: string) => Promise<void>
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ConfigEditor({ currentConfig, onSave }: ConfigEditorProps) {
|
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
|
||||||
const [editorContent, setEditorContent] = useState('')
|
|
||||||
const [error, setError] = useState<string | null>(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
try {
|
|
||||||
const yamlString = yaml.dump(currentConfig, { indent: 2 })
|
|
||||||
setEditorContent(yamlString)
|
|
||||||
setError(null)
|
|
||||||
} catch (err) {
|
|
||||||
setError('Failed to convert configuration to YAML')
|
|
||||||
console.error('Error converting config to YAML:', err)
|
|
||||||
}
|
|
||||||
}, [currentConfig])
|
|
||||||
|
|
||||||
const handleSave = async () => {
|
|
||||||
try {
|
|
||||||
// Validate YAML
|
|
||||||
yaml.load(editorContent)
|
|
||||||
|
|
||||||
// If validation passes, save
|
|
||||||
await onSave(editorContent)
|
|
||||||
setIsOpen(false)
|
|
||||||
setError(null)
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : 'Invalid YAML format')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Sheet open={isOpen} onOpenChange={setIsOpen}>
|
|
||||||
<SheetTrigger asChild>
|
|
||||||
<Button variant="outline" size="icon">
|
|
||||||
<Settings2 className="h-[1.2rem] w-[1.2rem]" />
|
|
||||||
<span className="sr-only">Edit configuration</span>
|
|
||||||
</Button>
|
|
||||||
</SheetTrigger>
|
|
||||||
<SheetContent className="w-[50vw] sm:max-w-[80vw]">
|
|
||||||
<SheetHeader>
|
|
||||||
<SheetTitle>Edit Configuration</SheetTitle>
|
|
||||||
</SheetHeader>
|
|
||||||
<div className="h-[80vh] mt-4">
|
|
||||||
<Editor
|
|
||||||
height="90%"
|
|
||||||
defaultLanguage="yaml"
|
|
||||||
value={editorContent}
|
|
||||||
onChange={(value) => setEditorContent(value || '')}
|
|
||||||
options={{
|
|
||||||
minimap: { enabled: false },
|
|
||||||
fontSize: 14,
|
|
||||||
lineNumbers: 'on',
|
|
||||||
scrollBeyondLastLine: false,
|
|
||||||
wordWrap: 'on',
|
|
||||||
wrappingIndent: 'indent',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{error && (
|
|
||||||
<div className="text-red-500 text-sm mt-2">{error}</div>
|
|
||||||
)}
|
|
||||||
<div className="flex justify-end gap-2 mt-4">
|
|
||||||
<Button variant="outline" onClick={() => setIsOpen(false)}>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button onClick={handleSave}>
|
|
||||||
Save Changes
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</SheetContent>
|
|
||||||
</Sheet>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,57 +1,28 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import yaml from 'js-yaml'
|
import yaml from 'js-yaml'
|
||||||
import { ServiceCard } from '../types/services'
|
import { Config } from '../types/services'
|
||||||
|
|
||||||
interface Config {
|
|
||||||
services: ServiceCard[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useConfig() {
|
export function useConfig() {
|
||||||
const [config, setConfig] = useState<Config>({ services: [] })
|
const [config, setConfig] = useState<Config>({ services: [], sections: [] })
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
const loadConfig = async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/config.yaml')
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to load configuration')
|
|
||||||
}
|
|
||||||
const text = await response.text()
|
|
||||||
const parsed = yaml.load(text) as Config
|
|
||||||
setConfig(parsed)
|
|
||||||
setError(null)
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : 'Failed to load configuration')
|
|
||||||
console.error('Error loading configuration:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const saveConfig = async (newConfig: string) => {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/api/config/update', {
|
|
||||||
method: 'POST',
|
|
||||||
credentials: 'include',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'text/yaml',
|
|
||||||
},
|
|
||||||
body: newConfig,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }))
|
|
||||||
throw new Error(errorData.error || 'Failed to save configuration')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reload the config after saving
|
|
||||||
await loadConfig()
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : 'Failed to save configuration')
|
|
||||||
console.error('Error saving configuration:', err)
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const loadConfig = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/config.yaml')
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to load configuration')
|
||||||
|
}
|
||||||
|
const text = await response.text()
|
||||||
|
const parsed = yaml.load(text) as Config
|
||||||
|
setConfig(parsed)
|
||||||
|
setError(null)
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to load configuration')
|
||||||
|
console.error('Error loading configuration:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load config immediately
|
// Load config immediately
|
||||||
loadConfig()
|
loadConfig()
|
||||||
|
|
||||||
@@ -61,5 +32,5 @@ export function useConfig() {
|
|||||||
return () => clearInterval(interval)
|
return () => clearInterval(interval)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return { config, error, saveConfig }
|
return { config, error }
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,31 @@
|
|||||||
import { ReactNode } from 'react'
|
import { ReactNode } from 'react'
|
||||||
|
|
||||||
|
export type CategoryId = 'system' | 'media' | 'monitoring' | 'tools' | 'acot' | 'home'
|
||||||
|
|
||||||
|
export interface CardStyle {
|
||||||
|
background: string
|
||||||
|
iconColor: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Section {
|
||||||
|
id: CategoryId
|
||||||
|
title: string
|
||||||
|
icon: string
|
||||||
|
cardStyle: CardStyle
|
||||||
|
}
|
||||||
|
|
||||||
export interface ServiceCard {
|
export interface ServiceCard {
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
url: string
|
url: string
|
||||||
icon?: ReactNode
|
icon?: ReactNode
|
||||||
iconName?: string
|
iconName?: string
|
||||||
category: 'system' | 'media' | 'monitoring' | 'tools' | 'acot' | 'home'
|
category: CategoryId
|
||||||
monitorName?: string
|
monitorName?: string
|
||||||
|
cardStyle?: CardStyle
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Config {
|
||||||
|
sections: Section[]
|
||||||
|
services: ServiceCard[]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user