Catch all rss

This commit is contained in:
Ichitux
2026-04-07 20:17:36 +02:00
parent 1afa7d0c17
commit 42bd57161d
2 changed files with 39 additions and 3 deletions

View File

@@ -126,6 +126,25 @@ export function getAllChannels() {
return results; return results;
} }
export function getAllMessages(limit = 50) {
const stmt = db.prepare(
`SELECT * FROM messages
ORDER BY created_at DESC
LIMIT ?`
);
stmt.bind([limit]);
const results = [];
while (stmt.step()) {
const row = stmt.getAsObject();
results.push(row);
}
stmt.free();
return results;
}
export function getLatestMessageTime(channelId) { export function getLatestMessageTime(channelId) {
const stmt = db.prepare( const stmt = db.prepare(
`SELECT MAX(created_at) as latest FROM messages WHERE channel_id = ?` `SELECT MAX(created_at) as latest FROM messages WHERE channel_id = ?`

View File

@@ -1,14 +1,14 @@
import express from 'express'; import express from 'express';
import RSS from 'rss'; import RSS from 'rss';
import { getMessagesByChannel, getAllChannels } from './database.js'; import { getMessagesByChannel, getAllChannels, getAllMessages } from './database.js';
const router = express.Router(); const router = express.Router();
function generateRSSFeed(messages, channelInfo) { function generateRSSFeed(messages, channelInfo, feedUrlSuffix = null) {
const feed = new RSS({ const feed = new RSS({
title: `Discord Channel - ${channelInfo}`, title: `Discord Channel - ${channelInfo}`,
description: 'Messages from Discord channel', description: 'Messages from Discord channel',
feed_url: `${process.env.BASE_URL || 'http://localhost:3000'}/rss/${channelInfo}`, feed_url: `${process.env.BASE_URL || 'http://localhost:3000'}/rss/${feedUrlSuffix || channelInfo}`,
site_url: process.env.BASE_URL || 'http://localhost:3000', site_url: process.env.BASE_URL || 'http://localhost:3000',
language: 'en', language: 'en',
pubDate: new Date(), pubDate: new Date(),
@@ -59,4 +59,21 @@ router.get('/:channelId', (req, res) => {
res.type('application/rss+xml').send(xml); res.type('application/rss+xml').send(xml);
}); });
// GET /rss-all - Combined RSS feed from all channels
router.get('/all', (req, res) => {
const limit = parseInt(req.query.limit, 10) || 50;
const messages = getAllMessages(limit);
if (messages.length === 0) {
return res.status(404).json({
error: 'No messages found',
hint: 'Make sure the bot has fetched messages from channels',
});
}
const xml = generateRSSFeed(messages, 'All Channels', 'all');
res.type('application/rss+xml').send(xml);
});
export default router; export default router;