From d74e83dc750495cffc9c1bf1a7b5a3a8dd5fe1db Mon Sep 17 00:00:00 2001 From: Netfloex <38650595+Netfloex@users.noreply.github.com> Date: Fri, 13 May 2022 00:29:51 +0200 Subject: [PATCH] Disabled static/include path check when in standalone environment --- src/lib/logMessages.ts | 19 +++++++++++-------- src/lib/logger.ts | 6 ++---- src/lib/validateConfig.ts | 13 ++++++++++++- src/tests/__snapshots__/log.test.ts.snap | 3 ++- src/utils/settings.ts | 2 ++ 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/lib/logMessages.ts b/src/lib/logMessages.ts index 611f1a2..17189c2 100644 --- a/src/lib/logMessages.ts +++ b/src/lib/logMessages.ts @@ -381,6 +381,17 @@ export const logMessages = defineLogList({ chalk`Config is a promise, waiting until it resolves.` ], + warnNoHost: ({ host }: { host: string }) => [ + Log.warn, + Tag.config, + chalk`Could not resolve {yellow ${host}}, normally this would exit.` + ], + warnPathNotFound: ({ path }: { path: string }) => [ + Log.warn, + Tag.config, + chalk`The path {dim ${path}} could not be found, but since you are using the standalone version you might not need it in this container.` + ], + // CSS downloadCSS: ({ url }: { url: string }) => [ @@ -500,13 +511,5 @@ export const logMessages = defineLogList({ Log.warn, Tag.env, chalk`Could not parse {dim ${string}} to a number, defaulting to ${or}` - ], - - // DNS - - warnNoHost: ({ host }: { host: string }) => [ - Log.warn, - Tag.dns, - chalk`Could not resolve {yellow ${host}}, normally this would exit.` ] } as const); diff --git a/src/lib/logger.ts b/src/lib/logger.ts index b37c64a..3d99157 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -24,8 +24,7 @@ export enum Tag { js, cloudflare, env, - nginx, - dns + nginx } const TagList: Record = { @@ -37,8 +36,7 @@ const TagList: Record = { "5": chalk`[{yellow JS}]`, "6": chalk`[{hex("#FF8800") CLOUDFLARE}]`, "7": chalk`[{blue ENV}]`, - "8": chalk`[{green NGINX}]`, - "9": chalk`[{red DNS}]` + "8": chalk`[{green NGINX}]` }; const TypeList: Record = { diff --git a/src/lib/validateConfig.ts b/src/lib/validateConfig.ts index 15b6b3f..7ea3867 100644 --- a/src/lib/validateConfig.ts +++ b/src/lib/validateConfig.ts @@ -122,7 +122,18 @@ const pathNameSchema = (error: string) => .string() .transform((str) => resolve(str)) .refine( - async (path) => await pathExists(path), + async (path) => { + const exists = await pathExists(path); + if (exists) return true; + + if (settings.standalone) { + logger.warnPathNotFound({ path }); + + return true; + } + + return false; + }, (path) => ({ message: chalk`${error}: {dim ${path}}` }) diff --git a/src/tests/__snapshots__/log.test.ts.snap b/src/tests/__snapshots__/log.test.ts.snap index 4f61d82..21b7e31 100644 --- a/src/tests/__snapshots__/log.test.ts.snap +++ b/src/tests/__snapshots__/log.test.ts.snap @@ -46,6 +46,8 @@ Error: undefined", "[NCM] [INFO] [CONFIG] Config is valid undefined", "[NCM] [WARN] [CONFIG] Config contains undefined, while process.env.undefined was not defined.", "[NCM] [INFO] [CONFIG] Config is a promise, waiting until it resolves.", + "[NCM] [WARN] [CONFIG] Could not resolve undefined, normally this would exit.", + "[NCM] [WARN] [CONFIG] The path undefined could not be found, but since you are using the standalone version you might not need it in this container.", "[NCM] [INFO] [CSS] Downloading CSS file... undefined", "[NCM] [DONE] [CSS] CSS file is cached, skipping: undefined", "[NCM] [DONE] [CSS] Downloaded CSS file undefined", @@ -65,7 +67,6 @@ undefined", "[NCM] [DONE] [CLOUDFLARE] Cloudflare ip list has been generated. Added undefined ip addresses.", "[NCM] [ERROR] [CLOUDFLARE] undefined", "[NCM] [WARN] [ENV] Could not parse undefined to a number, defaulting to undefined", - "[NCM] [WARN] [DNS] Could not resolve undefined, normally this would exit.", {}, ] `; diff --git a/src/utils/settings.ts b/src/utils/settings.ts index 40c51f5..ab38870 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -41,6 +41,8 @@ const settings = { authPath: r(env.AUTH_PATH, join(dataPath, "auth")), storePath: r(env.STORE_PATH, join(dataPath, "store.json")), + standalone: env.STANDALONE == "true", + cloudflareExpiry: parseIntDefault( env.CLOUDFLARE_CACHE_DURATION, 1000 * 60 * 60 * 24 * 7 // 7 Days