mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00

* refactor: optimize backend operations for client requests * fix: message styling * refactor: Improve handleKeyUp logic in StreamRunManager.js and handleText.js * refactor: Improve handleKeyUp logic in StreamRunManager.js and handleText.js * fix: clear new convo messages on clear all convos * fix: forgot to pass userId to getConvo * refactor: update getPartialText to send basePayload.text
28 lines
774 B
JavaScript
28 lines
774 B
JavaScript
const { getConvo } = require('~/models');
|
|
|
|
// Middleware to validate conversationId and user relationship
|
|
const validateMessageReq = async (req, res, next) => {
|
|
let conversationId = req.params.conversationId || req.body.conversationId;
|
|
|
|
if (conversationId === 'new') {
|
|
return res.status(200).send([]);
|
|
}
|
|
|
|
if (!conversationId && req.body.message) {
|
|
conversationId = req.body.message.conversationId;
|
|
}
|
|
|
|
const conversation = await getConvo(req.user.id, conversationId);
|
|
|
|
if (!conversation) {
|
|
return res.status(404).json({ error: 'Conversation not found' });
|
|
}
|
|
|
|
if (conversation.user !== req.user.id) {
|
|
return res.status(403).json({ error: 'User not authorized for this conversation' });
|
|
}
|
|
|
|
next();
|
|
};
|
|
|
|
module.exports = validateMessageReq;
|