mirror of
https://github.com/unraid/api.git
synced 2026-01-06 00:30:22 -06:00
56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
/*!
|
|
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
|
|
* Written by: Alexis Tyler
|
|
*/
|
|
|
|
import { ensurePermission } from '../../utils';
|
|
import { CoreContext, CoreResult } from '../../types';
|
|
import { version } from '../../../../package.json';
|
|
|
|
interface Result extends CoreResult {
|
|
json: {
|
|
name: string;
|
|
online: boolean;
|
|
uptime: {
|
|
timestamp: string;
|
|
seconds: number;
|
|
};
|
|
};
|
|
}
|
|
|
|
// When this service started
|
|
const startTimestamp = new Date();
|
|
|
|
/**
|
|
* Get Unraid api service info.
|
|
*/
|
|
export const getUnraidApiService = async (context: CoreContext): Promise<Result> => {
|
|
const { user } = context;
|
|
|
|
// Check permissions
|
|
ensurePermission(user, {
|
|
resource: 'service/unraid-api',
|
|
action: 'read',
|
|
possession: 'any'
|
|
});
|
|
|
|
const now = new Date();
|
|
const uptimeTimestamp = startTimestamp.toISOString();
|
|
const uptimeSeconds = (now.getTime() - startTimestamp.getTime());
|
|
|
|
const service = {
|
|
name: 'unraid-api',
|
|
online: true,
|
|
uptime: {
|
|
timestamp: uptimeTimestamp,
|
|
seconds: uptimeSeconds
|
|
},
|
|
version
|
|
};
|
|
|
|
return {
|
|
text: `Service: ${JSON.stringify(service, null, 2)}`,
|
|
json: service
|
|
};
|
|
};
|