add intelligence features; implement signals and predictions pages in admin panel
This commit is contained in:
+49
-5
@@ -1,5 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const fastifyStatic = require('@fastify/static');
|
||||
const db = require('../db');
|
||||
const config = require('../config');
|
||||
const Database = require('better-sqlite3');
|
||||
@@ -46,16 +47,59 @@ function checkAuth(request, reply) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const htmlPath = path.join(__dirname, '..', '..', 'admin.html');
|
||||
const publicDir = path.join(__dirname, '..', '..', 'public', 'admin');
|
||||
const assetsDir = path.join(publicDir, 'assets');
|
||||
const pagesDir = path.join(publicDir, 'pages');
|
||||
|
||||
// map pretty url → page html file. keep these close to the routes so its
|
||||
// obvious when a page gets added or renamed.
|
||||
const pageMap = {
|
||||
'/admin/articles': path.join(pagesDir, 'articles.html'),
|
||||
'/admin/events': path.join(pagesDir, 'events.html'),
|
||||
'/admin/stats': path.join(pagesDir, 'stats.html'),
|
||||
'/admin/sql': path.join(pagesDir, 'sql.html'),
|
||||
'/admin/intelligence/knowledge': path.join(pagesDir, 'intelligence', 'knowledge.html'),
|
||||
'/admin/intelligence/predictions': path.join(pagesDir, 'intelligence', 'predictions.html'),
|
||||
'/admin/intelligence/signals': path.join(pagesDir, 'intelligence', 'signals.html'),
|
||||
'/admin/intelligence/graph': path.join(pagesDir, 'intelligence', 'graph.html'),
|
||||
};
|
||||
|
||||
function sendPage(reply, filePath) {
|
||||
reply.type('text/html');
|
||||
reply.header('Cache-Control', 'no-cache');
|
||||
return fs.createReadStream(filePath);
|
||||
}
|
||||
|
||||
async function adminRoutes(fastify) {
|
||||
|
||||
fastify.get('/admin', async (request, reply) => {
|
||||
if (!checkAuth(request, reply)) return;
|
||||
reply.type('text/html');
|
||||
return fs.createReadStream(htmlPath);
|
||||
// gate every request under /admin/* behind basic auth (covers pages, api, and assets)
|
||||
fastify.addHook('onRequest', async (request, reply) => {
|
||||
if (!checkAuth(request, reply)) return reply;
|
||||
});
|
||||
|
||||
// static assets (css + js) under /admin/assets/*
|
||||
fastify.register(fastifyStatic, {
|
||||
root: assetsDir,
|
||||
prefix: '/admin/assets/',
|
||||
decorateReply: false,
|
||||
cacheControl: false,
|
||||
});
|
||||
|
||||
// top-level entry — redirect to articles
|
||||
fastify.get('/admin', async (request, reply) => {
|
||||
reply.redirect('/admin/articles');
|
||||
});
|
||||
|
||||
// intelligence root — redirect to the knowledge subsection
|
||||
fastify.get('/admin/intelligence', async (request, reply) => {
|
||||
reply.redirect('/admin/intelligence/knowledge');
|
||||
});
|
||||
|
||||
// wire up each pretty page path
|
||||
for (const [route, filePath] of Object.entries(pageMap)) {
|
||||
fastify.get(route, async (request, reply) => sendPage(reply, filePath));
|
||||
}
|
||||
|
||||
// list articles — all of them, not just the ones with embeddings
|
||||
fastify.get('/admin/api/articles', async (request, reply) => {
|
||||
if (!checkAuth(request, reply)) return;
|
||||
|
||||
Reference in New Issue
Block a user