add: added limit param to message get url to send fewer messages

This commit is contained in:
Lukian 2025-05-11 21:32:19 +02:00
parent 9052a99972
commit bd3cbc528c
3 changed files with 19 additions and 10 deletions

View file

@ -4,17 +4,13 @@ const {
getChannels,
getChannel,
addChannel,
getMessage,
getMessages,
addMessage,
deleteMessage,
addMention,
getMentions,
getUserByUsername,
deleteChannelMessages,
deleteChannel,
setHasReplies,
addReply,
getMessageReplies
} = require('../libs/mysql');
const rateLimit = require("express-rate-limit");
@ -130,13 +126,14 @@ async function getReplies(message, connection) {
router.get('/:name/messages', async (req, res) => {
const name = req.params.name;
const limit = Number(req.query.limit) || 10;
const connection = await getConnection();
const channel = await getChannel(connection, name);
if (!channel[0]) {
connection.end();
return res.send('No channel found');
}
const messages = await getMessages(connection, channel[0].id);
const messages = await getMessages(connection, channel[0].id, limit);
for (const message of messages) {
if (message.content.includes('@')) {