feat: web admin panel + better-sqlite3 migration + Docker fixes

- Added Express.js admin panel on port 3001 (ADMIN_PORT env)
  - Dashboard: stats (users, products, purchases, revenue)
  - Users: list, details, ban/unban toggle
  - Products: CRUD by category
  - Wallets: list with balances
  - Purchases: history with filters
  - Audit log: view audit trail
  - Auth: token-based login with ADMIN_SECRET env var
- Migrated sqlite3 → better-sqlite3
  - database.js: async adapter (runAsync/allAsync/getAsync)
  - purchaseService.js: lastID → lastInsertRowid
  - userService.js: lastID → lastInsertRowid
  - Removed sqlite3 from package.json
- Fixed: dotenv/config import added to index.js
- Fixed: ENCRYPTION_KEY validation (32+ char hex)
- Fixed: Dockerfile multi-stage build (no python needed)
- Fixed: Docker DNS (network: host in build)
- Fixed: docker-compose port 3001, healthcheck on 3001
- Added express, cookie-parser, pino-pretty, better-sqlite3 deps
This commit is contained in:
NW
2026-06-22 10:54:01 +01:00
parent 25d8507b11
commit 4657b1dfb5
24 changed files with 1619 additions and 931 deletions

215
src/admin/public/style.css Normal file
View File

@@ -0,0 +1,215 @@
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #f5f5f5;
--card: #fff;
--text: #1a1a1a;
--muted: #666;
--primary: #2563eb;
--danger: #dc2626;
--success: #16a34a;
--border: #e5e5e5;
--radius: 8px;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.5;
}
.topnav {
display: flex;
align-items: center;
gap: 1rem;
padding: 0.75rem 1.5rem;
background: var(--card);
border-bottom: 1px solid var(--border);
flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.nav-links { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.nav-links a {
padding: 0.4rem 0.75rem;
text-decoration: none;
color: var(--muted);
border-radius: var(--radius);
font-size: 0.9rem;
}
.nav-links a:hover, .nav-links a.active {
background: var(--primary);
color: #fff;
}
.logout-btn {
margin-left: auto;
padding: 0.4rem 0.75rem;
background: var(--danger);
color: #fff;
text-decoration: none;
border-radius: var(--radius);
font-size: 0.9rem;
}
.content { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.2rem; margin-bottom: 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin-bottom: 1.5rem;
}
.stat-card {
background: var(--card);
padding: 1.25rem;
border-radius: var(--radius);
border: 1px solid var(--border);
text-align: center;
}
.stat-value { display: block; font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.stat-label { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }
table {
width: 100%;
border-collapse: collapse;
background: var(--card);
border-radius: var(--radius);
overflow: hidden;
border: 1px solid var(--border);
}
th, td { padding: 0.6rem 0.75rem; text-align: left; font-size: 0.9rem; }
th { background: #fafafa; font-weight: 600; border-bottom: 2px solid var(--border); }
td { border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f9fafb; }
.badge {
display: inline-block;
padding: 0.15rem 0.5rem;
border-radius: 999px;
font-size: 0.75rem;
font-weight: 600;
}
.badge-active { background: #dcfce7; color: var(--success); }
.badge-banned { background: #fee2e2; color: var(--danger); }
.btn, .btn-sm, button {
display: inline-block;
padding: 0.5rem 1rem;
background: var(--primary);
color: #fff;
border: none;
border-radius: var(--radius);
cursor: pointer;
text-decoration: none;
font-size: 0.9rem;
}
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.btn:hover, .btn-sm:hover, button:hover { opacity: 0.9; }
.btn-danger, .btn-danger:hover { background: var(--danger); }
.btn-success, .btn-success:hover { background: var(--success); }
.btn-secondary { background: var(--muted); }
.form, .inline-form {
display: flex;
flex-direction: column;
gap: 0.75rem;
max-width: 500px;
}
.inline-form { flex-direction: row; flex-wrap: wrap; align-items: end; max-width: none; }
.form label { font-weight: 600; font-size: 0.9rem; }
input, select, textarea {
padding: 0.5rem;
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 0.9rem;
font-family: inherit;
}
textarea { min-height: 80px; resize: vertical; }
.form-section {
background: var(--card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1rem;
margin-bottom: 1rem;
}
.form-section summary {
font-weight: 600;
cursor: pointer;
margin-bottom: 0.75rem;
}
.detail-card {
background: var(--card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 1.25rem;
margin-bottom: 1rem;
}
.detail-card p { margin-bottom: 0.4rem; }
.flash {
padding: 0.75rem 1rem;
border-radius: var(--radius);
margin-bottom: 1rem;
font-size: 0.9rem;
}
.flash-info { background: #dbeafe; color: #1e40af; }
.flash-error { background: #fee2e2; color: #991b1b; }
.login-page {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #e5e7eb;
}
.login-box {
background: var(--card);
padding: 2rem;
border-radius: var(--radius);
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
width: 100%;
max-width: 360px;
}
.login-box h1 { text-align: center; margin-bottom: 1.5rem; }
.login-box label { display: block; margin-bottom: 0.25rem; font-weight: 600; }
.login-box input { width: 100%; margin-bottom: 1rem; }
.login-box button { width: 100%; }
.error { color: var(--danger); text-align: center; margin-bottom: 1rem; }
code { background: #f1f5f9; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
pre { font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; max-width: 300px; }
@media (max-width: 640px) {
.topnav { flex-direction: column; align-items: flex-start; }
.logout-btn { margin-left: 0; }
.stats-grid { grid-template-columns: 1fr 1fr; }
table { font-size: 0.8rem; }
th, td { padding: 0.4rem; }
}