Refactoring Woka management (#1810)
* Wrap websockets with HyperExpress * Add endpoints on pusher to resolve wokas * getting textures urls from pusher * Adding OpenAPI documentation for the pusher. The pusher now exposes a "/openapi" endpoint and a "/swagger-ui/" endpoint. * revert FRONT_URL * playerTextures metadata is being loaded via Phaser.Loader * fetch textures every time character or customize scene is open * Heavy changes: refactoring the pusher to always send the textures (and the front to accept them) * Sending character layer details to admin * Cleaning commented code * Fixing regex * Fix woka endpoints on pusher * Change error wording on pusher * Working on integration of the woka-list with the new admin endpoint. * Switching from "name" to "id" in texture object + using zod for woka/list validation * Add position on default woka data * Remove async on pusher option method * Fix woka list url * add options for /register * Fxiing loading the Woka list * Actually returning something in logout-callback * Copying messages to back too * remove customize button if no body parts are available (#1952) * remove customize button if no body parts are available * remove unused position field from PlayerTexturesCollection interface * removed unused label field * fix LocalUser test * little PlayerTextures class refactor * Fixing linting * Fixing missing Openapi packages in prod * Fixing back build Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com> * Add returns on pusher endpoints Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re> Co-authored-by: Hanusiak Piotr <piotr@ltmp.co> Co-authored-by: Piotr Hanusiak <wacneg@gmail.com>
This commit is contained in:
@@ -1,41 +1,101 @@
|
||||
import { HttpRequest, HttpResponse, TemplatedApp } from "uWebSockets.js";
|
||||
import { BaseController } from "./BaseController";
|
||||
import { parse } from "query-string";
|
||||
import { adminApi } from "../Services/AdminApi";
|
||||
import { ADMIN_API_URL, DISABLE_ANONYMOUS, FRONT_URL } from "../Enum/EnvironmentVariable";
|
||||
import { ADMIN_API_URL, DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
||||
import { isMapDetailsData, MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||
import { socketManager } from "../Services/SocketManager";
|
||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||
import { v4 } from "uuid";
|
||||
import { InvalidTokenError } from "./InvalidTokenError";
|
||||
import { parse } from "query-string";
|
||||
import { BaseHttpController } from "./BaseHttpController";
|
||||
|
||||
export class MapController extends BaseController {
|
||||
constructor(private App: TemplatedApp) {
|
||||
super();
|
||||
this.App = App;
|
||||
this.getMapUrl();
|
||||
}
|
||||
|
||||
export class MapController extends BaseHttpController {
|
||||
// Returns a map mapping map name to file name of the map
|
||||
getMapUrl() {
|
||||
this.App.options("/map", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
res.end();
|
||||
});
|
||||
|
||||
this.App.get("/map", (res: HttpResponse, req: HttpRequest) => {
|
||||
res.onAborted(() => {
|
||||
console.warn("/map request was aborted");
|
||||
});
|
||||
|
||||
const query = parse(req.getQuery());
|
||||
|
||||
routes() {
|
||||
/**
|
||||
* @openapi
|
||||
* /map:
|
||||
* get:
|
||||
* description: Returns a map mapping map name to file name of the map
|
||||
* produces:
|
||||
* - "application/json"
|
||||
* parameters:
|
||||
* - name: "playUri"
|
||||
* in: "query"
|
||||
* description: "The full URL of WorkAdventure to load this map"
|
||||
* required: true
|
||||
* type: "string"
|
||||
* - name: "authToken"
|
||||
* in: "query"
|
||||
* description: "The authentication token"
|
||||
* required: true
|
||||
* type: "string"
|
||||
* responses:
|
||||
* 200:
|
||||
* description: The details of the map
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - mapUrl
|
||||
* - policy_type
|
||||
* - tags
|
||||
* - textures
|
||||
* - authenticationMandatory
|
||||
* - roomSlug
|
||||
* - contactPage
|
||||
* - group
|
||||
* properties:
|
||||
* mapUrl:
|
||||
* type: string
|
||||
* description: The full URL to the JSON map file
|
||||
* example: https://myuser.github.io/myrepo/map.json
|
||||
* policy_type:
|
||||
* type: integer
|
||||
* description: ANONYMOUS_POLICY = 1, MEMBERS_ONLY_POLICY = 2, USE_TAGS_POLICY= 3
|
||||
* example: 1
|
||||
* tags:
|
||||
* type: array
|
||||
* description: The list of tags required to enter this room
|
||||
* items:
|
||||
* type: string
|
||||
* example: speaker
|
||||
* authenticationMandatory:
|
||||
* type: boolean|null
|
||||
* description: Whether the authentication is mandatory or not for this map.
|
||||
* example: true
|
||||
* roomSlug:
|
||||
* type: string
|
||||
* description: The slug of the room
|
||||
* deprecated: true
|
||||
* example: foo
|
||||
* contactPage:
|
||||
* type: string|null
|
||||
* description: The URL to the contact page
|
||||
* example: https://mycompany.com/contact-us
|
||||
* group:
|
||||
* type: string|null
|
||||
* description: The group this room is part of (maps the notion of "world" in WorkAdventure SAAS)
|
||||
* example: myorg/myworld
|
||||
* iframeAuthentication:
|
||||
* type: string|null
|
||||
* description: The URL of the authentication Iframe
|
||||
* example: https://mycompany.com/authc
|
||||
* expireOn:
|
||||
* type: string|undefined
|
||||
* description: The date (in ISO 8601 format) at which the room will expire
|
||||
* example: 2022-11-05T08:15:30-05:00
|
||||
* canReport:
|
||||
* type: boolean|undefined
|
||||
* description: Whether the "report" feature is enabled or not on this room
|
||||
* example: true
|
||||
*
|
||||
*/
|
||||
this.app.get("/map", (req, res) => {
|
||||
const query = parse(req.path_query);
|
||||
if (typeof query.playUri !== "string") {
|
||||
console.error("Expected playUri parameter in /map endpoint");
|
||||
res.writeStatus("400 Bad request");
|
||||
this.addCorsHeaders(res);
|
||||
res.end("Expected playUri parameter");
|
||||
res.status(400);
|
||||
res.send("Expected playUri parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,30 +105,22 @@ export class MapController extends BaseController {
|
||||
|
||||
const match = /\/_\/[^/]+\/(.+)/.exec(roomUrl.pathname);
|
||||
if (!match) {
|
||||
res.writeStatus("404 Not Found");
|
||||
this.addCorsHeaders(res);
|
||||
res.writeHeader("Content-Type", "application/json");
|
||||
res.end(JSON.stringify({}));
|
||||
res.status(404);
|
||||
res.json({});
|
||||
return;
|
||||
}
|
||||
|
||||
const mapUrl = roomUrl.protocol + "//" + match[1];
|
||||
|
||||
res.writeStatus("200 OK");
|
||||
this.addCorsHeaders(res);
|
||||
res.writeHeader("Content-Type", "application/json");
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
mapUrl,
|
||||
policy_type: GameRoomPolicyTypes.ANONYMOUS_POLICY,
|
||||
roomSlug: null, // Deprecated
|
||||
group: null,
|
||||
tags: [],
|
||||
textures: [],
|
||||
contactPage: null,
|
||||
authenticationMandatory: DISABLE_ANONYMOUS,
|
||||
} as MapDetailsData)
|
||||
);
|
||||
res.json({
|
||||
mapUrl,
|
||||
policy_type: GameRoomPolicyTypes.ANONYMOUS_POLICY,
|
||||
roomSlug: null, // Deprecated
|
||||
group: null,
|
||||
tags: [],
|
||||
contactPage: null,
|
||||
authenticationMandatory: DISABLE_ANONYMOUS,
|
||||
} as MapDetailsData);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -90,12 +142,12 @@ export class MapController extends BaseController {
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidTokenError) {
|
||||
// The token was not good, redirect user on login page
|
||||
res.writeStatus("401 Unauthorized");
|
||||
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
|
||||
res.end("Token decrypted error");
|
||||
res.status(401);
|
||||
res.send("Token decrypted error");
|
||||
return;
|
||||
} else {
|
||||
return this.errorToResponse(e, res);
|
||||
this.castErrorToResponse(e, res);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,12 +158,10 @@ export class MapController extends BaseController {
|
||||
mapDetails.authenticationMandatory = true;
|
||||
}
|
||||
|
||||
res.writeStatus("200 OK");
|
||||
this.addCorsHeaders(res);
|
||||
res.writeHeader("Content-Type", "application/json");
|
||||
res.end(JSON.stringify(mapDetails));
|
||||
res.json(mapDetails);
|
||||
return;
|
||||
} catch (e) {
|
||||
this.errorToResponse(e, res);
|
||||
this.castErrorToResponse(e, res);
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user