initialize project structure with core modules and configuration

This commit is contained in:
ImBenji
2026-04-16 22:47:34 +01:00
parent 82d856a21d
commit 7724fafbdc
20 changed files with 3644 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
const db = require('../db');
const { getLastIngestionBySource } = require('../state');
async function statusRoutes(fastify) {
fastify.get('/status', async () => {
const total = db.prepare('SELECT COUNT(*) AS count FROM articles').get().count;
const bySourceRows = db.prepare('SELECT source, COUNT(*) AS count FROM articles GROUP BY source ORDER BY source').all();
const contentCoverage = db.prepare(`
SELECT
COUNT(*) AS total,
SUM(CASE WHEN content IS NOT NULL AND TRIM(content) <> '' THEN 1 ELSE 0 END) AS with_content,
SUM(CASE WHEN image IS NOT NULL AND TRIM(image) <> '' THEN 1 ELSE 0 END) AS with_image
FROM articles
`).get();
const embeddingCoverage = db.prepare('SELECT COUNT(*) AS count FROM article_embeddings').get();
return {
totalArticles: total,
countsBySource: Object.fromEntries(bySourceRows.map((row) => [row.source, row.count])),
lastIngestionBySource: getLastIngestionBySource(),
contentFetchCoverage: {
withContent: contentCoverage.with_content || 0,
withImage: contentCoverage.with_image || 0,
withEmbedding: embeddingCoverage.count || 0,
total: contentCoverage.total || 0,
contentRatio: contentCoverage.total ? Number((contentCoverage.with_content / contentCoverage.total).toFixed(4)) : 0,
imageRatio: contentCoverage.total ? Number((contentCoverage.with_image / contentCoverage.total).toFixed(4)) : 0,
embeddingRatio: contentCoverage.total ? Number((embeddingCoverage.count / contentCoverage.total).toFixed(4)) : 0,
},
};
});
}
module.exports = statusRoutes;