Commit 5feb2e19 by archer

fix: word解析失败

parent ec22cd83
......@@ -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({
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment