refactor: organize source web and tests by business module
This commit is contained in:
1 parent
9854d2d5c2
commit
2aed328774
113 files changed
+189
-183
No files matched your search
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
async function bpmScanApi({scanner,workspace,user,sessionId,url,route,method,body,reply}){
|
||||
if(!route.startsWith('/api/bpm-scan')&&route!=='/api/arrivals')return false;
|
||||
const fail=(message,status=400)=>{throw Object.assign(new Error(message),{status});};
|
||||
if(!scanner)fail('BPM 扫描暂不可用。',503);
|
||||
if(route==='/api/arrivals'&&method==='GET'){
|
||||
const filters={connectionId:url.searchParams.get('connectionId')||'',q:url.searchParams.get('q')||'',before:url.searchParams.get('before')||'',days:Number(url.searchParams.get('days')||7)};
|
||||
reply(200,scanner.store.list(filters));return true;
|
||||
}
|
||||
if(route==='/api/bpm-scan'&&method==='GET'){reply(200,{...scanner.store.status(),connections:workspace.snapshot().connections.map(({id,name,status,owner})=>({id,name,status,owner}))});return true;}
|
||||
if(route==='/api/bpm-scan/config'&&method==='POST'){
|
||||
if(user.role!=='admin')fail('仅管理员可以配置自动扫描。',403);
|
||||
const config=scanner.store.saveConfig(body);workspace.record(user,'保存自动扫描',`${config.enabled?'开启':'暂停'},间隔 ${config.intervalMinutes} 分钟`);reply(200,config);return true;
|
||||
}
|
||||
if(route==='/api/bpm-scan/run'&&method==='POST'){
|
||||
if(!body||Object.keys(body).some(k=>k!=='connectionId')||typeof body.connectionId!=='string')fail('请选择 BPM 连接。');
|
||||
// A scan may span many pages. The UI polls the durable run instead of holding a request open.
|
||||
const {promise,runId}=scanner.startScan(body.connectionId,{user,sessionId});
|
||||
promise.catch(()=>{});reply(202,{runId});return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
module.exports={bpmScanApi};
|
||||
Reference in new issue
Block a user