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(' ') .join(' ')
.replace(/(\\n|\n)+/g, '\n'); .replace(/(\\n|\n)+/g, '\n');
setFileText(fileTexts); setFileText(fileTexts);
console.log(encode(fileTexts));
} catch (error: any) { } catch (error: any) {
console.log(error); console.log(error);
toast({ toast({

View File

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