mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Support preview of HTML files #5096 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -98,6 +98,24 @@ export const getBase64FromUploadFileList = async (fileList?: UploadFile[]) => {
|
||||
return '';
|
||||
};
|
||||
|
||||
async function fetchDocumentBlob(id: string, mimeType?: FileMimeType) {
|
||||
const response = await fileManagerService.getDocumentFile({}, id);
|
||||
const blob = new Blob([response.data], {
|
||||
type: mimeType || response.data.type,
|
||||
});
|
||||
|
||||
return blob;
|
||||
}
|
||||
|
||||
export async function previewHtmlFile(id: string) {
|
||||
const blob = await fetchDocumentBlob(id, FileMimeType.Html);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
export const downloadFileFromBlob = (blob: Blob, name?: string) => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
@ -116,8 +134,7 @@ export const downloadDocument = async ({
|
||||
id: string;
|
||||
filename?: string;
|
||||
}) => {
|
||||
const response = await fileManagerService.getDocumentFile({}, id);
|
||||
const blob = new Blob([response.data], { type: response.data.type });
|
||||
const blob = await fetchDocumentBlob(id);
|
||||
downloadFileFromBlob(blob, filename);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user