Implement all use of AdminService
Implement and generalize adminApi and localAdmin from adminInterface
This commit is contained in:
parent
5507a91d48
commit
317e0d3787
@ -1,6 +1,5 @@
|
|||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
import { BaseHttpController } from "./BaseHttpController";
|
import { BaseHttpController } from "./BaseHttpController";
|
||||||
import { adminApi } from "../Services/AdminApi";
|
|
||||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||||
import { parse } from "query-string";
|
import { parse } from "query-string";
|
||||||
import { openIDClient } from "../Services/OpenIDClient";
|
import { openIDClient } from "../Services/OpenIDClient";
|
||||||
@ -320,7 +319,7 @@ export class AuthenticateController extends BaseHttpController {
|
|||||||
(async () => {
|
(async () => {
|
||||||
const param = await req.json();
|
const param = await req.json();
|
||||||
|
|
||||||
adminApi.setLocale(req.header("accept-language"));
|
adminService.locale = req.header("accept-language");
|
||||||
|
|
||||||
//todo: what to do if the organizationMemberToken is already used?
|
//todo: what to do if the organizationMemberToken is already used?
|
||||||
const organizationMemberToken: string | null = param.organizationMemberToken;
|
const organizationMemberToken: string | null = param.organizationMemberToken;
|
||||||
@ -328,13 +327,15 @@ export class AuthenticateController extends BaseHttpController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (typeof organizationMemberToken != "string") throw new Error("No organization token");
|
if (typeof organizationMemberToken != "string") throw new Error("No organization token");
|
||||||
const data = await adminApi.fetchMemberDataByToken(organizationMemberToken, playUri);
|
const data = await adminService.fetchMemberDataByToken(organizationMemberToken, playUri);
|
||||||
const userUuid = data.userUuid;
|
const userUuid = data.userUuid;
|
||||||
const email = data.email;
|
const email = data.email;
|
||||||
const roomUrl = data.roomUrl;
|
const roomUrl = data.roomUrl;
|
||||||
const mapUrlStart = data.mapUrlStart;
|
const mapUrlStart = data.mapUrlStart;
|
||||||
|
|
||||||
const authToken = jwtTokenManager.createAuthToken(email || userUuid);
|
const authToken = jwtTokenManager.createAuthToken(email || userUuid);
|
||||||
|
|
||||||
|
console.info(data);
|
||||||
res.json({
|
res.json({
|
||||||
authToken,
|
authToken,
|
||||||
userUuid,
|
userUuid,
|
||||||
@ -420,7 +421,7 @@ export class AuthenticateController extends BaseHttpController {
|
|||||||
|
|
||||||
//get login profile
|
//get login profile
|
||||||
res.status(302);
|
res.status(302);
|
||||||
res.setHeader("Location", adminApi.getProfileUrl(authTokenData.accessToken));
|
res.setHeader("Location", adminService.getProfileUrl(authTokenData.accessToken));
|
||||||
res.send("");
|
res.send("");
|
||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -26,7 +26,7 @@ import {
|
|||||||
import { UserMovesMessage } from "../Messages/generated/messages_pb";
|
import { UserMovesMessage } from "../Messages/generated/messages_pb";
|
||||||
import { parse } from "query-string";
|
import { parse } from "query-string";
|
||||||
import { AdminSocketTokenData, jwtTokenManager, tokenInvalidException } from "../Services/JWTTokenManager";
|
import { AdminSocketTokenData, jwtTokenManager, tokenInvalidException } from "../Services/JWTTokenManager";
|
||||||
import { adminApi, FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
import { FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
||||||
import { socketManager } from "../Services/SocketManager";
|
import { socketManager } from "../Services/SocketManager";
|
||||||
import { emitInBatch } from "../Services/IoSocketHelpers";
|
import { emitInBatch } from "../Services/IoSocketHelpers";
|
||||||
import { ADMIN_API_URL, ADMIN_SOCKETS_TOKEN, DISABLE_ANONYMOUS, SOCKET_IDLE_TIMER } from "../Enum/EnvironmentVariable";
|
import { ADMIN_API_URL, ADMIN_SOCKETS_TOKEN, DISABLE_ANONYMOUS, SOCKET_IDLE_TIMER } from "../Enum/EnvironmentVariable";
|
||||||
@ -40,6 +40,7 @@ import { localWokaService } from "../Services/LocalWokaService";
|
|||||||
import { WebSocket } from "uWebSockets.js";
|
import { WebSocket } from "uWebSockets.js";
|
||||||
import { WokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
import { WokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import {adminService} from "../Services/AdminService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object passed between the "open" and the "upgrade" methods when opening a websocket
|
* The object passed between the "open" and the "upgrade" methods when opening a websocket
|
||||||
@ -236,7 +237,7 @@ export class IoSocketController {
|
|||||||
const websocketExtensions = req.getHeader("sec-websocket-extensions");
|
const websocketExtensions = req.getHeader("sec-websocket-extensions");
|
||||||
const IPAddress = req.getHeader("x-forwarded-for");
|
const IPAddress = req.getHeader("x-forwarded-for");
|
||||||
|
|
||||||
adminApi.setLocale(req.getHeader("accept-language"));
|
adminService.locale = req.getHeader("accept-language");
|
||||||
|
|
||||||
const roomId = query.roomId;
|
const roomId = query.roomId;
|
||||||
try {
|
try {
|
||||||
@ -305,7 +306,7 @@ export class IoSocketController {
|
|||||||
if (ADMIN_API_URL) {
|
if (ADMIN_API_URL) {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
userData = await adminApi.fetchMemberDataByUuid(
|
userData = await adminService.fetchMemberDataByUuid(
|
||||||
userIdentifier,
|
userIdentifier,
|
||||||
roomId,
|
roomId,
|
||||||
IPAddress,
|
IPAddress,
|
||||||
@ -328,9 +329,9 @@ export class IoSocketController {
|
|||||||
{
|
{
|
||||||
rejected: true,
|
rejected: true,
|
||||||
reason: "error",
|
reason: "error",
|
||||||
message: err?.response?.data.code,
|
message: err.response.data.code,
|
||||||
status: err?.response?.status,
|
status: err.response.status,
|
||||||
error: err?.response?.data,
|
error: err.response.data,
|
||||||
roomId,
|
roomId,
|
||||||
} as UpgradeFailedData,
|
} as UpgradeFailedData,
|
||||||
websocketKey,
|
websocketKey,
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
import { adminApi } from "../Services/AdminApi";
|
import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
||||||
import { ADMIN_API_URL, DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
|
||||||
import { isMapDetailsData, MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
|
||||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
|
||||||
import { InvalidTokenError } from "./InvalidTokenError";
|
|
||||||
import { parse } from "query-string";
|
import { parse } from "query-string";
|
||||||
import { BaseHttpController } from "./BaseHttpController";
|
import { BaseHttpController } from "./BaseHttpController";
|
||||||
|
import {adminService} from "../Services/AdminService";
|
||||||
|
|
||||||
export class MapController extends BaseHttpController {
|
export class MapController extends BaseHttpController {
|
||||||
// Returns a map mapping map name to file name of the map
|
// Returns a map mapping map name to file name of the map
|
||||||
@ -107,68 +104,15 @@ export class MapController extends BaseHttpController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
adminApi.setLocale(req.header("accept-language"));
|
adminService.locale = req.header("accept-language");
|
||||||
|
|
||||||
// If no admin URL is set, let's react on '/_/[instance]/[map url]' URLs
|
|
||||||
if (!ADMIN_API_URL) {
|
|
||||||
const roomUrl = new URL(query.playUri);
|
|
||||||
|
|
||||||
const match = /\/_\/[^/]+\/(.+)/.exec(roomUrl.pathname);
|
|
||||||
if (!match) {
|
|
||||||
res.status(404);
|
|
||||||
res.json({});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapUrl = roomUrl.protocol + "//" + match[1];
|
|
||||||
|
|
||||||
res.json({
|
|
||||||
mapUrl,
|
|
||||||
policy_type: GameRoomPolicyTypes.ANONYMOUS_POLICY,
|
|
||||||
roomSlug: null, // Deprecated
|
|
||||||
group: null,
|
|
||||||
tags: [],
|
|
||||||
contactPage: null,
|
|
||||||
authenticationMandatory: DISABLE_ANONYMOUS,
|
|
||||||
} as MapDetailsData);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
let userId: string | undefined = undefined;
|
|
||||||
if (query.authToken != undefined) {
|
|
||||||
let authTokenData: AuthTokenData;
|
|
||||||
try {
|
|
||||||
authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string);
|
|
||||||
userId = authTokenData.identifier;
|
|
||||||
} catch (e) {
|
|
||||||
try {
|
|
||||||
// Decode token, in this case we don't need to create new token.
|
|
||||||
authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string, true);
|
|
||||||
userId = authTokenData.identifier;
|
|
||||||
console.info("JWT expire, but decoded", userId);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof InvalidTokenError) {
|
|
||||||
// The token was not good, redirect user on login page
|
|
||||||
res.status(401);
|
|
||||||
res.send("Token decrypted error");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
this.castErrorToResponse(e, res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const mapDetails = isMapDetailsData.parse(
|
const mapDetails = isMapDetailsData.parse(
|
||||||
await adminApi.fetchMapDetails(query.playUri as string, userId)
|
await adminService.fetchMapDetails(query.playUri as string, query.authToken as string)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DISABLE_ANONYMOUS) {
|
if (DISABLE_ANONYMOUS) mapDetails.authenticationMandatory = true;
|
||||||
mapDetails.authenticationMandatory = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json(mapDetails);
|
res.json(mapDetails);
|
||||||
return;
|
return;
|
||||||
|
@ -7,6 +7,8 @@ import { z } from "zod";
|
|||||||
import { isWokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
import { isWokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
import { AdminInterface } from "./AdminInterface";
|
import { AdminInterface } from "./AdminInterface";
|
||||||
|
import {AuthTokenData, jwtTokenManager} from "./JWTTokenManager";
|
||||||
|
import {InvalidTokenError} from "../Controller/InvalidTokenError";
|
||||||
|
|
||||||
export interface AdminBannedData {
|
export interface AdminBannedData {
|
||||||
is_banned: boolean;
|
is_banned: boolean;
|
||||||
@ -27,19 +29,35 @@ export const isFetchMemberDataByUuidResponse = z.object({
|
|||||||
export type FetchMemberDataByUuidResponse = z.infer<typeof isFetchMemberDataByUuidResponse>;
|
export type FetchMemberDataByUuidResponse = z.infer<typeof isFetchMemberDataByUuidResponse>;
|
||||||
|
|
||||||
class AdminApi implements AdminInterface {
|
class AdminApi implements AdminInterface {
|
||||||
private locale: string = "en";
|
locale: string = "en";
|
||||||
setLocale(locale: string) {
|
|
||||||
console.info("PUSHER LOCALE SET TO :", locale);
|
async fetchMapDetails(playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect> {
|
||||||
this.locale = locale;
|
let userId: string | undefined = undefined;
|
||||||
}
|
if (authToken != undefined) {
|
||||||
/**
|
let authTokenData: AuthTokenData;
|
||||||
* @var playUri: is url of the room
|
try {
|
||||||
* @var userId: can to be undefined or email or uuid
|
authTokenData = jwtTokenManager.verifyJWTToken(authToken);
|
||||||
* @return MapDetailsData|RoomRedirect
|
userId = authTokenData.identifier;
|
||||||
*/
|
} catch (e) {
|
||||||
async fetchMapDetails(playUri: string, userId?: string): Promise<MapDetailsData | RoomRedirect> {
|
try {
|
||||||
if (!ADMIN_API_URL) {
|
// Decode token, in this case we don't need to create new token.
|
||||||
return Promise.reject(new Error("No admin backoffice set!"));
|
authTokenData = jwtTokenManager.verifyJWTToken(authToken, true);
|
||||||
|
userId = authTokenData.identifier;
|
||||||
|
console.info("JWT expire, but decoded", userId);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof InvalidTokenError) {
|
||||||
|
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);
|
||||||
|
//this.castErrorToResponse(e, res);
|
||||||
|
//return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const params: { playUri: string; userId?: string } = {
|
const params: { playUri: string; userId?: string } = {
|
||||||
@ -76,9 +94,6 @@ class AdminApi implements AdminInterface {
|
|||||||
ipAddress: string,
|
ipAddress: string,
|
||||||
characterLayers: string[]
|
characterLayers: string[]
|
||||||
): Promise<FetchMemberDataByUuidResponse> {
|
): Promise<FetchMemberDataByUuidResponse> {
|
||||||
if (!ADMIN_API_URL) {
|
|
||||||
return Promise.reject(new Error("No admin backoffice set!"));
|
|
||||||
}
|
|
||||||
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/room/access", {
|
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/room/access", {
|
||||||
params: {
|
params: {
|
||||||
userIdentifier,
|
userIdentifier,
|
||||||
@ -106,9 +121,6 @@ class AdminApi implements AdminInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData> {
|
async fetchMemberDataByToken(organizationMemberToken: string, playUri: string | null): Promise<AdminApiData> {
|
||||||
if (!ADMIN_API_URL) {
|
|
||||||
return Promise.reject(new Error("No admin backoffice set!"));
|
|
||||||
}
|
|
||||||
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
||||||
const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, {
|
const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, {
|
||||||
params: { playUri },
|
params: { playUri },
|
||||||
@ -132,9 +144,6 @@ class AdminApi implements AdminInterface {
|
|||||||
reporterUserUuid: string,
|
reporterUserUuid: string,
|
||||||
reportWorldSlug: string
|
reportWorldSlug: string
|
||||||
) {
|
) {
|
||||||
if (!ADMIN_API_URL) {
|
|
||||||
return Promise.reject(new Error("No admin backoffice set!"));
|
|
||||||
}
|
|
||||||
return Axios.post(
|
return Axios.post(
|
||||||
`${ADMIN_API_URL}/api/report`,
|
`${ADMIN_API_URL}/api/report`,
|
||||||
{
|
{
|
||||||
@ -150,9 +159,6 @@ class AdminApi implements AdminInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData> {
|
async verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData> {
|
||||||
if (!ADMIN_API_URL) {
|
|
||||||
return Promise.reject(new Error("No admin backoffice set!"));
|
|
||||||
}
|
|
||||||
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
||||||
return Axios.get(
|
return Axios.get(
|
||||||
ADMIN_API_URL +
|
ADMIN_API_URL +
|
||||||
@ -170,10 +176,6 @@ class AdminApi implements AdminInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]> {
|
async getUrlRoomsFromSameWorld(roomUrl: string): Promise<string[]> {
|
||||||
if (!ADMIN_API_URL) {
|
|
||||||
return Promise.reject(new Error("No admin backoffice set!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), {
|
return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), {
|
||||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale },
|
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": this.locale },
|
||||||
}).then((data) => {
|
}).then((data) => {
|
||||||
@ -181,10 +183,6 @@ class AdminApi implements AdminInterface {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param accessToken
|
|
||||||
*/
|
|
||||||
getProfileUrl(accessToken: string): string {
|
getProfileUrl(accessToken: string): string {
|
||||||
if (!OPID_PROFILE_SCREEN_PROVIDER) {
|
if (!OPID_PROFILE_SCREEN_PROVIDER) {
|
||||||
throw new Error("No admin backoffice set!");
|
throw new Error("No admin backoffice set!");
|
||||||
@ -192,7 +190,7 @@ class AdminApi implements AdminInterface {
|
|||||||
return `${OPID_PROFILE_SCREEN_PROVIDER}?accessToken=${accessToken}`;
|
return `${OPID_PROFILE_SCREEN_PROVIDER}?accessToken=${accessToken}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async logoutOauth(token: string) {
|
async logoutOauth(token: string): Promise<void>{
|
||||||
await Axios.get(ADMIN_API_URL + `/oauth/logout?token=${token}`);
|
await Axios.get(ADMIN_API_URL + `/oauth/logout?token=${token}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,90 @@
|
|||||||
import { FetchMemberDataByUuidResponse } from "./AdminApi";
|
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 {
|
export interface AdminInterface {
|
||||||
|
locale: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var playUri: is url of the room
|
||||||
|
* @var userIdentifier: can to be undefined or email or uuid
|
||||||
|
* @var ipAddress
|
||||||
|
* @var characterLayers
|
||||||
|
* @return MapDetailsData|RoomRedirect
|
||||||
|
*/
|
||||||
fetchMemberDataByUuid(
|
fetchMemberDataByUuid(
|
||||||
userIdentifier: string,
|
userIdentifier: string,
|
||||||
playUri: string,
|
playUri: string,
|
||||||
ipAddress: string,
|
ipAddress: string,
|
||||||
characterLayers: string[]
|
characterLayers: string[]
|
||||||
): Promise<FetchMemberDataByUuidResponse>;
|
): Promise<FetchMemberDataByUuidResponse>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var playUri: is url of the room
|
||||||
|
* @var userId: can to be undefined or email or uuid
|
||||||
|
* @return MapDetailsData|RoomRedirect
|
||||||
|
*/
|
||||||
|
fetchMapDetails(
|
||||||
|
playUri: string,
|
||||||
|
authToken?: string
|
||||||
|
): Promise<MapDetailsData | RoomRedirect>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param organizationMemberToken
|
||||||
|
* @param playUri
|
||||||
|
* @return AdminApiData
|
||||||
|
*/
|
||||||
|
fetchMemberDataByToken(
|
||||||
|
organizationMemberToken: string,
|
||||||
|
playUri: string | null
|
||||||
|
): Promise<AdminApiData>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param reportedUserUuid
|
||||||
|
* @param reportedUserComment
|
||||||
|
* @param reporterUserUuid
|
||||||
|
* @param reportWorldSlug
|
||||||
|
*/
|
||||||
|
reportPlayer(
|
||||||
|
reportedUserUuid: string,
|
||||||
|
reportedUserComment: string,
|
||||||
|
reporterUserUuid: string,
|
||||||
|
reportWorldSlug: string
|
||||||
|
): Promise<unknown>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param userUuid
|
||||||
|
* @param ipAddress
|
||||||
|
* @param roomUrl
|
||||||
|
* @return AdminBannedData
|
||||||
|
*/
|
||||||
|
verifyBanUser(
|
||||||
|
userUuid: string,
|
||||||
|
ipAddress: string,
|
||||||
|
roomUrl: string
|
||||||
|
): Promise<AdminBannedData>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param roomUrl
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
getUrlRoomsFromSameWorld(
|
||||||
|
roomUrl: string
|
||||||
|
): Promise<string[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param accessToken
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
getProfileUrl(
|
||||||
|
accessToken: string
|
||||||
|
): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param token
|
||||||
|
*/
|
||||||
|
logoutOauth(
|
||||||
|
token: string
|
||||||
|
): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import {FetchMemberDataByUuidResponse} from "./AdminApi";
|
import {AdminBannedData, FetchMemberDataByUuidResponse} from "./AdminApi";
|
||||||
import {AdminInterface} from "./AdminInterface";
|
import {AdminInterface} from "./AdminInterface";
|
||||||
import {MapDetailsData} from "../Messages/JsonMessages/MapDetailsData";
|
import {MapDetailsData} from "../Messages/JsonMessages/MapDetailsData";
|
||||||
import {RoomRedirect} from "../Messages/JsonMessages/RoomRedirect";
|
import {RoomRedirect} from "../Messages/JsonMessages/RoomRedirect";
|
||||||
import {GameRoomPolicyTypes} from "../Model/PusherRoom";
|
import {GameRoomPolicyTypes} from "../Model/PusherRoom";
|
||||||
import {DISABLE_ANONYMOUS} from "../Enum/EnvironmentVariable";
|
import {ADMIN_API_URL, DISABLE_ANONYMOUS, OPID_PROFILE_SCREEN_PROVIDER} from "../Enum/EnvironmentVariable";
|
||||||
|
import {AdminApiData} from "../Messages/JsonMessages/AdminApiData";
|
||||||
|
import Axios from "axios";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A local class mocking a real admin if no admin is configured.
|
* A local class mocking a real admin if no admin is configured.
|
||||||
*/
|
*/
|
||||||
class LocalAdmin implements AdminInterface {
|
class LocalAdmin implements AdminInterface {
|
||||||
|
locale: string = "en";
|
||||||
|
|
||||||
fetchMemberDataByUuid(
|
fetchMemberDataByUuid(
|
||||||
userIdentifier: string,
|
userIdentifier: string,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
@ -32,7 +36,7 @@ class LocalAdmin implements AdminInterface {
|
|||||||
fetchMapDetails(
|
fetchMapDetails(
|
||||||
playUri: string,
|
playUri: string,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
userId?: string
|
authToken?: string
|
||||||
): Promise<MapDetailsData | RoomRedirect> {
|
): Promise<MapDetailsData | RoomRedirect> {
|
||||||
|
|
||||||
const roomUrl = new URL(playUri);
|
const roomUrl = new URL(playUri);
|
||||||
@ -57,6 +61,61 @@ class LocalAdmin implements AdminInterface {
|
|||||||
loginSceneLogo: null
|
loginSceneLogo: null
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fetchMemberDataByToken(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
organizationMemberToken: string,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
playUri: string | null
|
||||||
|
): Promise<AdminApiData> {
|
||||||
|
return Promise.reject(new Error("No admin backoffice set!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
reportPlayer(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
reportedUserUuid: string,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
reportedUserComment: string,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
reporterUserUuid: string,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
reportWorldSlug: string
|
||||||
|
) {
|
||||||
|
return Promise.reject(new Error("No admin backoffice set!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
async verifyBanUser(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
userUuid: string,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
ipAddress: string,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
roomUrl: string
|
||||||
|
): Promise<AdminBannedData> {
|
||||||
|
return Promise.reject(new Error("No admin backoffice set!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUrlRoomsFromSameWorld(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
roomUrl: string
|
||||||
|
): Promise<string[]> {
|
||||||
|
return Promise.reject(new Error("No admin backoffice set!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
getProfileUrl(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
accessToken: string
|
||||||
|
): string {
|
||||||
|
new Error("No admin backoffice set!");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
async logoutOauth(
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
token: string
|
||||||
|
): Promise<void>{
|
||||||
|
return Promise.reject(new Error("No admin backoffice set!"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const localAdmin = new LocalAdmin();
|
export const localAdmin = new LocalAdmin();
|
||||||
|
@ -44,7 +44,6 @@ import {
|
|||||||
} from "../Messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
||||||
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY } from "../Enum/EnvironmentVariable";
|
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY } from "../Enum/EnvironmentVariable";
|
||||||
import { adminApi } from "./AdminApi";
|
|
||||||
import { emitInBatch } from "./IoSocketHelpers";
|
import { emitInBatch } from "./IoSocketHelpers";
|
||||||
import Jwt from "jsonwebtoken";
|
import Jwt from "jsonwebtoken";
|
||||||
import { clientEventsEmitter } from "./ClientEventsEmitter";
|
import { clientEventsEmitter } from "./ClientEventsEmitter";
|
||||||
@ -55,6 +54,7 @@ import Debug from "debug";
|
|||||||
import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface";
|
import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface";
|
||||||
import { compressors } from "hyper-express";
|
import { compressors } from "hyper-express";
|
||||||
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||||
|
import {adminService} from "./AdminService";
|
||||||
|
|
||||||
const debug = Debug("socket");
|
const debug = Debug("socket");
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
|
|
||||||
async handleReportMessage(client: ExSocketInterface, reportPlayerMessage: ReportPlayerMessage) {
|
async handleReportMessage(client: ExSocketInterface, reportPlayerMessage: ReportPlayerMessage) {
|
||||||
try {
|
try {
|
||||||
await adminApi.reportPlayer(
|
await adminService.reportPlayer(
|
||||||
reportPlayerMessage.getReporteduseruuid(),
|
reportPlayerMessage.getReporteduseruuid(),
|
||||||
reportPlayerMessage.getReportcomment(),
|
reportPlayerMessage.getReportcomment(),
|
||||||
client.userUuid,
|
client.userUuid,
|
||||||
@ -444,7 +444,7 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async updateRoomWithAdminData(room: PusherRoom): Promise<void> {
|
public async updateRoomWithAdminData(room: PusherRoom): Promise<void> {
|
||||||
const data = await adminApi.fetchMapDetails(room.roomUrl);
|
const data = await adminService.fetchMapDetails(room.roomUrl);
|
||||||
const mapDetailsData = isMapDetailsData.safeParse(data);
|
const mapDetailsData = isMapDetailsData.safeParse(data);
|
||||||
|
|
||||||
if (mapDetailsData.success) {
|
if (mapDetailsData.success) {
|
||||||
@ -702,7 +702,7 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
let tabUrlRooms: string[];
|
let tabUrlRooms: string[];
|
||||||
|
|
||||||
if (playGlobalMessageEvent.getBroadcasttoworld()) {
|
if (playGlobalMessageEvent.getBroadcasttoworld()) {
|
||||||
tabUrlRooms = await adminApi.getUrlRoomsFromSameWorld(clientRoomUrl);
|
tabUrlRooms = await adminService.getUrlRoomsFromSameWorld(clientRoomUrl);
|
||||||
} else {
|
} else {
|
||||||
tabUrlRooms = [clientRoomUrl];
|
tabUrlRooms = [clientRoomUrl];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user