mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
🔒 feat: Implement Granular File Storage Strategies and Access Control Middleware
This commit is contained in:
parent
74e029e78f
commit
ff54cbffd9
13 changed files with 269 additions and 210 deletions
|
|
@ -130,9 +130,10 @@ export function Citation(props: CitationComponentProps) {
|
|||
|
||||
// Setup file download hook
|
||||
const isFileType = refData?.refType === 'file' && (refData as any)?.fileId;
|
||||
const isLocalFile = isFileType && (refData as any)?.metadata?.storageType === 'local';
|
||||
const { refetch: downloadFile } = useFileDownload(
|
||||
user?.id ?? '',
|
||||
isFileType ? (refData as any).fileId : '',
|
||||
isFileType && !isLocalFile ? (refData as any).fileId : '',
|
||||
);
|
||||
|
||||
const handleFileDownload = useCallback(
|
||||
|
|
@ -142,6 +143,15 @@ export function Citation(props: CitationComponentProps) {
|
|||
|
||||
if (!isFileType || !(refData as any)?.fileId) return;
|
||||
|
||||
// Don't allow download for local files
|
||||
if (isLocalFile) {
|
||||
showToast({
|
||||
status: 'error',
|
||||
message: localize('com_sources_download_local_unavailable'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const stream = await downloadFile();
|
||||
if (stream.data == null || stream.data === '') {
|
||||
|
|
@ -167,7 +177,7 @@ export function Citation(props: CitationComponentProps) {
|
|||
});
|
||||
}
|
||||
},
|
||||
[downloadFile, isFileType, refData, localize, showToast],
|
||||
[downloadFile, isFileType, isLocalFile, refData, localize, showToast],
|
||||
);
|
||||
|
||||
if (!refData) return null;
|
||||
|
|
@ -187,8 +197,9 @@ export function Citation(props: CitationComponentProps) {
|
|||
label={getCitationLabel()}
|
||||
onMouseEnter={() => setHoveredCitationId(citationId || null)}
|
||||
onMouseLeave={() => setHoveredCitationId(null)}
|
||||
onClick={isFileType ? handleFileDownload : undefined}
|
||||
onClick={isFileType && !isLocalFile ? handleFileDownload : undefined}
|
||||
isFile={isFileType}
|
||||
isLocalFile={isLocalFile}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue