From db3ae9d0a65d4c8bc4cadd57a89482f6e840cdec Mon Sep 17 00:00:00 2001 From: Xi Xu Date: Thu, 10 Oct 2024 13:19:03 +0800 Subject: [PATCH] Update script.js --- script.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/script.js b/script.js index e95bd9c..dc5ed57 100644 --- a/script.js +++ b/script.js @@ -473,18 +473,16 @@ const ruleProviders = { // generate configuration using the above settings +function validateConfig(config) { + if (!Array.isArray(config.proxies) && !config["proxy-providers"]) + throw new Error( + "The configuration you provide must include either a proxies array or a proxy-providers object." + ); +} + function main(config) { try { - const proxyCount = config?.proxies?.length ?? 0; - const proxyProviderCount = - typeof config?.["proxy-providers"] === "object" - ? Object.keys(config["proxy-providers"]).length - : 0; - if (proxyCount === 0 && proxyProviderCount === 0) - throw new Error( - "Please import the configuration file containing proxies or proxy-providers." - ); - + validateConfig(config); Object.assign(config, generalConfig, { dns, hosts, @@ -494,10 +492,13 @@ function main(config) { rules, "rule-providers": ruleProviders, }); - + console.log(config); return config; } catch (error) { - console.error("Error in main function:", error); - throw error; + console.error( + "An error occurred during configuration generation: ", + error + ); + return { error: error.message, originalConfig: config }; } }