daodao97 / chatdoc

Chat with your doc by openai
456 stars 105 forks source link

无法加载pdf.js #2

Closed longxinzhang closed 1 year ago

longxinzhang commented 1 year ago

epub文件、pdf文件无法正确加载显示,网页和txt可以正常显示,控制台报错:

1、Failed to load resource: the server responded with a status of 404 (Not Found) viewer.html:1

2、Access to fetch at 'http://192.168.31.240:8000/static/927c0d75c7e9c278e0e2f862ccfa05b7/Proof%20of%20employment.pdf' from origin 'http://192.168.31.240:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. :8000/static/927c0d75c7e9c278e0e2f862ccfa05b7/Proof%20of%20employment.pdf:1

3、Failed to load resource: net::ERR_FAILED app.js:1109

4、载入 PDF 时发生错误。

PDF.js v3.4.120 (build: af6414988) Message: Failed to fetch _otherError @ app.js:1109

👉🏻 console.error(${message}\n\n${moreInfoText.join("\n")});

5、Uncaught (in promise) UnknownErrorExceptiondetails: "TypeError: Failed to fetch"message: "Failed to fetch"name: "UnknownErrorException"[[Prototype]]: Error [[Prototype]] : Error constructor : class UnknownErrorException [[Prototype]] : Error at BaseExceptionClosure (http://192.168.31.240:5173/pdfjs/build/pdf.js:482:29) at Object.defineProperty.value (http://192.168.31.240:5173/pdfjs/build/pdf.js:485:2) at w_pdfjs_require (http://192.168.31.240:5173/pdfjs/build/pdf.js:15512:41) at http://192.168.31.240:5173/pdfjs/build/pdf.js:15774:13 at http://192.168.31.240:5173/pdfjs/build/pdf.js:15786:3 at http://192.168.31.240:5173/pdfjs/build/pdf.js:15789:12 at webpackUniversalModuleDefinition (http://192.168.31.240:5173/pdfjs/build/pdf.js:31:50) at http://192.168.31.240:5173/pdfjs/build/pdf.js:32:3 stack : "Error\n at BaseExceptionClosure (http://192.168.31.240:5173/pdfjs/build/pdf.js:482:29)\n at Object.defineProperty.value (http://192.168.31.240:5173/pdfjs/build/pdf.js:485:2)\n at w_pdfjs_require (http://192.168.31.240:5173/pdfjs/build/pdf.js:15512:41)\n at http://192.168.31.240:5173/pdfjs/build/pdf.js:15774:13\n at http://192.168.31.240:5173/pdfjs/build/pdf.js:15786:3\n at http://192.168.31.240:5173/pdfjs/build/pdf.js:15789:12\n at webpackUniversalModuleDefinition (http://192.168.31.240:5173/pdfjs/build/pdf.js:31:50)\n at http://192.168.31.240:5173/pdfjs/build/pdf.js:32:3" [[Prototype]] : Object

daodao97 commented 1 year ago

需要在代码中开启跨域访问的ip https://github.com/daodao97/chatdoc/blob/master/server/main.py#L13

longxinzhang commented 1 year ago

ok了,修改后就可以运行了。

app = FastAPI()
origins = ["http://127.0.0.1", "http://localhost:5173", "http://本地主机地址:5173"]