Initial commit
This commit is contained in:
50
src/lib/config.ts
Normal file
50
src/lib/config.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const CONFIG_PATH = path.join(process.cwd(), 'config.json')
|
||||
|
||||
export interface Site {
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
interval_min: number
|
||||
}
|
||||
|
||||
export interface Database {
|
||||
id: string
|
||||
name: string
|
||||
host: string
|
||||
port: number
|
||||
database: string
|
||||
username: string
|
||||
password: string
|
||||
ssl: boolean
|
||||
color: string
|
||||
}
|
||||
|
||||
export interface Service {
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
icon: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
sites: Site[]
|
||||
databases: Database[]
|
||||
services: Service[]
|
||||
}
|
||||
|
||||
export function readConfig(): Config {
|
||||
const raw = fs.readFileSync(CONFIG_PATH, 'utf-8')
|
||||
return JSON.parse(raw)
|
||||
}
|
||||
|
||||
export function writeConfig(config: Config): void {
|
||||
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), 'utf-8')
|
||||
}
|
||||
|
||||
export function generateId(): string {
|
||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
|
||||
}
|
||||
Reference in New Issue
Block a user