Просмотр исходного кода

Server: Interface ServiceConfig#params doch nochmal anders - Betrifft GET /services/{serverID}

Christian Kahlau 3 лет назад
Родитель
Сommit
d396fdeafc
2 измененных файлов с 22 добавлено и 7 удалено
  1. 2 2
      common/interfaces/service-config.interface.ts
  2. 20 5
      server/src/ctrl/database.class.ts

+ 2 - 2
common/interfaces/service-config.interface.ts

@@ -7,11 +7,11 @@ export interface ServiceConfig {
   params: Array<{
     type: ParamType;
     key: string;
-    value: string | number;
+    value: string | string[] | number;
   }>;
 }
 
-export const ParamTypes = ['text', 'number', 'regexp'] as const;
+export const ParamTypes = ['text', 'number', 'check'] as const;
 export type ParamType = typeof ParamTypes[number];
 
 export function validateParamType(input: string): ParamType {

+ 20 - 5
server/src/ctrl/database.class.ts

@@ -255,11 +255,26 @@ export class Database extends SQLiteController {
 
       if (!!line['_ParamKey']) {
         const type = validateParamType(line['_ParamType']);
-        config.params.push({
-          type,
-          key: line['_ParamKey'],
-          value: type === 'number' ? Number(line['_ParamValue']) : line['_ParamValue']
-        });
+        const key = line['_ParamKey'];
+        if (type === 'check') {
+          let checkParam = config.params.find(c => c.type === 'check');
+          if (!checkParam) {
+            config.params.push(
+              (checkParam = {
+                key: 'regexp',
+                type: 'check',
+                value: []
+              })
+            );
+          }
+          (checkParam.value as string[]).push(line['_ParamValue']);
+        } else {
+          config.params.push({
+            type,
+            key,
+            value: type === 'number' ? Number(line['_ParamValue']) : line['_ParamValue']
+          });
+        }
       }
 
       return res;