1
0
Fork 0

New Root endpoint

refactor/models
Matthew 2019-11-17 16:12:00 -05:00
parent 42ed3da0d3
commit a45f1b6692
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 41 additions and 0 deletions

41
src/api/routes/Root.ts Normal file
View File

@ -0,0 +1,41 @@
import os from 'os';
import { Server } from '..';
import { Route } from '../../class';
export default class Root extends Route {
constructor(server: Server) {
super(server, { path: '/', deprecated: false });
}
public bind() {
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 administrators = accounts.filter((account) => account.root === true);
const response = {
nodeVersion: process.version,
uptime: process.uptime(),
server: {
users: accounts.length,
administrators,
},
stats: {
uptime: os.uptime(),
loadAverage: os.loadavg(),
cpuModel: os.cpus()[0].model,
cpuClock: os.cpus()[0].speed / 1000,
cpuCores: os.cpus().length,
hostname: os.hostname(),
ipv4: os.networkInterfaces().eth0.filter((r) => r.family === 'IPv4')[0].address,
ipv6: os.networkInterfaces().eth0.filter((r) => r.family === 'IPv6')[0].address,
},
};
res.status(200).json({ code: this.constants.codes.SUCCESS, message: response });
} catch (error) {
this.handleError(error, res);
}
});
}
}