1
0
Fork 0
cloudservices/src/api/routes/Root.ts

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-11-17 16:12:00 -05:00
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();
2019-11-17 16:26:07 -05:00
const administrators = accounts.filter((account) => account.root === true).length;
2019-11-17 16:12:00 -05:00
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);
2019-11-21 09:39:07 -05:00
this.server.client.util.handleError(error);
2019-11-17 16:12:00 -05:00
}
});
}
}