4.6.7 fix (#752)

This commit is contained in:
Archer
2024-01-19 20:16:08 +08:00
committed by GitHub
parent c031e6dcc9
commit 5e2adb22f0
37 changed files with 420 additions and 293 deletions

View File

@@ -0,0 +1,40 @@
import Papa from 'papaparse';
import { readFileRawText } from './rawText';
/**
* read csv to json
* @response {
* header: string[],
* data: string[][]
* }
*/
export const readCsvContent = async ({ file }: { file: File }) => {
try {
const { rawText: textArr } = await readFileRawText(file);
const csvArr = Papa.parse(textArr).data as string[][];
if (csvArr.length === 0) {
throw new Error('csv 解析失败');
}
const header = csvArr.shift() as string[];
// add title to data
const rawText = csvArr
.map((item) =>
item.map((value, index) => {
if (!header[index]) return value;
return `${header[index]}: ${value}`;
})
)
.flat()
.join('\n');
return {
rawText,
header,
data: csvArr.map((item) => item)
};
} catch (error) {
return Promise.reject('解析 csv 文件失败');
}
};

View File

@@ -1,4 +1,5 @@
import { loadFile2Buffer } from '../utils';
import { readCsvContent } from './csv';
import { readHtmlFile } from './html';
import { readMdFile } from './md';
import { readPdfFile } from './pdf';
@@ -29,6 +30,8 @@ export const readFileRawContent = async ({
file,
uploadImgController: uploadBase64Controller
});
case 'csv':
return readCsvContent({ file });
case 'pdf':
const pdf = await loadFile2Buffer({ file });
return readPdfFile({ pdf });

View File

@@ -74,7 +74,7 @@ const JSONEditor = ({ defaultValue, value, onChange, resize, ...props }: Props)
<Box
borderWidth={'1px'}
borderRadius={'base'}
borderRadius={'md'}
borderColor={'myGray.200'}
py={2}
{...props}

View File

@@ -22,13 +22,15 @@
"react-dom": "18.2.0",
"react-i18next": "^12.3.1",
"turndown": "^7.1.2",
"lexical":"0.12.6",
"lexical": "0.12.6",
"@lexical/react": "0.12.6",
"papaparse": "^5.4.1",
"@lexical/utils": "0.12.6",
"@lexical/text": "0.12.6"
},
"devDependencies": {
"@types/react": "18.2.0",
"@types/papaparse": "^5.3.7",
"@types/react-dom": "18.2.0",
"@types/turndown": "^5.0.4"
}