导出添加文件夹, 错误输出错误日志
This commit is contained in:
@@ -106,7 +106,7 @@ class exportMarkdownController extends baseController {
|
|||||||
// const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(),uuid.v4()));
|
// const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(),uuid.v4()));
|
||||||
// console.log("tmpPath=", tmpPath)
|
// console.log("tmpPath=", tmpPath)
|
||||||
const zip = JSZip();
|
const zip = JSZip();
|
||||||
|
let errMsg = [];
|
||||||
for (let item of data) {
|
for (let item of data) {
|
||||||
for(let interfaceItem of item.list){
|
for(let interfaceItem of item.list){
|
||||||
const safeVm = new Safeify({
|
const safeVm = new Safeify({
|
||||||
@@ -115,7 +115,7 @@ class exportMarkdownController extends baseController {
|
|||||||
unrestricted: true,
|
unrestricted: true,
|
||||||
quantity: 4, //沙箱进程数量,默认同 CPU 核数
|
quantity: 4, //沙箱进程数量,默认同 CPU 核数
|
||||||
memoryQuota: 500, //沙箱最大能使用的内存(单位 m),默认 500m
|
memoryQuota: 500, //沙箱最大能使用的内存(单位 m),默认 500m
|
||||||
cpuQuota: 0.5, //沙箱的 cpu 资源配额(百分比),默认 50%
|
cpuQuota: 0.5 //沙箱的 cpu 资源配额(百分比),默认 50%
|
||||||
});
|
});
|
||||||
// console.log("curProject", curProject)
|
// console.log("curProject", curProject)
|
||||||
const vmContext = {
|
const vmContext = {
|
||||||
@@ -127,14 +127,21 @@ class exportMarkdownController extends baseController {
|
|||||||
safeVm.preset("const project = JSON.parse(projectTmp);const interface = JSON.parse(interfaceTmp);const category=JSON.parse(categoryTmp)")
|
safeVm.preset("const project = JSON.parse(projectTmp);const interface = JSON.parse(interfaceTmp);const category=JSON.parse(categoryTmp)")
|
||||||
model = await safeVm.run(result.template_data, vmContext);
|
model = await safeVm.run(result.template_data, vmContext);
|
||||||
// fs.writeFileSync(`${tmpPath}/${interfaceItem.title}.md`, model.toString())
|
// fs.writeFileSync(`${tmpPath}/${interfaceItem.title}.md`, model.toString())
|
||||||
zip.file(`${interfaceItem.title}.md`, model.toString())
|
zip.file(`${item.name}/${interfaceItem.title}.md`, model.toString())
|
||||||
safeVm.destroy();
|
safeVm.destroy();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
|
||||||
|
errMsg.push({
|
||||||
|
error: e.toString(),
|
||||||
|
context: vmContext
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errMsg.length){
|
||||||
|
ctx.body = yapi.commons.resReturn(errMsg, 502, '下载出错');
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.set('Content-Disposition', `attachment; filename=${encodeURIComponent(curProject.name)}.zip`);
|
ctx.set('Content-Disposition', `attachment; filename=${encodeURIComponent(curProject.name)}.zip`);
|
||||||
let dataaa = await zip.generateAsync({
|
let dataaa = await zip.generateAsync({
|
||||||
|
|||||||
Reference in New Issue
Block a user