mirror of
https://github.com/unraid/api.git
synced 2026-01-14 04:29:51 -06:00
feat: add owner info
This commit is contained in:
40
app/core/modules/info/get-owner.ts
Normal file
40
app/core/modules/info/get-owner.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/*!
|
||||
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
|
||||
* Written by: Alexis Tyler
|
||||
*/
|
||||
|
||||
import { getServers } from '../../../graphql/schema/utils';
|
||||
import { apiManager } from '../../api-manager';
|
||||
import { CoreContext, CoreResult } from '../../types';
|
||||
import { ensurePermission } from '../../utils';
|
||||
|
||||
/**
|
||||
* Get server's owner info
|
||||
*
|
||||
* @memberof Core
|
||||
* @module info/get-owner
|
||||
*/
|
||||
export const getOwner = async function (context: CoreContext): Promise<CoreResult> {
|
||||
const { user } = context;
|
||||
|
||||
// Check permissions
|
||||
ensurePermission(user, {
|
||||
resource: 'owner',
|
||||
action: 'read',
|
||||
possession: 'any'
|
||||
});
|
||||
|
||||
const apiKey = apiManager.getValidKeys().find(key => key.name === 'my_servers')?.key.toString()!;
|
||||
const server = await getServers().then(servers => servers.find(server => server.apikey === apiKey));
|
||||
|
||||
return {
|
||||
get text() {
|
||||
return `Owner: ${server?.owner?.username ?? 'root'}`;
|
||||
},
|
||||
get json() {
|
||||
return {
|
||||
...server?.owner
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user