fixed API and stopping delay
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Router } from 'express';
|
||||
import express from 'express';
|
||||
import { requireAdmin } from '../auth.js';
|
||||
import { requireAdmin, createApiKey, listApiKeys, revokeApiKey } from '../auth.js';
|
||||
import { runHealthCheck } from '../streams/checker.js';
|
||||
import { probeStream } from '../streams/probe.js';
|
||||
import { applySeedIfEmpty } from '../sources/seed.js';
|
||||
@@ -19,6 +19,25 @@ import { broadcastGlobal } from '../ws.js';
|
||||
export const router = Router();
|
||||
router.use(requireAdmin);
|
||||
|
||||
// --- API key management ---
|
||||
|
||||
router.get('/api-keys', (_req, res) => {
|
||||
res.json(listApiKeys());
|
||||
});
|
||||
|
||||
router.post('/api-keys', (req, res) => {
|
||||
const label = String(req.body?.label || '').trim();
|
||||
const userId = Number(req.body?.userId) || req.user.id;
|
||||
const key = createApiKey(userId, label);
|
||||
res.status(201).json({ key }); // plaintext key shown exactly once
|
||||
});
|
||||
|
||||
router.delete('/api-keys/:id', (req, res) => {
|
||||
revokeApiKey(Number(req.params.id));
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
|
||||
// Raw body parser used only by the image upload route. The global JSON
|
||||
// parser is mounted before us so we have to opt-out for `image/*`.
|
||||
const rawImageBody = express.raw({ type: ['image/*', 'application/octet-stream'], limit: '5mb' });
|
||||
|
||||
Reference in New Issue
Block a user