fix Payload Too Large for convert file api

This commit is contained in:
oom 2024-06-28 10:39:52 +07:00
parent 96d732bb96
commit ba8175204c
9 changed files with 169 additions and 157 deletions

View file

@ -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,