fix Payload Too Large for convert file api
This commit is contained in:
parent
96d732bb96
commit
ba8175204c
9 changed files with 169 additions and 157 deletions
|
|
@ -7,19 +7,19 @@ import { LibreOfficeFileConverter } from 'libreoffice-file-converter';
|
|||
* @swagger
|
||||
* tags:
|
||||
* name: office-convert
|
||||
* description: ใช้แปลงไฟล์จากเอกสารที่ libreoffice แปลงได้ x
|
||||
* description: ใช้แปลงไฟล์จากเอกสารที่ libreoffice แปลงได้ เช่น docx เป็น pdf
|
||||
*/
|
||||
|
||||
/** javascript-obfuscator:disable
|
||||
* @swagger
|
||||
* /api/v1/report-template/convert:
|
||||
* post:
|
||||
* summary: Create document from template
|
||||
* summary: แปลงฟอร์แม็ตเอกสารเช่นจาก docx เป็น pdf ให้ตั้งค่า Media type เป็นชนิดไฟล์ที่ต้องการ
|
||||
* tags: [office-convert]
|
||||
* parameters:
|
||||
* - name: report_name
|
||||
* - name: report-name
|
||||
* in: header
|
||||
* description: นามสกุลไฟล์ที่อัปโหลดเข้ามา(ตอนนี้ไม่จำเป็นต้องใช้เพราะ soffice ตรวจสอบเอง)
|
||||
* description: ชื่อไฟล์ที่ต้องการหลังแปลง
|
||||
* required: true
|
||||
* schema:
|
||||
* type: string
|
||||
|
|
@ -59,25 +59,27 @@ import { LibreOfficeFileConverter } from 'libreoffice-file-converter';
|
|||
* schema:
|
||||
* type: string
|
||||
* format: binary
|
||||
* 400:
|
||||
* description: Invalid format
|
||||
* 500:
|
||||
* description: Server error
|
||||
*
|
||||
*/
|
||||
convertTemplateRoute.post("/convert", async function (req, res) {
|
||||
convertTemplateRoute.post("/", async function (req, res) {
|
||||
try {
|
||||
if (!req.headers['content-type'] ||
|
||||
!req.headers['accept'] ||
|
||||
!req.headers['report_name'] ||
|
||||
!req.headers['report-name'] ||
|
||||
req.headers['content-type'] !== "application/octet-stream") {
|
||||
res.statusCode = 400;
|
||||
res.statusMessage = 'Require header: content-type(application/octet-stream) accept, report_name';
|
||||
res.statusMessage = 'Require header: content-type(application/octet-stream) accept, report-name';
|
||||
res.end(res.statusMessage);
|
||||
console.log(req.headers['content-type'],req.headers['accept'],req.headers['report_name'])
|
||||
console.log(req.headers['content-type'],req.headers['accept'],req.headers['report-name'])
|
||||
return
|
||||
}
|
||||
let outputMediaType = mimeToExtension(req.headers['accept']);
|
||||
let reportName = req.headers['report_name']
|
||||
console.log('output: ' + outputMediaType);
|
||||
let reportName = req.headers['report-name']
|
||||
console.log('convert output: ' + outputMediaType);
|
||||
const libreOfficeFileConverter = new LibreOfficeFileConverter({
|
||||
childProcessOptions: {
|
||||
timeout: 60 * 1000,
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ const swaggerOptions = {
|
|||
openapi: "3.1.0",
|
||||
info: {
|
||||
title: "Report Server",
|
||||
version: "0.8.0",
|
||||
version: "0.8.1",
|
||||
description:
|
||||
"Advance create and convert document API for microservice era.",
|
||||
"Technical preview releases - Report Server <br/>Advance create and convert document API for microservice era. ",
|
||||
license: {
|
||||
name: "by Frappet",
|
||||
name: "by oom@Frappet",
|
||||
url: "https://frappet.com",
|
||||
},
|
||||
},
|
||||
|
|
@ -18,7 +18,7 @@ const swaggerOptions = {
|
|||
{url: "https://report-server.frappet.synology.me"},
|
||||
{url:"https://bma-ehr.frappet.synology.me/"},
|
||||
{url: "http://localhost:3000"},
|
||||
{url: "http://192.168.2.100:3000"},
|
||||
{url: "http://192.168.2.101:3001"},
|
||||
],
|
||||
},
|
||||
apis: ["./libs/*.ts"],
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ export async function docxTemplateX(base: string=".", tdata: templateData, outpu
|
|||
* @swagger
|
||||
* /api/v1/report-template/docx:
|
||||
* get:
|
||||
* summary: list docx template
|
||||
* summary: แสดงรายการ template ที่มีในโฟลเดอร์ templates
|
||||
* tags: [report-template]
|
||||
* responses:
|
||||
* 200:
|
||||
|
|
@ -87,7 +87,7 @@ docxTemplateRoute.get("/", async function (req, res) {
|
|||
* @swagger
|
||||
* /api/v1/report-template/docx:
|
||||
* post:
|
||||
* summary: Create document from docx template output can be docx pdf odt
|
||||
* summary: สร้างเอกสารโดยใช้ template จากไฟล์ docx จะแทนค่าตัวแปรในเอกสาร หรือจะแปลงเป็นฟอร์แม็ตอื่นได้ด้วยรองรับ docx pdf odt, ค่า template เป็นชื่อของ template, reportName เป็นชื่อไฟล์ที่ต้องการ
|
||||
* tags: [report-template]
|
||||
* requestBody:
|
||||
* required: true
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Report Server",
|
||||
"version": "0.8.0",
|
||||
"description": "Advance create and convert document API for microservice era.",
|
||||
"version": "0.8.1",
|
||||
"description": "Technical preview releases - Report Server <br/>Advance create and convert document API for microservice era. ",
|
||||
"license": {
|
||||
"name": "by Frappet",
|
||||
"name": "by oom@Frappet",
|
||||
"url": "https://frappet.com"
|
||||
}
|
||||
},
|
||||
|
|
@ -20,21 +20,21 @@
|
|||
"url": "http://localhost:3000"
|
||||
},
|
||||
{
|
||||
"url": "http://192.168.2.100:3000"
|
||||
"url": "http://192.168.2.101:3001"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/api/v1/report-template/convert": {
|
||||
"post": {
|
||||
"summary": "Create document from template",
|
||||
"summary": "แปลงฟอร์แม็ตเอกสารเช่นจาก docx เป็น pdf ให้ตั้งค่า Media type เป็นชนิดไฟล์ที่ต้องการ",
|
||||
"tags": [
|
||||
"office-convert"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "report_name",
|
||||
"name": "report-name",
|
||||
"in": "header",
|
||||
"description": "นามสกุลไฟล์ที่อัปโหลดเข้ามา(ตอนนี้ไม่จำเป็นต้องใช้เพราะ soffice ตรวจสอบเอง)",
|
||||
"description": "ชื่อไฟล์ที่ต้องการหลังแปลง",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
|
|
@ -95,6 +95,9 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Invalid format"
|
||||
},
|
||||
"500": {
|
||||
"description": "Server error"
|
||||
}
|
||||
|
|
@ -103,7 +106,7 @@
|
|||
},
|
||||
"/api/v1/report-template/docx": {
|
||||
"get": {
|
||||
"summary": "list docx template",
|
||||
"summary": "แสดงรายการ template ที่มีในโฟลเดอร์ templates",
|
||||
"tags": [
|
||||
"report-template"
|
||||
],
|
||||
|
|
@ -130,7 +133,7 @@
|
|||
}
|
||||
},
|
||||
"post": {
|
||||
"summary": "Create document from docx template output can be docx pdf odt",
|
||||
"summary": "สร้างเอกสารโดยใช้ template จากไฟล์ docx จะแทนค่าตัวแปรในเอกสาร หรือจะแปลงเป็นฟอร์แม็ตอื่นได้ด้วยรองรับ docx pdf odt, ค่า template เป็นชื่อของ template, reportName เป็นชื่อไฟล์ที่ต้องการ",
|
||||
"tags": [
|
||||
"report-template"
|
||||
],
|
||||
|
|
@ -242,7 +245,7 @@
|
|||
}
|
||||
},
|
||||
"post": {
|
||||
"summary": "สร้าองเอกสารจาก xlsx template แล้วส่งกลับมาเป็น xlsx pdf odt",
|
||||
"summary": "สร้างเอกสารจาก xlsx template แล้วส่งกลับมาเป็น xlsx pdf odt , ค่า template เป็นชื่อของ template ที่ใช้งาน, reportName เป็นชื่อไฟล์ที่ต้องการ",
|
||||
"tags": [
|
||||
"report-template"
|
||||
],
|
||||
|
|
@ -372,7 +375,7 @@
|
|||
"tags": [
|
||||
{
|
||||
"name": "office-convert",
|
||||
"description": "ใช้แปลงไฟล์จากเอกสารที่ libreoffice แปลงได้ x"
|
||||
"description": "ใช้แปลงไฟล์จากเอกสารที่ libreoffice แปลงได้ เช่น docx เป็น pdf"
|
||||
},
|
||||
{
|
||||
"name": "report-template",
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ xlsxTemplateRoute.get("/", async function (req, res) {
|
|||
* @swagger
|
||||
* /api/v1/report-template/xlsx:
|
||||
* post:
|
||||
* summary: สร้าองเอกสารจาก xlsx template แล้วส่งกลับมาเป็น xlsx pdf odt
|
||||
* summary: สร้างเอกสารจาก xlsx template แล้วส่งกลับมาเป็น xlsx pdf odt , ค่า template เป็นชื่อของ template ที่ใช้งาน, reportName เป็นชื่อไฟล์ที่ต้องการ
|
||||
* tags: [report-template]
|
||||
* requestBody:
|
||||
* required: true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue