72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const app = express();
|
|
|
|
app.use(express.static('public'));
|
|
app.use(express.json());
|
|
|
|
// Session Management für Freigabe
|
|
const sessions = new Map();
|
|
|
|
// Gesundheitscheck für APK
|
|
app.get('/api/health', (req, res) => {
|
|
res.json({ status: 'online', timestamp: Date.now() });
|
|
});
|
|
|
|
// Session erstellen (für QR-Code)
|
|
app.post('/api/session/create', (req, res) => {
|
|
const id = Math.random().toString(36).substring(7);
|
|
sessions.set(id, {
|
|
status: 'pending',
|
|
created: Date.now(),
|
|
expires: Date.now() + (30 * 60 * 1000) // 30 Minuten
|
|
});
|
|
res.json({ sessionId: id, qrData: `kids://auth/${id}` });
|
|
});
|
|
|
|
// Session Status prüfen
|
|
app.get('/api/session/:id', (req, res) => {
|
|
const session = sessions.get(req.params.id);
|
|
if (!session) return res.status(404).json({ error: 'not found' });
|
|
if (Date.now() > session.expires) {
|
|
sessions.delete(req.params.id);
|
|
return res.json({ status: 'expired' });
|
|
}
|
|
res.json(session);
|
|
});
|
|
|
|
// Freigabe durch Eltern
|
|
app.post('/api/session/:id/approve', (req, res) => {
|
|
const { duration = 30, jellyfinUser = 'kind-default' } = req.body;
|
|
sessions.set(req.params.id, {
|
|
status: 'approved',
|
|
approvedAt: Date.now(),
|
|
expires: Date.now() + (duration * 60000),
|
|
jellyfinUser
|
|
});
|
|
res.json({ success: true });
|
|
});
|
|
|
|
// Spiele-Liste
|
|
app.get('/api/games', (req, res) => {
|
|
res.json([
|
|
{ id: 'bubbles', name: 'Blubber-Blasen', type: 'touch', age: 2 },
|
|
{ id: 'memory', name: 'Memory', type: 'touch', age: 4 },
|
|
{ id: 'drawing', name: 'Malen', type: 'touch', age: 3 },
|
|
{ id: 'nes-mario', name: 'Super Mario', type: 'emulator', system: 'nes', age: 5 },
|
|
{ id: 'snes-mario', name: 'Super Mario World', type: 'emulator', system: 'snes', age: 5 },
|
|
{ id: 'megadrive-sonic', name: 'Sonic', type: 'emulator', system: 'megadrive', age: 5 }
|
|
]);
|
|
});
|
|
|
|
// Jellyfin Proxy (kindersicher)
|
|
app.get('/api/media/list', async (req, res) => {
|
|
// Hier Jellyfin API aufrufen und filtern
|
|
res.json([
|
|
{ id: 1, title: 'Peppa Wutz', thumb: '/covers/peppa.jpg', age: 2 },
|
|
{ id: 2, title: 'Sendung mit der Maus', thumb: '/covers/maus.jpg', age: 3 }
|
|
]);
|
|
});
|
|
|
|
app.listen(3000, () => console.log('Kids Game Server on :3000'));
|