mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
🔒 feat: View/Delete Shared Agent Files (#8419)
* 🔧 fix: Add localized message for delete operation not allowed
* refactor: improve file deletion operations ux
* feat: agent-based file access control and enhance file retrieval logic
* feat: implement agent-specific file retrieval
* feat: enhance agent file retrieval logic for authors and shared access
* ci: include userId and agentId in mockGetFiles call for OCR file retrieval
This commit is contained in:
parent
6aa4bb5a4a
commit
f1b29ffb45
22 changed files with 1216 additions and 35 deletions
|
|
@ -9,6 +9,8 @@ import {
|
|||
} from 'librechat-data-provider';
|
||||
import type * as t from 'librechat-data-provider';
|
||||
import type { UseMutationResult } from '@tanstack/react-query';
|
||||
import { useToastContext } from '~/Providers';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
export const useUploadFileMutation = (
|
||||
_options?: t.UploadMutationOptions,
|
||||
|
|
@ -145,10 +147,24 @@ export const useDeleteFilesMutation = (
|
|||
unknown // context
|
||||
> => {
|
||||
const queryClient = useQueryClient();
|
||||
const { onSuccess, ...options } = _options || {};
|
||||
const { showToast } = useToastContext();
|
||||
const localize = useLocalize();
|
||||
const { onSuccess, onError, ...options } = _options || {};
|
||||
return useMutation([MutationKeys.fileDelete], {
|
||||
mutationFn: (body: t.DeleteFilesBody) => dataService.deleteFiles(body),
|
||||
...options,
|
||||
onError: (error, vars, context) => {
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
const errorWithResponse = error as { response?: { status?: number } };
|
||||
if (errorWithResponse.response?.status === 403) {
|
||||
showToast({
|
||||
message: localize('com_ui_delete_not_allowed'),
|
||||
status: 'error',
|
||||
});
|
||||
}
|
||||
}
|
||||
onError?.(error, vars, context);
|
||||
},
|
||||
onSuccess: (data, vars, context) => {
|
||||
queryClient.setQueryData<t.TFile[] | undefined>([QueryKeys.files], (cachefiles) => {
|
||||
const { files: filesDeleted } = vars;
|
||||
|
|
@ -160,6 +176,12 @@ export const useDeleteFilesMutation = (
|
|||
|
||||
return (cachefiles ?? []).filter((file) => !fileMap.has(file.file_id));
|
||||
});
|
||||
|
||||
showToast({
|
||||
message: localize('com_ui_delete_success'),
|
||||
status: 'success',
|
||||
});
|
||||
|
||||
onSuccess?.(data, vars, context);
|
||||
if (vars.agent_id != null && vars.agent_id) {
|
||||
queryClient.refetchQueries([QueryKeys.agent, vars.agent_id]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue