refactor: instance update config api

This commit is contained in:
unitwk 2022-11-20 15:06:44 +08:00
parent 2e15f2fa1d
commit a46e6fc906
3 changed files with 26 additions and 2 deletions

View File

@ -44,3 +44,28 @@ export function configureEntityParams(self: any, args: any, key: string, typeFn?
self[key] = v;
}
}
export function toText(v: any) {
if (isEmpty(v)) return null;
return String(v);
}
export function toNumber(v: any) {
if (isEmpty(v)) return null;
if (isNaN(Number(v))) return null;
return Number(v);
}
export function toBoolean(v: any) {
if (isEmpty(v)) return null;
return Boolean(v);
}
export function isEmpty(v: any) {
return v === null || v === undefined;
}
export function supposeValue(v: any, def: any = null) {
if (isEmpty(v)) return def;
return v;
}

View File

@ -44,7 +44,7 @@ export default class OpenFrpTask implements ILifeCycleTask {
public name: string = "openfrp";
async start(instance: Instance) {
const { openFrpToken, openFrpTunnelId, isOpenFrp } = instance.config?.extraServiceConfig;
const { openFrpToken, openFrpTunnelId } = instance.config?.extraServiceConfig;
if (openFrpToken && openFrpTunnelId) {
const frpProcess = new OpenFrp(openFrpToken, openFrpTunnelId);
frpProcess.processWrapper.on("start", (pid) => {

View File

@ -67,7 +67,6 @@ export default class InstanceConfig {
};
public extraServiceConfig = {
isOpenFrp: false,
openFrpTunnelId: "",
openFrpToken: ""
};