forked from engineering/cloudservices
changes to server data and moderation routes
parent
1b0f099885
commit
8495560e18
|
@ -27,14 +27,13 @@ export default class Account extends Route {
|
|||
res.status(200).json({ code: this.constants.codes.SUCCESS, message: acc });
|
||||
} catch (error) {
|
||||
this.handleError(error, res);
|
||||
this.server.client.util.handleError(error);
|
||||
}
|
||||
});
|
||||
|
||||
this.router.get('/moderations/:id?', async (req: Req, res) => {
|
||||
try {
|
||||
const moderations = await this.server.client.db.Moderation.find({ username: req.account.username });
|
||||
if (!moderations.length) res.sendStatus(204);
|
||||
if (!moderations.length) return res.status(204).json({ code: this.constants.codes.NOT_FOUND, message: null });
|
||||
if (req.params.id) {
|
||||
const filtered = moderations.filter((moderation) => moderation.logID === req.params.id);
|
||||
res.status(200).json({ code: this.constants.codes.SUCCESS, message: { filtered } });
|
||||
|
@ -43,7 +42,6 @@ export default class Account extends Route {
|
|||
}
|
||||
} catch (error) {
|
||||
this.handleError(error, res);
|
||||
this.server.client.util.handleError(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -54,16 +52,23 @@ export default class Account extends Route {
|
|||
this.server.client.util.exec(`memory ${req.account.username}`),
|
||||
this.server.client.redis.get(`storage-${req.account.username}`),
|
||||
]);
|
||||
let storage: string;
|
||||
if (req.query?.cache === 'true') {
|
||||
const val = await this.server.client.util.exec(`du -sb /home/${req.account.username}`);
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
storage = val.split('\t')[0];
|
||||
} else {
|
||||
storage = diskUsage;
|
||||
}
|
||||
res.status(200).json({ code: this.constants.codes.SUCCESS,
|
||||
message: {
|
||||
cpu: Number(`${cpuUsage.split('\n')[0] || '0'}`),
|
||||
ram: (Number(ramUsage) * 1000) / 1024 / 1024,
|
||||
disk: Number(diskUsage) / 1024 / 1024,
|
||||
disk: Number(storage) / 1024 / 1024,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
this.handleError(error, res);
|
||||
this.server.client.util.handleError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,33 +8,45 @@ export default class Root extends Route {
|
|||
}
|
||||
|
||||
public bind() {
|
||||
this.router.get('/', async (req, res) => {
|
||||
this.router.get('/', async (_req, res) => {
|
||||
try {
|
||||
const date = new Date();
|
||||
date.setSeconds(-process.uptime());
|
||||
const accounts = await this.server.client.db.Account.find();
|
||||
const accounts = await this.server.client.db.Account.find().lean().exec();
|
||||
const administrators = accounts.filter((account) => account.root === true).length;
|
||||
const technicians = accounts.filter((account) => account?.permissions?.director === true).length;
|
||||
const staff = accounts.filter((account) => account?.permissions?.staff === true).length;
|
||||
const response = {
|
||||
csd: {
|
||||
nodeVersion: process.version,
|
||||
uptime: process.uptime(),
|
||||
server: {
|
||||
users: accounts.length,
|
||||
administrators,
|
||||
},
|
||||
server: {
|
||||
userCount: accounts.length,
|
||||
administratorCount: administrators,
|
||||
technicianCount: technicians,
|
||||
staffCount: staff,
|
||||
stats: {
|
||||
uptime: os.uptime(),
|
||||
loadAverage: os.loadavg(),
|
||||
cpuModel: os.cpus()[0].model,
|
||||
cpuClock: os.cpus()[0].speed / 1000,
|
||||
cpuCores: os.cpus().length,
|
||||
loadAverages: os.loadavg(),
|
||||
hostname: os.hostname(),
|
||||
ipv4: os.networkInterfaces().enp0s3.filter((r) => r.family === 'IPv4')[0].address,
|
||||
ipv4Address: os.networkInterfaces().enp0s3.filter((r) => r.family === 'IPv4')[0].address,
|
||||
operatingSystem: {
|
||||
platform: os.platform(),
|
||||
kernelVersion: os.version(),
|
||||
release: os.release(),
|
||||
},
|
||||
cpu: {
|
||||
model: os.cpus()[0].model,
|
||||
clockSpeed: os.cpus()[0].speed / 1000,
|
||||
coreCount: os.cpus().length,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
res.status(200).json({ code: this.constants.codes.SUCCESS, message: response });
|
||||
} catch (error) {
|
||||
this.handleError(error, res);
|
||||
this.server.client.util.handleError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue