diff --git a/server/.github/test.conf.json5 b/server/.github/test.conf.json5 index 3bf6f03b1..81606dc3d 100644 --- a/server/.github/test.conf.json5 +++ b/server/.github/test.conf.json5 @@ -20,7 +20,6 @@ REDIRECT_URI: "https://example.com", }, ARC_AUTH_TOKEN: "unused", - CDN_FILE_ROOT: "./test-cdn", TYPE: "omni", ENABLE_SERVER_HTTPS: false, RUN_OWN_CDN: true, diff --git a/server/.github/workflows/tests.yml b/server/.github/workflows/tests.yml index 4ebf723ad..958fe0cf0 100644 --- a/server/.github/workflows/tests.yml +++ b/server/.github/workflows/tests.yml @@ -44,6 +44,7 @@ jobs: PORT: 8080 MONGO_URL: "127.0.0.1" REDIS_URL: "127.0.0.1" + CDN_FILE_ROOT: "./test-cdn" - name: Lint Code run: pnpm lint diff --git a/server/src/lib/cdn/cdn.ts b/server/src/lib/cdn/cdn.ts index f36cc595a..68dadfcf0 100644 --- a/server/src/lib/cdn/cdn.ts +++ b/server/src/lib/cdn/cdn.ts @@ -4,7 +4,7 @@ import CreateLogCtx from "lib/logger/logger"; import { promisify } from "util"; import mkdirp from "mkdirp"; import { Response } from "express"; -import { ServerConfig } from "lib/setup/config"; +import { Environment, ServerConfig } from "lib/setup/config"; const readFilePromise = promisify(fs.readFile); const writeFilePromise = promisify(fs.writeFile); @@ -19,7 +19,7 @@ const logger = CreateLogCtx(__filename); * Path directory traversal *is* possible, and *will* ruin your day. */ function CDNRoot(fileLoc: string) { - return path.join(ServerConfig.CDN_FILE_ROOT, fileLoc); + return path.join(Environment.cdnRoot, fileLoc); } /** diff --git a/server/src/lib/setup/config.ts b/server/src/lib/setup/config.ts index 40fb4c3fc..e312b89c3 100644 --- a/server/src/lib/setup/config.ts +++ b/server/src/lib/setup/config.ts @@ -56,7 +56,6 @@ export interface TachiConfig { EAG_OAUTH2_INFO?: OAuth2Info; MIN_OAUTH2_INFO?: OAuth2Info; ARC_AUTH_TOKEN: string; - CDN_FILE_ROOT: string; TYPE: "ktchi" | "btchi" | "omni"; ENABLE_SERVER_HTTPS?: boolean; RUN_OWN_CDN?: boolean; @@ -96,7 +95,6 @@ const err = p(config, { EAG_OAUTH2_INFO: isValidOauth2, MIN_OAUTH2_INFO: isValidOauth2, ARC_AUTH_TOKEN: "string", - CDN_FILE_ROOT: "string", ENABLE_SERVER_HTTPS: "*boolean", RUN_OWN_CDN: "*boolean", CLIENT_DEV_SERVER: "*?string", @@ -163,8 +161,15 @@ if (!mongoUrl) { process.exit(1); } +const cdnRoot = process.env.CDN_FILE_ROOT; +if (!cdnRoot) { + logger.error(`No CDN_FILE_ROOT specified in environment. Terminating.`); + process.exit(1); +} + export const Environment = { port, redisUrl, mongoUrl, + cdnRoot, };