diff --git a/src/home/controller/index.js b/src/home/controller/index.js index f9be467..3eb867d 100644 --- a/src/home/controller/index.js +++ b/src/home/controller/index.js @@ -239,35 +239,12 @@ export default class extends Base { if (SCP && SCP.length > 0) { for (let item of SCP) { - await scp.scp( - `${dir}/${domain}.crt`, - { host: item.host, username: item.user, password: item.password, path: `${dir2}/${domain}.crt` }, - (err) => { - if(err){ - console.log('远程复制失败1:', err); - }else{ - console.log('远程复制成功1:'); - } - } - ); - await scp.scp( - `${dir}/${domain}.key`, - { host: item.host, username: item.user, password: item.password, path: `${dir2}/${domain}.key` }, - (err) => { - if(err){ - console.log('远程复制失败2:', err); - }else{ - console.log('远程复制成功2:'); - } - } - ); + await this.scpFun(originCrt, `${dir2}/${domain}.crt`, item); + await this.scpFun(originKey, `${dir2}/${domain}.key`, item); } - } } - - // 2. 检查配置 execSync('nginx -t'); @@ -301,12 +278,37 @@ export default class extends Base { } } + async scpFun (org, path, item) { + return new Promise(async (resolve, reject) => { + scp.scp( + org, + { host: item.host, username: item.user, password: item.password, path: path }, + (err) => { + if (err) { + console.log('远程复制失败1:', err); + } else { + console.log('远程复制成功1:'); + } + resolve(); + } + ); + }) + } + /** * 配置路由 */ async lechallengeAction () { let params = this.param(); - let txt = fs.readFileSync(path.join(LECHALLENGE_PATH, params.file)) - this.json(txt); + let file = params.file; + if (!file.startsWith('test-')) { + return this.fail('文件名错误'); + } + try { + let txt = fs.readFileSync(path.join(LECHALLENGE_PATH, params.file)) + this.json(txt); + } catch (e) { + return this.fail('文件名错误'); + } } } \ No newline at end of file