fix: os.uptime

This commit is contained in:
Alexis Tyler
2021-06-29 06:48:13 +09:30
parent a1f748b235
commit 33a48ed655
14 changed files with 8 additions and 102 deletions

View File

@@ -1,41 +0,0 @@
/*!
* 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()
}
};
};

View File

@@ -27,7 +27,6 @@ export * from './get-permissions';
export * from './get-plugins';
export * from './get-services';
export * from './get-unassigned-devices';
export * from './get-uptime';
export * from './get-users';
export * from './get-vars';
export * from './get-welcome';

View File

@@ -3,11 +3,14 @@
* Written by: Alexis Tyler
*/
import uptime from 'os-uptime';
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
*
@@ -33,7 +36,7 @@ export const getOs = async function (context: CoreContext): Promise<CoreResult>
get json() {
return {
...os,
uptime: uptime().toISOString()
uptime: bootTimestamp
};
}
};

View File

@@ -4,7 +4,6 @@
*/
import path from 'path';
import uptime from 'os-uptime';
import { paths } from '../paths';
import { Var } from '../types/states';
import { IniStringBooleanOrAuto, IniStringBoolean } from '../types/ini';
@@ -214,7 +213,6 @@ interface VarIni {
sysFlashSlots: string;
sysModel: string;
timeZone: string;
uptime: string;
useNtp: IniStringBoolean;
useSsh: IniStringBoolean;
useSsl: IniStringBooleanOrAuto;
@@ -291,8 +289,7 @@ const parse = (state: VarIni): Var => {
useNtp: iniBooleanToJsBoolean(state.useNtp),
useSsh: iniBooleanToJsBoolean(state.useSsh),
useSsl: iniBooleanOrAutoToJsBoolean(state.useSsl),
useTelnet: iniBooleanToJsBoolean(state.useTelnet),
uptime: uptime().toISOString()
useTelnet: iniBooleanToJsBoolean(state.useTelnet)
};
};

View File

@@ -181,8 +181,6 @@ export interface Var {
sysModel: string;
/** Current timezone. {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | Timezone list}. */
timeZone: string;
/** Time the host has been online in ms. */
uptime: string;
/** Should a NTP server be used for time sync. */
useNtp: boolean;
/** Should SSH be enabled. */

View File

@@ -391,17 +391,6 @@ dee.on('*', async (data: { Type: string }) => {
dee.listen();
// OS uptime
run('uptime', 'UPDATED', {
moduleToRun: modules.getUptime,
context: {
user: internalServiceUser
},
loop: Infinity
}).catch((error: unknown) => {
log.error('Failed getting "uptime" with "%s".', (error as Error).message);
});
// Services
run('services', 'UPDATED', {
moduleToRun: modules.getServices,

View File

@@ -3,14 +3,4 @@
* Written by: Alexis Tyler
*/
import { uptime } from 'os';
// Get uptime on boot and convert to date
const bootTimestamp = new Date(new Date().getTime() - (uptime() * 1000));
export default () => ({
os: {
// Timestamp of when the server booted
uptime: bootTimestamp
}
});
export default () => ({});

View File

@@ -51,9 +51,6 @@ export const Subscription = {
unassignedDevices: {
...createSubscription('devices/unassigned')
},
uptime: {
...createSubscription('uptime')
},
users: {
...createSubscription('users')
},

View File

@@ -37,7 +37,6 @@ const files = [
'./dist/types/graphql/schema/types/unassigned-devices/mount.graphql',
'./dist/types/graphql/schema/types/unassigned-devices/partition.graphql',
'./dist/types/graphql/schema/types/unassigned-devices/unassigned-device.graphql',
'./dist/types/graphql/schema/types/uptime/uptime.graphql',
'./dist/types/graphql/schema/types/users/me.graphql',
'./dist/types/graphql/schema/types/users/user.graphql',
'./dist/types/graphql/schema/types/vars/vars.graphql',

View File

@@ -1,12 +0,0 @@
type Query {
uptime: Uptime @func(module: "getUptime")
}
type Subscription {
uptime: Uptime
}
type Uptime {
milliseconds: Int!
timestamp: String!
}

View File

@@ -166,7 +166,6 @@ type Vars {
shareAfpCount: Int
shareMoverActive: Boolean
csrfToken: String
uptime: String!
}
enum mdState {

View File

@@ -137,11 +137,6 @@
"action": "read:any",
"attributes": "*"
},
{
"resource": "uptime",
"action": "read:any",
"attributes": "*"
},
{
"resource": "user",
"action": "read:any",

5
package-lock.json generated
View File

@@ -10917,11 +10917,6 @@
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
"dev": true
},
"os-uptime": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/os-uptime/-/os-uptime-2.0.2.tgz",
"integrity": "sha512-r9N4pWwi3wQpWrGKUjM0Lpj0CwC3jngofs5Bs3pP6+GUYeZxtYT+Msl1cPvqBn9ZYR+rHL/jhPJQghXzGLGFhw=="
},
"p-cancelable": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz",

View File

@@ -107,7 +107,6 @@
"node-window-polyfill": "^1.0.2",
"number-to-color": "^0.5.0",
"observable-to-promise": "^1.0.0",
"os-uptime": "^2.0.2",
"p-iteration": "^1.1.8",
"p-props": "^4.0.0",
"p-wait-for": "^3.2.0",
@@ -246,7 +245,6 @@
"node-window-polyfill",
"number-to-color",
"observable-to-promise",
"os-uptime",
"p-iteration",
"p-props",
"p-wait-for",
@@ -275,4 +273,4 @@
"uuid-apikey",
"xhr2"
]
}
}