fix: 暂时去掉pdf导出功能

This commit is contained in:
喻希里 2017-11-08 11:36:03 +08:00
parent 8d830b36a7
commit 0b178ead96
3 changed files with 37 additions and 39 deletions

View File

@ -3,21 +3,21 @@
function exportData(exportDataModule,pid){
exportDataModule.markdown = {
name: 'markdown',
route: `/api/plugin/export?type=markdown&pid=${pid}`,
desc: '导出项目接口文档为 markdown 文件'
}
exportDataModule.pdf = {
name: 'pdf',
route: `/api/plugin/export?type=pdf&pid=${pid}`,
desc: '导出项目接口文档为 pdf 文件'
}
exportDataModule.html = {
name: 'html',
route: `/api/plugin/export?type=html&pid=${pid}`,
desc: '导出项目接口文档为 html 文件'
}
exportDataModule.markdown = {
name: 'markdown',
route: `/api/plugin/export?type=markdown&pid=${pid}`,
desc: '导出项目接口文档为 markdown 文件'
}
// exportDataModule.pdf = {
// name: 'pdf',
// route: `/api/plugin/export?type=pdf&pid=${pid}`,
// desc: '导出项目接口文档为 pdf 文件'
// }
}

View File

@ -6,7 +6,7 @@ const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItTableOfContents = require("markdown-it-table-of-contents");
const defaultTheme = require("./defaultTheme.js");
const htmlToPdf = require("html-pdf");
// const htmlToPdf = require("html-pdf");
class exportController extends baseController{
constructor(ctx){
super(ctx);
@ -32,11 +32,11 @@ class exportController extends baseController{
ctx.set("Content-Disposition",`attachment; filename=api.md`);
return ctx.body = tp;
}
case "pdf": {
tp = await createPdf.bind(this)(pid,false);
ctx.set("Content-Disposition",'filename="api.pdf"');
return ctx.body = tp;
}
// case "pdf": {
// tp = await createPdf.bind(this)(pid,false);
// // ctx.set("Content-Disposition",'filename="api.pdf"');
// return ctx.body = tp;
// }
default: {//默认为html
tp += await createHtml.bind(this)(pid);
ctx.set("Content-Disposition",`attachment; filename=api.html`);
@ -49,29 +49,29 @@ class exportController extends baseController{
ctx.body = yapi.commons.resReturn(null, 502, "下载出错");
}
async function createPdf(){
let md = await createMarkdown.bind(this)(pid);
let markdown = new markdownIt();
markdown.use(markdownItAnchor); // Optional, but makes sense as you really want to link to something
markdown.use(markdownItTableOfContents,{
markerPattern: /^\[toc\]/im
});
let tp = defaultTheme + unescape(markdown.render(md));
tp = createHtml5(tp);
// async function createPdf(){
// let md = await createMarkdown.bind(this)(pid);
// let markdown = new markdownIt();
// markdown.use(markdownItAnchor); // Optional, but makes sense as you really want to link to something
// markdown.use(markdownItTableOfContents,{
// markerPattern: /^\[toc\]/im
// });
// let tp = defaultTheme + unescape(markdown.render(md));
// tp = createHtml5(tp);
let htp = htmlToPdf.create(tp);
// let htp = htmlToPdf.create(tp);
let getPdfBuffer = ()=>{
return new Promise((resolve, reject)=>{
htp.toBuffer(function(err, buffer){
if(err) reject(err);
resolve(buffer)
})
})
}
let result = await getPdfBuffer();
return result;
}
// let getPdfBuffer = ()=>{
// return new Promise((resolve, reject)=>{
// htp.toBuffer(function(err, buffer){
// if(err) reject(err);
// resolve(buffer)
// })
// })
// }
// let result = await getPdfBuffer();
// return result;
// }
async function createHtml(pid){
let md = await createMarkdown.bind(this)(pid,true);

View File

@ -23,7 +23,6 @@
"clipboard": "^1.7.1",
"deref": "^0.7.0",
"fs-extra": "^3.0.1",
"html-pdf": "^2.2.0",
"json-schema-ref-parser": "^4.0.0",
"json5": "^0.5.1",
"jsonwebtoken": "^7.4.1",
@ -46,7 +45,6 @@
"mongoose-auto-increment": "^5.0.1",
"nodemailer": "^4.0.1",
"ora": "^1.3.0",
"phantom-html-to-pdf": "^0.5.5",
"randexp": "^0.4.6",
"request": "^2.81.0",
"sha1": "^1.1.1",