Initial commit of Step Admin panel

This commit is contained in:
Chaos
2026-03-24 21:33:48 +08:00
commit 81045c5d57
45 changed files with 4327 additions and 0 deletions

36
scripts/init-db.ts Normal file
View File

@@ -0,0 +1,36 @@
import Database from 'better-sqlite3';
import path from 'path';
import fs from 'fs';
const dataDir = path.resolve('./data');
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}
const db = new Database(path.join(dataDir, 'app.db'));
db.exec(`
CREATE TABLE IF NOT EXISTS certificates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
device_name TEXT NOT NULL,
subject TEXT NOT NULL,
serial_number TEXT UNIQUE NOT NULL,
status TEXT NOT NULL DEFAULT 'active', -- 'active', 'revoked', 'expired'
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
expires_at DATETIME NOT NULL,
revoked_at DATETIME,
file_path TEXT NOT NULL,
created_by TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS audit_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
action TEXT NOT NULL,
details TEXT NOT NULL,
ip_address TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
created_by TEXT NOT NULL
);
`);
console.log('Database initialized successfully.');