改善断连自动恢复并按上次有效记录计算人数增量
This commit is contained in:
1 parent
3ef8a16eca
commit
914a2b7287
11 files changed
+334
-69
No files matched your search
+12
-1
@@ -41,6 +41,15 @@ function peopleCountResponse(ledger,result,actor){
|
||||
if(!result.previous||typeof result.previous!=='object'||Array.isArray(result.previous))unavailable();filtered.previous={};
|
||||
for(const part of parts)if(Object.hasOwn(result.previous,part+'Count')){const value=result.previous[part+'Count'];if(!count(value))unavailable();filtered.previous[part+'Count']=value;}
|
||||
}
|
||||
if(Object.hasOwn(result,'previousDates')){
|
||||
if(!result.previousDates||typeof result.previousDates!=='object'||Array.isArray(result.previousDates))unavailable();filtered.previousDates={};
|
||||
for(const part of parts)if(Object.hasOwn(result.previousDates,part)){
|
||||
const value=result.previousDates[part];
|
||||
if(value!==null&&(typeof value!=='string'||!/^\d{4}-\d{2}-\d{2}$/.test(value)||!Number.isFinite(Date.parse(value+'T00:00:00Z'))||new Date(value+'T00:00:00Z').toISOString().slice(0,10)!==value||value<'2000-01-01'||value>=result.date))unavailable();
|
||||
if(Object.hasOwn(filtered.previous||{},part+'Count')&&((value===null)!==(filtered.previous[part+'Count']===null)))unavailable();
|
||||
filtered.previousDates[part]=value;
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@@ -106,6 +115,8 @@ function createApp(options={}){
|
||||
const actor=user(req);const actorLedger=ledger.asActor(actor);
|
||||
if(route.startsWith('/api/')||route.startsWith('/print/')){
|
||||
if(!actor)fail('请先登录',401);
|
||||
// 仅校验本次页面的原账号与cookie一致,实际授权仍由登录和成员权限决定。
|
||||
if(req.headers['x-ledger-user']!==undefined&&req.headers['x-ledger-user']!==actor.id){const error=new Error('登录账号已在其他页面切换,请刷新后继续;原操作已暂停。');error.status=409;error.code='ACCOUNT_CHANGED';throw error;}
|
||||
if(route==='/api/team-members'&&!isPost)return send(res,200,actorLedger.teamMembers());
|
||||
if(route==='/api/team-funds'&&!isPost)return send(res,200,actorLedger.teamFunds(Object.fromEntries(url.searchParams),actor));
|
||||
const memberPasswordMatch=route.match(/^\/api\/team-members\/(owner|assistant|assistant2)\/password$/);
|
||||
@@ -228,7 +239,7 @@ function createApp(options={}){
|
||||
}
|
||||
const assets={'/':'index.html','/app.js':'app.js','/order-copy.js':'order-copy.js','/order-templates.js':'order-templates.js','/order-templates-ui.js':'order-templates-ui.js','/order-edit-ui.js':'order-edit-ui.js','/order-cancellations-ui.js':'order-cancellations-ui.js','/order-changes-ui.js':'order-changes-ui.js','/order-ownership-ui.js':'order-ownership-ui.js','/daily-funds-ui.js':'daily-funds-ui.js','/team-funds-ui.js':'team-funds-ui.js','/cost-funding-ui.js':'cost-funding-ui.js','/price-locks-ui.js':'price-locks-ui.js','/material-pools-ui.js':'material-pools-ui.js','/recoveries-ui.js':'recoveries-ui.js','/inventory-changes-ui.js':'inventory-changes-ui.js','/credit-card-fees.js':'credit-card-fees.js','/calculations.js':'calculations.js','/fee-estimates.js':'fee-estimates.js','/app.css':'app.css','/print.js':'print.js'};const file=assets[route];if(!file||isPost)fail('地址不存在',404);
|
||||
send(res,200,fs.readFileSync(path.join(__dirname,'public',file)),file.endsWith('.js')?'application/javascript; charset=utf-8':file.endsWith('.css')?'text/css; charset=utf-8':'text/html; charset=utf-8');
|
||||
}catch(e){if(!res.headersSent)send(res,e.status||400,{error:e.status||e.message?.startsWith('打印')?e.message:(e.code?.startsWith('SQLITE')?'保存失败,请保留操作内容并联系维护者':e.message||'操作失败')});else res.end();}
|
||||
}catch(e){if(!res.headersSent)send(res,e.status||400,{error:e.status||e.message?.startsWith('打印')?e.message:(e.code?.startsWith('SQLITE')?'保存失败,请保留操作内容并联系维护者':e.message||'操作失败'),...(e.code==='ACCOUNT_CHANGED'?{code:e.code}:{})});else res.end();}
|
||||
});
|
||||
const timers=[];
|
||||
function startTimers(){if(timers.length)return false;timers.push(setInterval(()=>sync.tick(),60000));timers.push(setInterval(()=>doBackup().catch(()=>{}),6*60*60*1000));automaticSnapshots.start();doBackup().catch(()=>{});for(const t of timers)t.unref();return true;}
|
||||
|
||||
Reference in new issue
Block a user