Files
api/app/core/modules/info/get-os.ts
T
Alexis 010efe75bd Revert "chore: lint all the files"
This reverts commit 4ef387b5bb.
2021-09-07 13:46:23 +09:30

44 lines
871 B
TypeScript

/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import { uptime } from 'os';
import si from 'systeminformation';
import { CoreContext, CoreResult } from '../../types';
import { ensurePermission } from '../../utils';
// Get uptime on boot and convert to date
const bootTimestamp = new Date(new Date().getTime() - (uptime() * 1000));
/**
* Get OS info
*
* @memberof Core
* @module info/get-os
*/
export const getOs = async function (context: CoreContext): Promise<CoreResult> {
const { user } = context;
// Check permissions
ensurePermission(user, {
resource: 'os',
action: 'read',
possession: 'any'
});
const os = await si.osInfo();
return {
get text() {
return `OS info: ${JSON.stringify(os, null, 2)}`;
},
get json() {
return {
...os,
uptime: bootTimestamp
};
}
};
};