feat: add configErrorState

This commit is contained in:
Alexis
2021-09-08 20:26:22 +09:30
parent 97d40b4c4d
commit a6b1657062
2 changed files with 28 additions and 13 deletions

View File

@@ -1,11 +1,11 @@
/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Copyright 2019-2021 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
import path from 'path';
import { paths } from '../paths';
import { Var } from '../types/states';
import { ConfigErrorState, Var } from '../types/states';
import { IniStringBooleanOrAuto, IniStringBoolean } from '../types/ini';
import { State } from './state';
import { toNumber } from '../utils/casting';
@@ -42,20 +42,20 @@ const iniBooleanOrAutoToJsBoolean = (value: IniStringBooleanOrAuto | string) =>
};
/**
* Unraid registation check
* Unraid registration check
*/
type RegistationCheck =
type RegistrationCheck =
/** Key file is missing. */
'ENOKEYFILE2' |
/** Everything is fine. */
'';
/**
* Unraid registation type
* Unraid registration type
*
* Check the {@link https://unraid.net/pricing | pricing page} for up to date info.
*/
type RegistationType =
type RegistrationType =
/** Missing key file. */
'- missing key file' |
/** Up to 6 attached storage devices. */
@@ -166,14 +166,14 @@ interface VarIni {
portssl: string;
porttelnet: string;
queueDepth: string;
regCheck: RegistationCheck;
regCheck: RegistrationCheck;
regFile: string;
regGen: string;
regGuid: string;
regTm: string;
regTm2: string;
regTo: string;
regTy: RegistationType;
regTy: RegistrationType;
regState: RegistrationState;
safeMode: string;
sbClean: string;
@@ -226,12 +226,19 @@ interface VarIni {
}
const parse = (state: VarIni): Var => {
const configValid = iniBooleanToJsBoolean(state.configValid, false);
return {
...state,
bindMgt: iniBooleanOrAutoToJsBoolean(state.bindMgt),
cacheNumDevices: toNumber(state.cacheNumDevices),
cacheSbNumDisks: toNumber(state.cacheSbNumDisks),
configValid: iniBooleanToJsBoolean(state.configValid, false),
configValid,
configError: configValid === false ? (({
error: 'UNKNOWN_ERROR',
invalid: 'INVALID',
nokeyserver: 'NO_KEY_SERVER',
withdrawn: 'WITHDRAWN'
}[state.configValid] ?? 'UNKNOWN_ERROR') as ConfigErrorState) : undefined,
deviceCount: toNumber(state.deviceCount),
fsCopyPrcnt: toNumber(state.fsCopyPrcnt),
fsNumMounted: toNumber(state.fsNumMounted),
@@ -300,7 +307,7 @@ const parse = (state: VarIni): Var => {
interface ParseOptions {
/** If the internal store should be updated with the new data. */
set?: boolean;
/** If the main bus should recieve an event with the new data. */
/** If the main bus should receive an event with the new data. */
emit?: boolean;
}

View File

@@ -1,5 +1,5 @@
/*!
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
* Copyright 2019-2021 Lime Technology Inc. All rights reserved.
* Written by: Alexis Tyler
*/
@@ -8,6 +8,12 @@ type FsType = 'xfs' | string;
type RegistrationCheck = 'Error' | 'Valid';
type RegistrationType = 'INVALID' | 'BASIC' | 'PLUS' | 'PRO' | string;
export type ConfigErrorState =
'UNKNOWN_ERROR' |
'INVALID' |
'NO_KEY_SERVER' |
'WITHDRAWN';
/**
* Global vars
*/
@@ -19,6 +25,8 @@ export interface Var {
comment: string;
/** Is the array's config valid. */
configValid: boolean;
/** If the array's config isn't valid this is the reason. */
configError?: ConfigErrorState;
/** Current CSRF token for HTTP requests with emhttpd. */
csrfToken: string;
defaultFormat: string;
@@ -115,7 +123,7 @@ export interface Var {
queueDepth: string;
regCheck: string;
regState: string;
/** Where the registeration key is stored. (e.g. "/boot/config/Pro.key") */
/** Where the registration key is stored. (e.g. "/boot/config/Pro.key") */
regFile: string;
regGen: string;
regGuid: string;
@@ -125,7 +133,7 @@ export interface Var {
regTo: string;
/** Which type of key this is. */
regTy: RegistrationType;
/** Is the server currently in safemode. */
/** Is the server currently in safe mode. */
safeMode: boolean;
sbClean: boolean;
sbEvents: number;