Fix prettier and change last use of adminAPI to Service way

This commit is contained in:
CEC 2022-04-14 11:59:35 +02:00
parent 3767555e38
commit 0ac6b50469
7 changed files with 29 additions and 47 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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<void>{
async logoutOauth(token: string): Promise<void> {
await Axios.get(ADMIN_API_URL + `/oauth/logout?token=${token}`);
}
}

View File

@ -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<MapDetailsData | RoomRedirect>;
fetchMapDetails(playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect>;
/**
* @param organizationMemberToken
* @param playUri
* @return AdminApiData
*/
fetchMemberDataByToken(
organizationMemberToken: string,
playUri: string | null
): Promise<AdminApiData>;
fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData>;
/**
* @param reportedUserUuid
@ -59,32 +53,22 @@ export interface AdminInterface {
* @param roomUrl
* @return AdminBannedData
*/
verifyBanUser(
userUuid: string,
ipAddress: string,
roomUrl: string
): Promise<AdminBannedData>;
verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData>;
/**
* @param roomUrl
* @return string[]
*/
getUrlRoomsFromSameWorld(
roomUrl: string
): Promise<string[]>;
getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]>;
/**
* @param accessToken
* @return string
*/
getProfileUrl(
accessToken: string
): string;
getProfileUrl(accessToken: string): string;
/**
* @param token
*/
logoutOauth(
token: string
): Promise<void>;
logoutOauth(token: string): Promise<void>;
}

View File

@ -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<MapDetailsData | RoomRedirect> {
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<void>{
): Promise<void> {
return Promise.reject(new Error("No admin backoffice set!"));
}
}

View File

@ -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");