INNER CODE UNIT · JavaScript
editAccountTime
shadowsocks/shadowsocks-manager · plugins/account/index.js:240
const editAccountTime = async (id, timeString, check) => {
const time = +timeString;
let accountInfo = await knex('account_plugin').where({ id }).then(s => s[0]);
if(accountInfo.type < 2 || accountInfo.type > 5) { return; }
accountInfo.data = JSON.parse(accountInfo.data);
const timePeriod = {
'2': 7 * 86400 * 1000,
'3': 30 * 86400 * 1000,
'4': 1 * 86400 * 1000,
'5': 3600 * 1000,
};
accountInfo.data.create += time;
while(time > 0 && accountInfo.data.create >= Date.now()) {
accountInfo.data.limit += 1;
accountInfo.data.create -= timePeriod[accountInfo.type];
}
await knex('account_plugin').update({
data: JSON.stringify(accountInfo.data)