mirror of
https://github.com/unraid/api.git
synced 2026-01-03 23:19:54 -06:00
fix: os.uptime
This commit is contained in:
@@ -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()
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -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';
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 () => ({});
|
||||
|
||||
@@ -51,9 +51,6 @@ export const Subscription = {
|
||||
unassignedDevices: {
|
||||
...createSubscription('devices/unassigned')
|
||||
},
|
||||
uptime: {
|
||||
...createSubscription('uptime')
|
||||
},
|
||||
users: {
|
||||
...createSubscription('users')
|
||||
},
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
type Query {
|
||||
uptime: Uptime @func(module: "getUptime")
|
||||
}
|
||||
|
||||
type Subscription {
|
||||
uptime: Uptime
|
||||
}
|
||||
|
||||
type Uptime {
|
||||
milliseconds: Int!
|
||||
timestamp: String!
|
||||
}
|
||||
@@ -166,7 +166,6 @@ type Vars {
|
||||
shareAfpCount: Int
|
||||
shareMoverActive: Boolean
|
||||
csrfToken: String
|
||||
uptime: String!
|
||||
}
|
||||
|
||||
enum mdState {
|
||||
|
||||
@@ -137,11 +137,6 @@
|
||||
"action": "read:any",
|
||||
"attributes": "*"
|
||||
},
|
||||
{
|
||||
"resource": "uptime",
|
||||
"action": "read:any",
|
||||
"attributes": "*"
|
||||
},
|
||||
{
|
||||
"resource": "user",
|
||||
"action": "read:any",
|
||||
|
||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user