diff --git a/server/.github/test.conf.json5 b/server/.github/test.conf.json5 index b3f9d0d5f..4265d9963 100644 --- a/server/.github/test.conf.json5 +++ b/server/.github/test.conf.json5 @@ -11,5 +11,5 @@ ARC_AUTH_TOKEN: "unused", CDN_ROOT: "./local-cdn", PORT: 8080, - TYPE: "ktchi", // It really doesn't matter whether we're in bokutachi or kamaitachi mode. If we had the performance we could run these in parallel? + TYPE: "omni", // It really doesn't matter whether we're in bokutachi or kamaitachi mode. If we had the performance we could run these in parallel? } diff --git a/server/src/lib/setup/config.ts b/server/src/lib/setup/config.ts index e03381f6e..62967b1f7 100644 --- a/server/src/lib/setup/config.ts +++ b/server/src/lib/setup/config.ts @@ -36,7 +36,7 @@ export interface TachiConfig { ARC_API_URL: string; ARC_AUTH_TOKEN: string; CDN_ROOT: string; - TYPE: "ktchi" | "btchi"; + TYPE: "ktchi" | "btchi" | "omni"; PORT: integer; INFO: { NAME: string; @@ -54,25 +54,43 @@ const err = p(config, { ARC_AUTH_TOKEN: "string", CDN_ROOT: "string", PORT: p.isPositiveInteger, - TYPE: p.isIn("ktchi", "btchi"), + TYPE: p.isIn("ktchi", "btchi", "omni"), }); if (err) { throw FormatPrError(err, "Invalid conf.json5 file."); } +/** + * KTCHI | Kamaitachi is the arcade build of Tachi. + */ const KTCHI_INFO: TachiConfig["INFO"] = { NAME: "Kamaitachi", }; +/** + * BTCHI | Bokutachi is the home-simulator build of Tachi. + */ const BTCHI_INFO: TachiConfig["INFO"] = { NAME: "Bokutachi", }; +/** + * OMNI | Omnitachi is a local development/testing build of Tachi, which enables all endpoints. + * + * If you're one of those nerds who is reading this to figure out how to steal and rerun + * this codebase this is what you're looking for. + */ +const OMNI_INFO: TachiConfig["INFO"] = { + NAME: "Omnitachi", +}; + if (config.TYPE === "ktchi") { config.INFO = KTCHI_INFO; -} else { +} else if (config.TYPE === "btchi") { config.INFO = BTCHI_INFO; +} else if (config.type === "omni") { + config.INFO = OMNI_INFO; } const tachiConfig = config as TachiConfig; diff --git a/server/src/server/middleware/type-require.ts b/server/src/server/middleware/type-require.ts new file mode 100644 index 000000000..7915d24ba --- /dev/null +++ b/server/src/server/middleware/type-require.ts @@ -0,0 +1,34 @@ +import { CONFIG } from "../../lib/setup/config"; +import { RequestHandler } from "express"; + +/** + * Middleware that makes the route only available under Bokutachi. + * Note that if the special type "tachi" is set (which is set for testing purposes) + * this restriction is bypassed. + */ +export const RequireBokutachi: RequestHandler = (req, res, next) => { + if (CONFIG.TYPE === "btchi" || CONFIG.TYPE === "omni") { + return next(); + } + + return res.status(404).send({ + success: false, + description: `The route ${req.route} is only available on Bokutachi.`, + }); +}; + +/** + * Middleware that makes the route only available under Kamaitachi. + * Note that if the special type "tachi" is set (which is set for testing purposes) + * this restriction is bypassed. + */ +export const RequireKamaitachi: RequestHandler = (req, res, next) => { + if (CONFIG.TYPE === "ktchi" || CONFIG.TYPE === "omni") { + return next(); + } + + return res.status(404).send({ + success: false, + description: `The route ${req.route} is only available on Kamaitachi.`, + }); +};