mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-28 18:08:15 +03:00
create require middleware and make type: omni
This commit is contained in:
Vendored
+1
-1
@@ -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?
|
||||
}
|
||||
|
||||
@@ -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.`,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user