create require middleware and make type: omni

This commit is contained in:
zkldi
2021-06-08 15:54:39 +01:00
parent 457c3d95a2
commit d6f9d1e786
3 changed files with 56 additions and 4 deletions
+1 -1
View File
@@ -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?
}
+21 -3
View File
@@ -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;
@@ -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.`,
});
};