From 7fe94076c703c608cd6b4a4cd4779e9bec88a989 Mon Sep 17 00:00:00 2001 From: GyDi Date: Sat, 19 Mar 2022 16:02:47 +0800 Subject: [PATCH] feat: reduce the impact of the enhanced mode --- src/services/enhance.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/services/enhance.ts b/src/services/enhance.ts index d25c6c8..57e4ff6 100644 --- a/src/services/enhance.ts +++ b/src/services/enhance.ts @@ -101,6 +101,8 @@ class Enhance { const payload = event.payload as CmdType.EnhancedPayload; let pdata = payload.current || {}; + let hasScript = false; + for (const each of payload.chain) { const { uid, type = "" } = each.item; @@ -109,6 +111,7 @@ class Enhance { if (type === "script") { // support async main function pdata = await toScript(each.script!, { ...pdata }); + hasScript = true; } // process merge @@ -132,6 +135,29 @@ class Enhance { } } + // If script is never used + // filter other fields + if (!hasScript) { + const validKeys = [ + "proxies", + "proxy-providers", + "proxy-groups", + "rule-providers", + "rules", + ]; + + // to lowercase + const newData: any = {}; + Object.keys(pdata).forEach((key) => { + const newKey = key.toLowerCase(); + if (validKeys.includes(newKey)) { + newData[newKey] = (pdata as any)[key]; + } + }); + + pdata = newData; + } + const result = { data: pdata, status: "ok" }; emit(payload.callback, JSON.stringify(result)).catch(console.error); });