2021-06-24 10:09:10 +02:00
|
|
|
import { ADMIN_API_TOKEN } from "../Enum/EnvironmentVariable";
|
|
|
|
import { stringify } from "circular-json";
|
|
|
|
import { parse } from "query-string";
|
|
|
|
import { socketManager } from "../Services/SocketManager";
|
2022-03-11 17:02:58 +01:00
|
|
|
import { BaseHttpController } from "./BaseHttpController";
|
2020-11-13 18:00:22 +01:00
|
|
|
|
2022-03-11 17:02:58 +01:00
|
|
|
export class DebugController extends BaseHttpController {
|
|
|
|
routes() {
|
|
|
|
this.app.get("/dump", (req, res) => {
|
|
|
|
const query = parse(req.path_query);
|
2020-11-13 18:00:22 +01:00
|
|
|
|
2022-01-27 18:38:33 +01:00
|
|
|
if (ADMIN_API_TOKEN === "") {
|
2022-03-11 17:02:58 +01:00
|
|
|
return res.status(401).send("No token configured!");
|
2022-01-27 18:38:33 +01:00
|
|
|
}
|
2020-11-13 18:00:22 +01:00
|
|
|
if (query.token !== ADMIN_API_TOKEN) {
|
2022-03-11 17:02:58 +01:00
|
|
|
return res.status(401).send("Invalid token sent!");
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
2022-01-07 14:37:44 +01:00
|
|
|
const worlds = Object.fromEntries(socketManager.getWorlds().entries());
|
|
|
|
|
2022-03-11 17:02:58 +01:00
|
|
|
return res.json(
|
|
|
|
stringify(worlds, (key: unknown, value: unknown) => {
|
|
|
|
if (value instanceof Map) {
|
|
|
|
const obj: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
for (const [mapKey, mapValue] of value.entries()) {
|
|
|
|
obj[mapKey] = mapValue;
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
} else if (value instanceof Set) {
|
|
|
|
const obj: Array<unknown> = [];
|
|
|
|
for (const [setKey, setValue] of value.entries()) {
|
|
|
|
obj.push(setValue);
|
2021-06-24 10:09:10 +02:00
|
|
|
}
|
2022-03-11 17:02:58 +01:00
|
|
|
return obj;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2020-11-13 18:00:22 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|