fix: ensure we return an empty string when key file is missing

This commit is contained in:
Alexis Tyler
2021-04-22 13:14:53 +09:30
parent eb99cd2686
commit 3f2707cff1
6 changed files with 34 additions and 25 deletions
+3 -5
View File
@@ -3,11 +3,10 @@
* 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';
import { getKeyFile } from '../../utils/misc/get-key-file';
/**
* Get server's license info
@@ -28,8 +27,7 @@ export const getLicense = async function (context: CoreContext): Promise<CoreRes
// 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, '');
const file = await getKeyFile();
return {
get text() {
@@ -39,7 +37,7 @@ export const getLicense = async function (context: CoreContext): Promise<CoreRes
return {
type,
state,
file: parsedFile
file
};
}
};