mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🔗 feat: Enhance Share Functionality, Optimize DataTable & Fix Critical Bugs (#5220)
* 🔄 refactor: frontend and backend share link logic; feat: qrcode for share link; feat: refresh link * 🐛 fix: Conditionally render shared link and refactor share link creation logic * 🐛 fix: Correct conditional check for shareId in ShareButton component * 🔄 refactor: Update shared links API and data handling; improve query parameters and response structure * 🔄 refactor: Update shared links pagination and response structure; replace pageNumber with cursor for improved data fetching * 🔄 refactor: DataTable performance optimization * fix: delete shared link cache update * 🔄 refactor: Enhance shared links functionality; add conversationId to shared link model and update related components * 🔄 refactor: Add delete functionality to SharedLinkButton; integrate delete mutation and confirmation dialog * 🔄 feat: Add AnimatedSearchInput component with gradient animations and search functionality; update search handling in API and localization * 🔄 refactor: Improve SharedLinks component; enhance delete functionality and loading states, optimize AnimatedSearchInput, and refine DataTable scrolling behavior * fix: mutation type issues with deleted shared link mutation * fix: MutationOptions types * fix: Ensure only public shared links are retrieved in getSharedLink function * fix: `qrcode.react` install location * fix: ensure non-public shared links are not fetched when checking for existing shared links, and remove deprecated .exec() method for queries * fix: types and import order * refactor: cleanup share button UI logic, make more intuitive --------- Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
460cde0c0b
commit
fa9e778399
55 changed files with 1779 additions and 1975 deletions
|
|
@ -1,6 +1,7 @@
|
|||
const express = require('express');
|
||||
|
||||
const {
|
||||
getSharedLink,
|
||||
getSharedMessages,
|
||||
createSharedLink,
|
||||
updateSharedLink,
|
||||
|
|
@ -45,29 +46,60 @@ if (allowSharedLinks) {
|
|||
*/
|
||||
router.get('/', requireJwtAuth, async (req, res) => {
|
||||
try {
|
||||
let pageNumber = req.query.pageNumber || 1;
|
||||
pageNumber = parseInt(pageNumber, 10);
|
||||
const params = {
|
||||
pageParam: req.query.cursor,
|
||||
pageSize: Math.max(1, parseInt(req.query.pageSize) || 10),
|
||||
isPublic: isEnabled(req.query.isPublic),
|
||||
sortBy: ['createdAt', 'title'].includes(req.query.sortBy) ? req.query.sortBy : 'createdAt',
|
||||
sortDirection: ['asc', 'desc'].includes(req.query.sortDirection)
|
||||
? req.query.sortDirection
|
||||
: 'desc',
|
||||
search: req.query.search
|
||||
? decodeURIComponent(req.query.search.trim())
|
||||
: undefined,
|
||||
};
|
||||
|
||||
if (isNaN(pageNumber) || pageNumber < 1) {
|
||||
return res.status(400).json({ error: 'Invalid page number' });
|
||||
}
|
||||
const result = await getSharedLinks(
|
||||
req.user.id,
|
||||
params.pageParam,
|
||||
params.pageSize,
|
||||
params.isPublic,
|
||||
params.sortBy,
|
||||
params.sortDirection,
|
||||
params.search,
|
||||
);
|
||||
|
||||
let pageSize = req.query.pageSize || 25;
|
||||
pageSize = parseInt(pageSize, 10);
|
||||
|
||||
if (isNaN(pageSize) || pageSize < 1) {
|
||||
return res.status(400).json({ error: 'Invalid page size' });
|
||||
}
|
||||
const isPublic = req.query.isPublic === 'true';
|
||||
res.status(200).send(await getSharedLinks(req.user.id, pageNumber, pageSize, isPublic));
|
||||
res.status(200).send({
|
||||
links: result.links,
|
||||
nextCursor: result.nextCursor,
|
||||
hasNextPage: result.hasNextPage,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Error getting shared links' });
|
||||
console.error('Error getting shared links:', error);
|
||||
res.status(500).json({
|
||||
message: 'Error getting shared links',
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', requireJwtAuth, async (req, res) => {
|
||||
router.get('/link/:conversationId', requireJwtAuth, async (req, res) => {
|
||||
try {
|
||||
const created = await createSharedLink(req.user.id, req.body);
|
||||
const share = await getSharedLink(req.user.id, req.params.conversationId);
|
||||
|
||||
return res.status(200).json({
|
||||
success: share.success,
|
||||
shareId: share.shareId,
|
||||
conversationId: req.params.conversationId,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Error getting shared link' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/:conversationId', requireJwtAuth, async (req, res) => {
|
||||
try {
|
||||
const created = await createSharedLink(req.user.id, req.params.conversationId);
|
||||
if (created) {
|
||||
res.status(200).json(created);
|
||||
} else {
|
||||
|
|
@ -78,11 +110,11 @@ router.post('/', requireJwtAuth, async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
router.patch('/', requireJwtAuth, async (req, res) => {
|
||||
router.patch('/:shareId', requireJwtAuth, async (req, res) => {
|
||||
try {
|
||||
const updated = await updateSharedLink(req.user.id, req.body);
|
||||
if (updated) {
|
||||
res.status(200).json(updated);
|
||||
const updatedShare = await updateSharedLink(req.user.id, req.params.shareId);
|
||||
if (updatedShare) {
|
||||
res.status(200).json(updatedShare);
|
||||
} else {
|
||||
res.status(404).end();
|
||||
}
|
||||
|
|
@ -93,14 +125,15 @@ router.patch('/', requireJwtAuth, async (req, res) => {
|
|||
|
||||
router.delete('/:shareId', requireJwtAuth, async (req, res) => {
|
||||
try {
|
||||
const deleted = await deleteSharedLink(req.user.id, { shareId: req.params.shareId });
|
||||
if (deleted) {
|
||||
res.status(200).json(deleted);
|
||||
} else {
|
||||
res.status(404).end();
|
||||
const result = await deleteSharedLink(req.user.id, req.params.shareId);
|
||||
|
||||
if (!result) {
|
||||
return res.status(404).json({ message: 'Share not found' });
|
||||
}
|
||||
|
||||
return res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Error deleting shared link' });
|
||||
return res.status(400).json({ message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue