Files
api/app/core/modules/info/get-license.ts
T
2021-04-22 09:29:48 +09:30

47 lines
1.0 KiB
TypeScript

/*!
* Copyright 2019-2021 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import fs from 'fs';
import btoa from 'btoa';
import { varState } from '../../states';
import { CoreContext, CoreResult } from '../../types';
import { ensurePermission } from '../../utils';
/**
* Get server's license info
*
* @memberof Core
* @module info/get-license
*/
export const getLicense = async function (context: CoreContext): Promise<CoreResult> {
const { user } = context;
// Check permissions
ensurePermission(user, {
resource: 'license',
action: 'read',
possession: 'any'
});
// Get license data
const type = varState.data.regTy;
const state = varState.data.regState;
const file = await fs.promises.readFile(varState.data.regFile, 'binary');
const parsedFile = btoa(file).trim().replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
return {
get text() {
return `License type: ${type}\nState: ${state}`;
},
get json() {
return {
type,
state,
file: parsedFile
};
}
};
};