mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-29 14:48:51 +01:00
* feat(sharepoint): integrate SharePoint file picker and download workflow Introduces end‑to‑end SharePoint import support: * Token exchange with Microsoft Graph and scope management (`useSharePointToken`) * Re‑usable hooks: `useSharePointPicker`, `useSharePointDownload`, `useSharePointFileHandling` * FileSearch dropdown now offers **From Local Machine** / **From SharePoint** sources and gracefully falls back when SharePoint is disabled * Agent upload model, `AttachFileMenu`, and `DropdownPopup` extended for SharePoint files and sub‑menus * Blurry overlay with progress indicator and `maxSelectionCount` limit during downloads * Cache‑flush utility (`config/flush-cache.js`) supporting Redis & filesystem, with dry‑run and npm script * Updated `SharePointIcon` (uses `currentColor`) and new i18n keys * Bug fixes: placeholder syntax in progress message, picker event‑listener cleanup * Misc style and performance optimizations * Fix ESLint warnings --------- Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { useCallback } from 'react';
|
|
import useFileHandling from './useFileHandling';
|
|
import useSharePointDownload from './useSharePointDownload';
|
|
import type { SharePointFile } from '~/data-provider/Files/sharepoint';
|
|
|
|
interface UseSharePointFileHandlingProps {
|
|
fileSetter?: any;
|
|
fileFilter?: (file: File) => boolean;
|
|
additionalMetadata?: Record<string, string | undefined>;
|
|
overrideEndpoint?: any;
|
|
overrideEndpointFileConfig?: any;
|
|
toolResource?: string;
|
|
}
|
|
|
|
interface UseSharePointFileHandlingReturn {
|
|
handleSharePointFiles: (files: SharePointFile[]) => Promise<void>;
|
|
isProcessing: boolean;
|
|
downloadProgress: any;
|
|
error: string | null;
|
|
}
|
|
|
|
export default function useSharePointFileHandling(
|
|
props?: UseSharePointFileHandlingProps,
|
|
): UseSharePointFileHandlingReturn {
|
|
const { handleFiles } = useFileHandling(props);
|
|
|
|
const { downloadSharePointFiles, isDownloading, downloadProgress, error } = useSharePointDownload(
|
|
{
|
|
onFilesDownloaded: async (downloadedFiles: File[]) => {
|
|
const fileArray = Array.from(downloadedFiles);
|
|
await handleFiles(fileArray, props?.toolResource);
|
|
},
|
|
onError: (error) => {
|
|
console.error('SharePoint download failed:', error);
|
|
},
|
|
},
|
|
);
|
|
|
|
const handleSharePointFiles = useCallback(
|
|
async (sharePointFiles: SharePointFile[]) => {
|
|
try {
|
|
await downloadSharePointFiles(sharePointFiles);
|
|
} catch (error) {
|
|
console.error('SharePoint file handling error:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
[downloadSharePointFiles],
|
|
);
|
|
|
|
return {
|
|
handleSharePointFiles,
|
|
isProcessing: isDownloading,
|
|
downloadProgress,
|
|
error,
|
|
};
|
|
}
|