🗑️ fix: Delete Shared Links on Conversation Deletion (#10396)
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled

*  feat: Enhance DELETE /all endpoint to remove shared links alongside conversations and tool calls

- Added functionality to delete all shared links for a user when clearing conversations.
- Introduced comprehensive tests to ensure correct behavior and error handling for the new deletion process.

*  feat: Implement deleteConvoSharedLink method and update conversation deletion logic to remove associated shared links
This commit is contained in:
Danny Avila 2025-11-06 11:44:28 -05:00 committed by GitHub
parent c6611d4e77
commit ba71375982
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 640 additions and 3 deletions

View file

@ -173,8 +173,8 @@ export function createShareMethods(mongoose: typeof import('mongoose')) {
return null;
}
// Filter messages based on targetMessageId if present (branch-specific sharing)
let messagesToShare = share.messages;
/** Filtered messages based on targetMessageId if present (branch-specific sharing) */
let messagesToShare: t.IMessage[] = share.messages;
if (share.targetMessageId) {
messagesToShare = getMessagesUpToTarget(share.messages, share.targetMessageId);
}
@ -310,6 +310,34 @@ export function createShareMethods(mongoose: typeof import('mongoose')) {
}
}
/**
* Delete shared links by conversation ID
*/
async function deleteConvoSharedLink(
user: string,
conversationId: string,
): Promise<t.DeleteAllSharesResult> {
if (!user || !conversationId) {
throw new ShareServiceError('Missing required parameters', 'INVALID_PARAMS');
}
try {
const SharedLink = mongoose.models.SharedLink as Model<t.ISharedLink>;
const result = await SharedLink.deleteMany({ user, conversationId });
return {
message: 'Shared links deleted successfully',
deletedCount: result.deletedCount,
};
} catch (error) {
logger.error('[deleteConvoSharedLink] Error deleting shared links', {
error: error instanceof Error ? error.message : 'Unknown error',
user,
conversationId,
});
throw new ShareServiceError('Error deleting shared links', 'SHARE_DELETE_ERROR');
}
}
/**
* Create a new shared link for a conversation
*/
@ -528,6 +556,7 @@ export function createShareMethods(mongoose: typeof import('mongoose')) {
deleteSharedLink,
getSharedMessages,
deleteAllSharedLinks,
deleteConvoSharedLink,
};
}