feat: Michess – Initiales Setup auf Basis von chessu

- Rebranding: chessu → Michess (Header, Footer, Metadata, Session-Cookie)
- Stockfish KI-Integration: 6 Schwierigkeitsgrade (Anfänger bis Meister)
- Admin-Panel: Nutzerverwaltung, Sperren/Entsperren, Git-Pull-Update
- Freundessystem: Anfragen, Freundesliste, Nutzersuche
- DB-Schema: role, banned, friend_request, friendship Tabellen
- Docker: NAS-optimiertes docker-compose.yml mit PostgreSQL Healthcheck
- Stockfish binary via apk im Alpine-Image installiert
- .env.example für einfaches Deployment
- scripts/update.sh für manuelles NAS-Update
- Brain.md + Plan.md als Projekt-Gedächtnis

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Michess
2026-04-13 10:02:52 +02:00
parent 29968f023d
commit 7dac042d73
28 changed files with 1760 additions and 89 deletions

View File

@@ -20,11 +20,25 @@ const server = createServer(app);
// database
await db.connect();
db.query(INIT_TABLES, (err) => {
db.query(INIT_TABLES, async (err) => {
if (err) {
console.error(err);
} else {
console.log("Tables initialized");
console.log("Michess tables initialized");
// Set admin role for ADMIN_EMAIL if configured
const adminEmail = process.env.ADMIN_EMAIL;
if (adminEmail) {
try {
await db.query(
`UPDATE "user" SET role='admin' WHERE email=$1 AND role='user'`,
[adminEmail]
);
console.log(`Admin role ensured for: ${adminEmail}`);
} catch (e) {
console.error("Failed to set admin role:", e);
}
}
}
});
@@ -33,6 +47,20 @@ app.use(cors(corsConfig));
app.use(express.json());
app.set("trust proxy", 1);
app.use(session);
// Ban check middleware
app.use("/v1", (req: Request, res: Response, next: NextFunction) => {
if (req.session.user?.id && typeof req.session.user.id === "number") {
const user = req.session.user as { banned?: boolean };
if (user.banned) {
req.session.destroy(() => {});
res.status(403).json({ message: "Your account has been banned." });
return;
}
}
next();
});
app.use("/v1", routes);
// socket.io
@@ -41,8 +69,8 @@ io.use((socket, next) => {
session(socket.request as Request, {} as Response, next as NextFunction);
});
io.use((socket, next) => {
const session = socket.request.session;
if (session && session.user) {
const sess = socket.request.session;
if (sess && sess.user) {
next();
} else {
console.log("io.use: no session");
@@ -53,5 +81,5 @@ initSocket();
const port = process.env.PORT || 3001;
server.listen(port, () => {
console.log(`chessu api server listening on :${port}`);
console.log(`Michess API server listening on :${port}`);
});