From 0ac6b50469f68b92eb094f89cd66addc3cd7f944 Mon Sep 17 00:00:00 2001 From: CEC Date: Thu, 14 Apr 2022 11:59:35 +0200 Subject: [PATCH] Fix prettier and change last use of adminAPI to Service way --- .../src/Controller/AuthenticateController.ts | 4 +-- pusher/src/Controller/IoSocketController.ts | 2 +- pusher/src/Controller/MapController.ts | 2 +- pusher/src/Services/AdminApi.ts | 10 +++--- pusher/src/Services/AdminInterface.ts | 36 ++++++------------- pusher/src/Services/LocalAdmin.ts | 20 +++++------ pusher/src/Services/SocketManager.ts | 2 +- 7 files changed, 29 insertions(+), 47 deletions(-) diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index a91a7e3c..d959d2ea 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -1,6 +1,6 @@ import { v4 } from "uuid"; import { BaseHttpController } from "./BaseHttpController"; -import { adminApi, FetchMemberDataByUuidResponse } from "../Services/AdminApi"; +import { FetchMemberDataByUuidResponse } from "../Services/AdminApi"; import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager"; import { parse } from "query-string"; import { openIDClient } from "../Services/OpenIDClient"; @@ -508,7 +508,7 @@ export class AuthenticateController extends BaseHttpController { userRoomToken: undefined, }; try { - data = await adminApi.fetchMemberDataByUuid(email, playUri, IPAddress, []); + data = await adminService.fetchMemberDataByUuid(email, playUri, IPAddress, []); } catch (err) { console.error("openIDCallback => fetchMemberDataByUuid", err); } diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index a8847d9c..857c82e7 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -40,7 +40,7 @@ import { localWokaService } from "../Services/LocalWokaService"; import { WebSocket } from "uWebSockets.js"; import { WokaDetail } from "../Messages/JsonMessages/PlayerTextures"; import { z } from "zod"; -import {adminService} from "../Services/AdminService"; +import { adminService } from "../Services/AdminService"; /** * The object passed between the "open" and the "upgrade" methods when opening a websocket diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index c56fbb16..cefae661 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -2,7 +2,7 @@ import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable"; import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData"; import { parse } from "query-string"; import { BaseHttpController } from "./BaseHttpController"; -import {adminService} from "../Services/AdminService"; +import { adminService } from "../Services/AdminService"; export class MapController extends BaseHttpController { // Returns a map mapping map name to file name of the map diff --git a/pusher/src/Services/AdminApi.ts b/pusher/src/Services/AdminApi.ts index a4b3ed5f..22e02d0a 100644 --- a/pusher/src/Services/AdminApi.ts +++ b/pusher/src/Services/AdminApi.ts @@ -7,8 +7,8 @@ import { z } from "zod"; import { isWokaDetail } from "../Messages/JsonMessages/PlayerTextures"; import qs from "qs"; import { AdminInterface } from "./AdminInterface"; -import {AuthTokenData, jwtTokenManager} from "./JWTTokenManager"; -import {InvalidTokenError} from "../Controller/InvalidTokenError"; +import { AuthTokenData, jwtTokenManager } from "./JWTTokenManager"; +import { InvalidTokenError } from "../Controller/InvalidTokenError"; export interface AdminBannedData { is_banned: boolean; @@ -46,13 +46,13 @@ class AdminApi implements AdminInterface { console.info("JWT expire, but decoded", userId); } catch (e) { if (e instanceof InvalidTokenError) { - throw new Error('Token decrypted error'); + throw new Error("Token decrypted error"); // The token was not good, redirect user on login page //res.status(401); //res.send("Token decrypted error"); //return; } else { - throw new Error('Error on decryption of token :' + e); + throw new Error("Error on decryption of token :" + e); //this.castErrorToResponse(e, res); //return; } @@ -190,7 +190,7 @@ class AdminApi implements AdminInterface { return `${OPID_PROFILE_SCREEN_PROVIDER}?accessToken=${accessToken}`; } - async logoutOauth(token: string): Promise{ + async logoutOauth(token: string): Promise { await Axios.get(ADMIN_API_URL + `/oauth/logout?token=${token}`); } } diff --git a/pusher/src/Services/AdminInterface.ts b/pusher/src/Services/AdminInterface.ts index 88e01d61..538c49bb 100644 --- a/pusher/src/Services/AdminInterface.ts +++ b/pusher/src/Services/AdminInterface.ts @@ -1,7 +1,7 @@ -import {AdminBannedData, FetchMemberDataByUuidResponse} from "./AdminApi"; -import {MapDetailsData} from "../Messages/JsonMessages/MapDetailsData"; -import {RoomRedirect} from "../Messages/JsonMessages/RoomRedirect"; -import {AdminApiData} from "../Messages/JsonMessages/AdminApiData"; +import { AdminBannedData, FetchMemberDataByUuidResponse } from "./AdminApi"; +import { MapDetailsData } from "../Messages/JsonMessages/MapDetailsData"; +import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect"; +import { AdminApiData } from "../Messages/JsonMessages/AdminApiData"; export interface AdminInterface { locale: string; @@ -25,20 +25,14 @@ export interface AdminInterface { * @var userId: can to be undefined or email or uuid * @return MapDetailsData|RoomRedirect */ - fetchMapDetails( - playUri: string, - authToken?: string - ): Promise; + fetchMapDetails(playUri: string, authToken?: string): Promise; /** * @param organizationMemberToken * @param playUri * @return AdminApiData */ - fetchMemberDataByToken( - organizationMemberToken: string, - playUri: string | null - ): Promise; + fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise; /** * @param reportedUserUuid @@ -59,32 +53,22 @@ export interface AdminInterface { * @param roomUrl * @return AdminBannedData */ - verifyBanUser( - userUuid: string, - ipAddress: string, - roomUrl: string - ): Promise; + verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise; /** * @param roomUrl * @return string[] */ - getUrlRoomsFromSameWorld( - roomUrl: string - ): Promise; + getUrlRoomsFromSameWorld(roomUrl: string): Promise; /** * @param accessToken * @return string */ - getProfileUrl( - accessToken: string - ): string; + getProfileUrl(accessToken: string): string; /** * @param token */ - logoutOauth( - token: string - ): Promise; + logoutOauth(token: string): Promise; } diff --git a/pusher/src/Services/LocalAdmin.ts b/pusher/src/Services/LocalAdmin.ts index 263378b6..7f43f568 100644 --- a/pusher/src/Services/LocalAdmin.ts +++ b/pusher/src/Services/LocalAdmin.ts @@ -1,11 +1,10 @@ -import {AdminBannedData, FetchMemberDataByUuidResponse} from "./AdminApi"; -import {AdminInterface} from "./AdminInterface"; -import {MapDetailsData} from "../Messages/JsonMessages/MapDetailsData"; -import {RoomRedirect} from "../Messages/JsonMessages/RoomRedirect"; -import {GameRoomPolicyTypes} from "../Model/PusherRoom"; -import {ADMIN_API_URL, DISABLE_ANONYMOUS, OPID_PROFILE_SCREEN_PROVIDER} from "../Enum/EnvironmentVariable"; -import {AdminApiData} from "../Messages/JsonMessages/AdminApiData"; -import Axios from "axios"; +import { AdminBannedData, FetchMemberDataByUuidResponse } from "./AdminApi"; +import { AdminInterface } from "./AdminInterface"; +import { MapDetailsData } from "../Messages/JsonMessages/MapDetailsData"; +import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect"; +import { GameRoomPolicyTypes } from "../Model/PusherRoom"; +import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable"; +import { AdminApiData } from "../Messages/JsonMessages/AdminApiData"; /** * A local class mocking a real admin if no admin is configured. @@ -38,7 +37,6 @@ class LocalAdmin implements AdminInterface { // eslint-disable-next-line @typescript-eslint/no-unused-vars authToken?: string ): Promise { - const roomUrl = new URL(playUri); const match = /\/_\/[^/]+\/(.+)/.exec(roomUrl.pathname); @@ -58,7 +56,7 @@ class LocalAdmin implements AdminInterface { group: null, iframeAuthentication: null, loadingLogo: null, - loginSceneLogo: null + loginSceneLogo: null, }); } @@ -113,7 +111,7 @@ class LocalAdmin implements AdminInterface { async logoutOauth( // eslint-disable-next-line @typescript-eslint/no-unused-vars token: string - ): Promise{ + ): Promise { return Promise.reject(new Error("No admin backoffice set!")); } } diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index f42d6324..b840b994 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -54,7 +54,7 @@ import Debug from "debug"; import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface"; import { compressors } from "hyper-express"; import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData"; -import {adminService} from "./AdminService"; +import { adminService } from "./AdminService"; const debug = Debug("socket");