mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
✨ feat: Enhance favorites management with validation, update data structure, and improve UI interactions
This commit is contained in:
parent
bfeae91a96
commit
960e2ee527
10 changed files with 117 additions and 31 deletions
|
|
@ -9,6 +9,28 @@ const updateFavoritesController = async (req, res) => {
|
|||
return res.status(400).json({ message: 'Favorites data is required' });
|
||||
}
|
||||
|
||||
// Validate favorites structure
|
||||
if (!Array.isArray(favorites)) {
|
||||
return res.status(400).json({ message: 'Favorites must be an array' });
|
||||
}
|
||||
|
||||
for (const fav of favorites) {
|
||||
const hasAgent = !!fav.agentId;
|
||||
const hasModel = !!(fav.model && fav.endpoint);
|
||||
|
||||
if (!hasAgent && !hasModel) {
|
||||
return res.status(400).json({
|
||||
message: 'Each favorite must have either agentId or model+endpoint',
|
||||
});
|
||||
}
|
||||
|
||||
if (hasAgent && hasModel) {
|
||||
return res.status(400).json({
|
||||
message: 'Favorite cannot have both agentId and model/endpoint',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const user = await User.findByIdAndUpdate(
|
||||
userId,
|
||||
{ $set: { favorites } },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue