2020-09-25 15:42:55 +02:00
|
|
|
import {ADMIN_API_TOKEN} from "../Enum/EnvironmentVariable";
|
2020-09-25 13:48:02 +02:00
|
|
|
import {IoSocketController} from "_Controller/IoSocketController";
|
|
|
|
import {stringify} from "circular-json";
|
2020-09-29 10:57:14 +02:00
|
|
|
import {HttpRequest, HttpResponse} from "uWebSockets.js";
|
|
|
|
import { parse } from 'query-string';
|
|
|
|
import {App} from "../Server/sifrr.server";
|
2020-09-25 13:48:02 +02:00
|
|
|
|
|
|
|
export class DebugController {
|
2020-09-29 10:57:14 +02:00
|
|
|
constructor(private App : App, private ioSocketController: IoSocketController) {
|
2020-09-25 13:48:02 +02:00
|
|
|
this.getDump();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getDump(){
|
2020-09-29 10:57:14 +02:00
|
|
|
this.App.get("/dump", (res: HttpResponse, req: HttpRequest) => {
|
|
|
|
const query = parse(req.getQuery());
|
|
|
|
|
|
|
|
if (query.token !== ADMIN_API_TOKEN) {
|
2020-09-25 13:48:02 +02:00
|
|
|
return res.status(401).send('Invalid token sent!');
|
|
|
|
}
|
|
|
|
|
2020-09-29 10:57:14 +02:00
|
|
|
return res.writeStatus('200 OK').writeHeader('Content-Type', 'application/json').end(stringify(
|
2020-09-25 13:48:02 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|