fix: word解析失败

This commit is contained in:
archer
2023-04-05 11:16:12 +08:00
parent ec22cd8320
commit 5feb2e19bf
2 changed files with 9 additions and 5 deletions

View File

@@ -70,7 +70,6 @@ const SelectFileModal = ({
.join(' ')
.replace(/(\\n|\n)+/g, '\n');
setFileText(fileTexts);
console.log(encode(fileTexts));
} catch (error: any) {
console.log(error);
toast({

View File

@@ -109,11 +109,16 @@ export const readDocContent = (file: File) =>
new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = ({ target }) => {
reader.onload = async ({ target }) => {
if (!target?.result) return reject('读取 doc 文件失败');
return mammoth.extractRawText({ arrayBuffer: target.result as ArrayBuffer }).then((res) => {
resolve(res.value);
});
try {
const res = await mammoth.extractRawText({
arrayBuffer: target.result as ArrayBuffer
});
resolve(res?.value);
} catch (error) {
reject('读取 doc 文件失败, 请转换成 PDF');
}
};
reader.onerror = (err) => {
console.log('error doc read:', err);