Download api/server/middleware/validateMessageReq.js from Zhitomir/chat: direct link, hf CLI and curl.
- Browser
- Download file 778 Bytes
-
https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/middleware/validateMessageReq.js
- Command line
-
hf download hf://spaces/Zhitomir/chat/api/server/middleware/validateMessageReq.js
-
curl -L -o validateMessageReq.js https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/middleware/validateMessageReq.js
778 Bytes
| 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; | |