2020-09-25 13:48:02 +02:00
|
|
|
import {Application, Request, Response} from "express";
|
|
|
|
import {OK} from "http-status-codes";
|
|
|
|
import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable";
|
|
|
|
import Axios from "axios";
|
|
|
|
import {DEBUG_MODE} from "../../../front/src/Enum/EnvironmentVariable";
|
|
|
|
import {IoSocketController} from "_Controller/IoSocketController";
|
|
|
|
import Flatted from "flatted";
|
|
|
|
import {stringify} from "circular-json";
|
|
|
|
|
|
|
|
export class DebugController {
|
|
|
|
constructor(private App : Application, private ioSocketController: IoSocketController) {
|
|
|
|
this.getDump();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getDump(){
|
2020-09-25 15:42:05 +02:00
|
|
|
this.App.get("/dump", (req: Request, res: Response) => {
|
2020-09-25 13:48:02 +02:00
|
|
|
if (req.query.token !== ADMIN_API_TOKEN) {
|
|
|
|
return res.status(401).send('Invalid token sent!');
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.status(OK).contentType('application/json').send(stringify(
|
|
|
|
this.ioSocketController.getWorlds(),
|
2020-09-25 15:42:05 +02:00
|
|
|
(key: unknown, value: unknown) => {
|
2020-09-25 13:48:02 +02:00
|
|
|
if(value instanceof Map) {
|
2020-09-25 15:42:05 +02:00
|
|
|
const obj: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any
|
2020-09-25 13:48:02 +02:00
|
|
|
for (const [mapKey, mapValue] of value.entries()) {
|
|
|
|
obj[mapKey] = mapValue;
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
} else if(value instanceof Set) {
|
2020-09-25 15:42:05 +02:00
|
|
|
const obj: Array<unknown> = [];
|
2020-09-25 13:48:02 +02:00
|
|
|
for (const [setKey, setValue] of value.entries()) {
|
|
|
|
obj.push(setValue);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|