- AdminJS at /admin with auth (admin role only) - Manage: users, categories, tools, content blocks, settings - DB tables: settings, categories, tools, content_blocks - Users table: added role (user/admin) and is_blocked fields - API: /api/settings, /api/tools, /api/content/:section - Sidebar: admin link visible only for admin users - Removed /logs from public routes (now in AdminJS) - Video converter: fixed ffmpeg codecs for RPi5 (h264_v4l2m2m) - Dependencies: sequelize, @adminjs/sequelize, mariadb
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const db = require('../lib/db');
|
|
|
|
// Public API — used by landing and dashboard to load dynamic content
|
|
|
|
// Get all settings as key-value object
|
|
router.get('/settings', async (req, res) => {
|
|
try {
|
|
const [rows] = await db.pool.execute('SELECT setting_key, setting_value FROM settings');
|
|
const settings = {};
|
|
for (const r of rows) settings[r.setting_key] = r.setting_value;
|
|
res.json(settings);
|
|
} catch (err) {
|
|
res.status(500).json({ error: err.message });
|
|
}
|
|
});
|
|
|
|
// Get categories with their tools
|
|
router.get('/tools', async (req, res) => {
|
|
try {
|
|
const [categories] = await db.pool.execute('SELECT * FROM categories ORDER BY sort_order');
|
|
const [tools] = await db.pool.execute('SELECT * FROM tools WHERE is_enabled = 1 ORDER BY sort_order');
|
|
|
|
const result = categories.map(cat => ({
|
|
...cat,
|
|
tools: tools.filter(t => t.category_id === cat.id),
|
|
}));
|
|
|
|
res.json(result);
|
|
} catch (err) {
|
|
res.status(500).json({ error: err.message });
|
|
}
|
|
});
|
|
|
|
// Get content blocks by section
|
|
router.get('/content/:section', async (req, res) => {
|
|
try {
|
|
const [rows] = await db.pool.execute(
|
|
'SELECT block_key, title, body, sort_order FROM content_blocks WHERE section = ? AND is_visible = 1 ORDER BY sort_order',
|
|
[req.params.section]
|
|
);
|
|
res.json(rows);
|
|
} catch (err) {
|
|
res.status(500).json({ error: err.message });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|