diff --git a/striker-ui-api/src/lib/consts/OS_LIST.ts b/striker-ui-api/src/lib/consts/OS_LIST.ts new file mode 100644 index 00000000..6cea3615 --- /dev/null +++ b/striker-ui-api/src/lib/consts/OS_LIST.ts @@ -0,0 +1,26 @@ +import { execSync } from 'child_process'; + +import SERVER_PATHS from './SERVER_PATHS'; + +type OSKeyMapToName = Record; + +const osList: string[] = execSync( + `${SERVER_PATHS.usr.sbin['striker-parse-os-list'].self} | ${SERVER_PATHS.usr.bin['sed'].self} -E 's/^.*name="os_list_([^"]+).*CDATA[[]([^]]+).*$/\\1,\\2/'`, + { + encoding: 'utf-8', + timeout: 10000, + }, +).split('\n'); + +osList.pop(); + +const osKeyMapToName: OSKeyMapToName = osList.reduce((map, csv) => { + const [osKey, osName] = csv.split(',', 2); + + map[osKey] = osName; + + return map; +}, {} as OSKeyMapToName); + +export const OS_LIST: Readonly = osList; +export const OS_LIST_MAP: Readonly = osKeyMapToName; diff --git a/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts b/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts index e10cd269..e4329107 100644 --- a/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts @@ -1,7 +1,5 @@ -import { execSync } from 'child_process'; - import NODE_AND_DR_RESERVED_MEMORY_SIZE from '../../consts/NODE_AND_DR_RESERVED_MEMORY_SIZE'; -import SERVER_PATHS from '../../consts/SERVER_PATHS'; +import { OS_LIST } from '../../consts/OS_LIST'; import join from '../../join'; import { sanitizeSQLParam } from '../../sanitizeSQLParam'; @@ -309,16 +307,9 @@ const buildQueryAnvilDetail = ({ [], ); - const osList = execSync( - `${SERVER_PATHS.usr.sbin['striker-parse-os-list'].self} | ${SERVER_PATHS.usr.bin['sed'].self} -E 's/^.*name="os_list_([^"]+).*CDATA[[]([^]]+).*$/\\1,\\2/'`, - { encoding: 'utf-8', timeout: 10000 }, - ).split('\n'); - - osList.pop(); - results = { anvils, - osList, + osList: OS_LIST, }; }