Files
api/app/core/modules/get-uptime.ts
T
Alexis Tyler 4e1b0bd72c chore: lint
2021-01-28 15:45:14 +10:30

42 lines
819 B
TypeScript

/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import os from 'os';
import { ensurePermission } from '../utils';
import { CoreResult, CoreContext } from '../types';
interface Result extends CoreResult {
json: {
milliseconds: number;
timestamp: string;
};
}
/**
* OS uptime
* @returns The milliseconds since we booted.
*/
export const getUptime = async (context: CoreContext): Promise<Result> => {
const { user } = context;
// Check permissions
ensurePermission(user, {
resource: 'uptime',
action: 'read',
possession: 'any'
});
const uptime = new Date(os.uptime());
const humanFormat = uptime.getTime();
return {
text: `Uptime: ${humanFormat}`,
json: {
milliseconds: uptime.getTime(),
timestamp: uptime.toISOString()
}
};
};