INNER CODE UNIT · JavaScript
editAccountTimeForRef
shadowsocks/shadowsocks-manager · plugins/account/index.js:262
const editAccountTimeForRef = 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,
};
if(accountInfo.data.create + timePeriod[accountInfo.type] * accountInfo.data.limit <= Date.now()) {
accountInfo.data.limit = 1;
accountInfo.data.create = Date.now() + time - timePeriod[accountInfo.type];
} else {
accountInfo.data.create += time;
}
while(time > 0 && accountInfo.data.create >= Date.now()) {