修改插件:Doc2X插件适配文件上传功能 (#2284)
* Change to download first and check contentType * Up to date * Some bug fix, still some bug with img * Update tool to read from file * improve formatting in PDF * Add tool of img file OCR , but meet some bug * Bug fix for parameter passing error. * Modification Introduction
This commit is contained in:
@@ -40,9 +40,35 @@ const main = async ({ apikey, url, ocr }: Props): Response => {
|
||||
real_api_key = data.data.token;
|
||||
}
|
||||
|
||||
//Get the image binary from the URL
|
||||
//Fetch the pdf and check its contene type
|
||||
let PDFResponse;
|
||||
try {
|
||||
PDFResponse = await fetch(url);
|
||||
} catch (e) {
|
||||
return {
|
||||
result: `Failed to fetch PDF from URL: ${url} with error: ${e}`,
|
||||
success: false
|
||||
};
|
||||
}
|
||||
if (!PDFResponse.ok) {
|
||||
return {
|
||||
result: `Failed to fetch PDF from URL: ${url}`,
|
||||
success: false
|
||||
};
|
||||
}
|
||||
|
||||
const contentType = PDFResponse.headers.get('content-type');
|
||||
if (!contentType || !contentType.startsWith('application/pdf')) {
|
||||
return {
|
||||
result: `The provided URL does not point to a PDF: ${contentType}`,
|
||||
success: false
|
||||
};
|
||||
}
|
||||
|
||||
const blob = await PDFResponse.blob();
|
||||
const formData = new FormData();
|
||||
formData.append('pdf_url', url);
|
||||
const fileName = url.split('/').pop()?.split('?')[0] || 'pdf';
|
||||
formData.append('file', blob, fileName);
|
||||
formData.append('ocr', ocr ? '1' : '0');
|
||||
|
||||
let upload_url = 'https://api.doc2x.noedgeai.com/api/platform/async/pdf';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"version": "488",
|
||||
"name": "Doc2X PDF文件(URL)识别",
|
||||
"avatar": "plugins/doc2x",
|
||||
"intro": "将传入的PDF文件(URL)发送至Doc2X进行解析,返回带LaTeX公式的markdown格式的文本",
|
||||
"intro": "从URL下载PDF文件,并发送至Doc2X进行解析,返回带LaTeX公式的markdown格式的文本",
|
||||
"inputExplanationUrl": "https://fael3z0zfze.feishu.cn/wiki/Rkc5witXWiJoi5kORd2cofh6nDg?fromScene=spaceOverview",
|
||||
"showStatus": true,
|
||||
"weight": 10,
|
||||
@@ -201,7 +201,7 @@
|
||||
"key": "system_httpJsonBody",
|
||||
"renderTypeList": ["hidden"],
|
||||
"valueType": "any",
|
||||
"value": "{\n \"apikey\": \"{{apikey}}\",\n \"url\": \"{{url}}\",\n \"ocr\": \"{{ocr}}\"\n}",
|
||||
"value": "{\n \"apikey\": \"{{apikey}}\",\n \"url\": \"{{url}}\",\n \"ocr\": {{ocr}}\n}",
|
||||
"label": "",
|
||||
"required": false
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user