95 lines
3.1 KiB
TypeScript
95 lines
3.1 KiB
TypeScript
import { PDFOptions } from "puppeteer"
|
|
/**
|
|
* @prop {string} template template ID
|
|
* @prop {string} reportName outputname
|
|
* @prop {htmlTemplateOption} htmlOption? support only html-template
|
|
* @prop {object} data json data for apply template
|
|
*/
|
|
export interface templateOption {
|
|
template: string
|
|
reportName: string
|
|
htmlOption?: htmlTemplateOption
|
|
data: object
|
|
}
|
|
/**
|
|
* @prop {number} navigationTimeout page.setDefaultNavigationTimeout(navigationTimeout)
|
|
* @prop {number} querySelector Element of page
|
|
* @prop {number} waitUntil 'networkidle0' or 'networkidle0'
|
|
* @prop {number} preloadWait wait in the scroll loop in ms second
|
|
* @prop {number} preloadScroll scroll height
|
|
* @prop {number} preloadLoop number of retry preload lazy load page
|
|
* @prop {PDFOptions} pdfOption PdfOptions of Puppeteer
|
|
*/
|
|
export interface htmlTemplateOption {
|
|
navigationTimeout?: number
|
|
querySelector?: string
|
|
waitUntil?: string
|
|
preloadWait?: number
|
|
preloadScroll?: number
|
|
preloadLoop?: number
|
|
pdfOption?: PDFOptions
|
|
}
|
|
|
|
export interface IDictionary<TValue> {
|
|
[key: string]: TValue
|
|
}
|
|
export function mimeToExtension(mime: string): string {
|
|
const mimeList: IDictionary<string> = {
|
|
"application/pdf": "pdf",
|
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
|
"docx",
|
|
"application/msword": "doc",
|
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
|
|
"application/vnd.ms-excel": "xls",
|
|
"application/vnd.ms-powerpoint": "ppt",
|
|
"application/vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
"pptx",
|
|
"application/vnd.oasis.opendocument.text": "odt",
|
|
"application/vnd.oasis.opendocument.spreadsheet": "ods",
|
|
"application/vnd.oasis.opendocument.presentation": "odp",
|
|
"text/html": "html",
|
|
"application/json": "json",
|
|
"text/csv": "csv",
|
|
"text/markdown": "md",
|
|
"text/plain": "txt",
|
|
"application/rtf": "rtf",
|
|
"image/png": "png",
|
|
"image/jpeg": "jpeg",
|
|
}
|
|
if (mimeList[mime]) {
|
|
return mimeList[mime]
|
|
} else if (mime.match(/^application\/x\./)) {
|
|
return mime.substr(mime.indexOf(".") + 1)
|
|
} else {
|
|
return mime
|
|
}
|
|
}
|
|
/** javascript-obfuscator:disable
|
|
* @swagger
|
|
* tags:
|
|
* name: report-template
|
|
* description: API สำหรับสร้างเอกสารจาก Template docx หรือ xlsx การทำงานคล้ายการทำ Mail Merge ทำให้ยูสเซอร์ทั่วไปแก้ Template ได้ง่าย สามารถแปลงไฟล์นามสกุลอื่นๆที่ soffice รองรับ
|
|
*/
|
|
|
|
/** javascript-obfuscator:disable
|
|
* @swagger
|
|
* components:
|
|
* schemas:
|
|
* templateOption:
|
|
* type: object
|
|
* required:
|
|
* - template
|
|
* - reportName
|
|
* - data
|
|
* - finished
|
|
* properties:
|
|
* template:
|
|
* type: string
|
|
* description: name of template
|
|
* reportName:
|
|
* type: string
|
|
* description: name of report for download
|
|
* data:
|
|
* type: object
|
|
* description: value for template
|
|
*/
|