console.error("Got bad response of",response.status,"when checking rate limits for",issuerDid);
returnres.status(400).send(JSON.stringify({success:false,message:'Got bad status of '+response.status+' when checking limits with endorser server. Verify that the account exists and that the JWT works for that server.'}));
}else{
constbody=awaitresponse.json();
limitPerWeek=body.maxClaimsPerWeek/4;// allowing fewer images than claims
awaitnewPromise((resolve,reject)=>{
db.run(
'INSERT INTO user (did, per_week) VALUES (?, ?)',
[issuerDid,limitPerWeek],
(dbErr)=>{
if(dbErr){
console.error("Error inserting user record for",issuerDid,"into database (but continuing):",dbErr);
// we can continue... it just means we'll check the endorser server again next time
}
resolve();
}
);
});
}
}
if(limitPerWeek==null){
returnres.status(400).send(JSON.stringify({success:false,message:'Unable to determine rate limits for this user. Verify that the account exists and that the JWT works for that server.'}));
console.error("Got bad response of",response.status,"when checking rate limits for",issuerDid);
return{
success:false,
result:res.status(400).send(JSON.stringify({success:false,message:'Got bad status of '+response.status+' when checking limits with endorser server. Verify that the account exists and that the JWT works for that server.'}))
};
}else{
constbody=awaitresponse.json();
maxImagesPerWeek=body.maxClaimsPerWeek/4;// allowing fewer images than claims
awaitnewPromise((resolve,reject)=>{
db.run(
'INSERT INTO user (did, per_week) VALUES (?, ?)',
[issuerDid,maxImagesPerWeek],
(dbErr)=>{
if(dbErr){
console.error("Error inserting user record for",issuerDid,"into database (but continuing):",dbErr);
// we can continue... it just means we'll check the endorser server again next time
}
resolve();
}
);
});
}
}
if(maxImagesPerWeek==null){
return{
success:false,
result:res.status(400).send(JSON.stringify({success:false,message:'Unable to determine rate limits for this user. Verify that the account exists and that the JWT works for that server.'}))
};
}
// check the user's claims so far this week
conststartOfWeekDate=DateTime.utc().startOf('week')// luxon weeks start on Mondays