1
0
Fork 0
cloudservices/src/intervals/storage.ts

25 lines
828 B
TypeScript
Raw Normal View History

2019-11-09 23:05:34 -05:00
/* eslint-disable no-await-in-loop */
import fs from 'fs-extra';
import { Client } from '..';
export default function storage(client: Client) {
2019-11-09 23:13:49 -05:00
const main = async () => {
2019-11-09 23:05:34 -05:00
const accounts = await client.db.Account.find();
for (const account of accounts) {
2019-11-09 23:23:26 -05:00
const res = await client.util.exec(`du -bs /home/${account.username}`);
let bytes = Number(res.split('/')[0].replace('\t', ''));
2019-11-09 23:05:34 -05:00
try {
await fs.access(`/var/mail/${account.username}`, fs.constants.F_OK);
2019-11-09 23:38:11 -05:00
const res2 = await client.util.exec(`du -bs /var/mail/${account.username}`);
bytes += Number(res2.split('/')[0].replace('\t', ''));
2019-11-09 23:05:34 -05:00
} catch {
bytes += 0;
}
await client.redis.set(`storage-${account.username}`, bytes);
}
2019-11-09 23:13:49 -05:00
};
setInterval(async () => {
await main();
2019-11-09 23:34:48 -05:00
}, 900000);
2019-11-09 23:05:34 -05:00
}