mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00
fix: upload file (#2992)
* fix: upload file * chore: remove wasm, support html image parse * chore: adjust * chore: move base64match function into htmlstr2md
This commit is contained in:
@@ -1,20 +1,39 @@
|
||||
import mammoth from 'mammoth';
|
||||
import { ReadRawTextByBuffer, ReadFileResponse } from '../type';
|
||||
import mammoth, { images } from 'mammoth';
|
||||
import { ReadRawTextByBuffer, ReadFileResponse, ImageType } from '../type';
|
||||
import { html2md } from '../../htmlStr2Md/utils';
|
||||
|
||||
/**
|
||||
* read docx to markdown
|
||||
*/
|
||||
export const readDocsFile = async ({ buffer }: ReadRawTextByBuffer): Promise<ReadFileResponse> => {
|
||||
const imageList: ImageType[] = [];
|
||||
try {
|
||||
const { value: html } = await mammoth.convertToHtml({
|
||||
buffer
|
||||
});
|
||||
const { value: html } = await mammoth.convertToHtml(
|
||||
{
|
||||
buffer
|
||||
},
|
||||
{
|
||||
convertImage: images.imgElement(async (image) => {
|
||||
const imageBase64 = await image.readAsBase64String();
|
||||
const uuid = crypto.randomUUID();
|
||||
const mime = image.contentType;
|
||||
imageList.push({
|
||||
uuid,
|
||||
base64: imageBase64,
|
||||
mime
|
||||
});
|
||||
return {
|
||||
src: uuid
|
||||
};
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
const rawText = html2md(html);
|
||||
const { rawText } = html2md(html);
|
||||
|
||||
return {
|
||||
rawText
|
||||
rawText,
|
||||
imageList
|
||||
};
|
||||
} catch (error) {
|
||||
console.log('error doc read:', error);
|
||||
|
@@ -5,9 +5,10 @@ import { html2md } from '../../htmlStr2Md/utils';
|
||||
export const readHtmlRawText = async (params: ReadRawTextByBuffer): Promise<ReadFileResponse> => {
|
||||
const { rawText: html } = readFileRawText(params);
|
||||
|
||||
const rawText = html2md(html);
|
||||
const { rawText, imageList } = html2md(html);
|
||||
|
||||
return {
|
||||
rawText
|
||||
rawText,
|
||||
imageList
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user