mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 08:56:42 +08:00
Refa: files /file API to RESTFul style (#13741)
### What problem does this PR solve? Files /file API to RESTFul style. ### Type of change - [x] Documentation Update - [x] Refactoring --------- Co-authored-by: writinwaters <cai.keith@gmail.com> Co-authored-by: Liu An <asiro@qq.com>
This commit is contained in:
@@ -161,15 +161,14 @@ export default {
|
||||
`${ExternalApi}${api_host}/chatbots/${id}/info`,
|
||||
|
||||
// file manager
|
||||
listFile: `${api_host}/file/list`,
|
||||
uploadFile: `${api_host}/file/upload`,
|
||||
removeFile: `${api_host}/file/rm`,
|
||||
renameFile: `${api_host}/file/rename`,
|
||||
getAllParentFolder: `${api_host}/file/all_parent_folder`,
|
||||
createFolder: `${api_host}/file/create`,
|
||||
listFile: `${ExternalApi}${api_host}/files`,
|
||||
uploadFile: `${ExternalApi}${api_host}/files`,
|
||||
removeFile: `${ExternalApi}${api_host}/files`,
|
||||
getAllParentFolder: `${ExternalApi}${api_host}/files`,
|
||||
createFolder: `${ExternalApi}${api_host}/files`,
|
||||
connectFileToKnowledge: `${api_host}/file2document/convert`,
|
||||
getFile: `${api_host}/file/get`,
|
||||
moveFile: `${api_host}/file/mv`,
|
||||
getFile: `${ExternalApi}${api_host}/files`,
|
||||
moveFile: `${ExternalApi}${api_host}/files/move`,
|
||||
|
||||
// system
|
||||
getSystemVersion: `${api_host}/system/version`,
|
||||
|
||||
@@ -101,8 +101,15 @@ export const getBase64FromUploadFileList = async (fileList?: UploadFile[]) => {
|
||||
return '';
|
||||
};
|
||||
|
||||
async function fetchDocumentBlob(id: string, mimeType?: FileMimeType) {
|
||||
const response = await fileManagerService.getDocumentFile({}, id);
|
||||
async function fetchPreviewBlob(
|
||||
id: string,
|
||||
resource: 'document' | 'files',
|
||||
mimeType?: FileMimeType,
|
||||
) {
|
||||
const response =
|
||||
resource === 'files'
|
||||
? await fileManagerService.getFile({}, id)
|
||||
: await fileManagerService.getDocumentFile({}, id);
|
||||
const blob = new Blob([response.data], {
|
||||
type: mimeType || response.data.type,
|
||||
});
|
||||
@@ -110,8 +117,11 @@ async function fetchDocumentBlob(id: string, mimeType?: FileMimeType) {
|
||||
return blob;
|
||||
}
|
||||
|
||||
export async function previewHtmlFile(id: string) {
|
||||
const blob = await fetchDocumentBlob(id, FileMimeType.Html);
|
||||
export async function previewHtmlFile(
|
||||
id: string,
|
||||
resource: 'document' | 'files' = 'document',
|
||||
) {
|
||||
const blob = await fetchPreviewBlob(id, resource, FileMimeType.Html);
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
@@ -137,7 +147,7 @@ export const downloadDocument = async ({
|
||||
id: string;
|
||||
filename?: string;
|
||||
}) => {
|
||||
const blob = await fetchDocumentBlob(id);
|
||||
const blob = await fetchPreviewBlob(id, 'document');
|
||||
downloadFileFromBlob(blob, filename);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user