Files
api/app/core/utils/misc/get-machine-id.ts
T
Alexis 010efe75bd Revert "chore: lint all the files"
This reverts commit 4ef387b5bb.
2021-09-07 13:46:23 +09:30

25 lines
660 B
TypeScript

import fs from 'fs';
import { paths } from '../../paths';
import { CacheManager } from '../../cache-manager';
import { FileMissingError } from '../../errors';
const cache = new CacheManager('unraid:utils:misc/get-machine-id');
export const getMachineId = async (): Promise<string> => {
const path = paths.get('machine-id');
let machineId: string = cache.get('machine-id');
if (!path) {
const error = new FileMissingError('/etc/machine-id');
error.fatal = false;
throw error;
}
if (!machineId) {
machineId = await fs.promises.readFile(path, 'utf8').then(machineId => machineId.split('\n')[0].trim()).catch(() => '');
}
return machineId;
};