2021-06-24 10:09:10 +02:00
|
|
|
import { ADMIN_API_TOKEN, ADMIN_API_URL } from "../Enum/EnvironmentVariable";
|
2020-11-13 18:00:22 +01:00
|
|
|
import Axios from "axios";
|
2021-06-24 10:09:10 +02:00
|
|
|
import { GameRoomPolicyTypes } from "_Model/PusherRoom";
|
2020-11-13 18:00:22 +01:00
|
|
|
|
|
|
|
export interface AdminApiData {
|
2021-06-24 10:09:10 +02:00
|
|
|
organizationSlug: string;
|
|
|
|
worldSlug: string;
|
|
|
|
roomSlug: string;
|
|
|
|
mapUrlStart: string;
|
|
|
|
tags: string[];
|
|
|
|
policy_type: number;
|
|
|
|
userUuid: string;
|
|
|
|
messages?: unknown[];
|
|
|
|
textures: CharacterTexture[];
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
2021-04-01 16:43:12 +02:00
|
|
|
export interface MapDetailsData {
|
2021-06-24 10:09:10 +02:00
|
|
|
roomSlug: string;
|
|
|
|
mapUrl: string;
|
|
|
|
policy_type: GameRoomPolicyTypes;
|
|
|
|
tags: string[];
|
2021-04-01 16:43:12 +02:00
|
|
|
}
|
|
|
|
|
2021-01-15 03:19:58 +01:00
|
|
|
export interface AdminBannedData {
|
2021-06-24 10:09:10 +02:00
|
|
|
is_banned: boolean;
|
|
|
|
message: string;
|
2021-01-15 03:19:58 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 18:00:22 +01:00
|
|
|
export interface CharacterTexture {
|
2021-06-24 10:09:10 +02:00
|
|
|
id: number;
|
|
|
|
level: number;
|
|
|
|
url: string;
|
|
|
|
rights: string;
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface FetchMemberDataByUuidResponse {
|
|
|
|
uuid: string;
|
|
|
|
tags: string[];
|
2021-06-24 10:09:10 +02:00
|
|
|
visitCardUrl: string | null;
|
2020-11-13 18:00:22 +01:00
|
|
|
textures: CharacterTexture[];
|
|
|
|
messages: unknown[];
|
2021-03-01 22:32:50 +01:00
|
|
|
anonymous?: boolean;
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class AdminApi {
|
2021-06-24 10:09:10 +02:00
|
|
|
async fetchMapDetails(
|
|
|
|
organizationSlug: string,
|
|
|
|
worldSlug: string,
|
|
|
|
roomSlug: string | undefined
|
|
|
|
): Promise<MapDetailsData> {
|
2020-11-13 18:00:22 +01:00
|
|
|
if (!ADMIN_API_URL) {
|
2021-06-24 10:09:10 +02:00
|
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
const params: { organizationSlug: string; worldSlug: string; roomSlug?: string } = {
|
2020-11-13 18:00:22 +01:00
|
|
|
organizationSlug,
|
2021-06-24 10:09:10 +02:00
|
|
|
worldSlug,
|
2020-11-13 18:00:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (roomSlug) {
|
|
|
|
params.roomSlug = roomSlug;
|
|
|
|
}
|
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
const res = await Axios.get(ADMIN_API_URL + "/api/map", {
|
|
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
|
|
params,
|
|
|
|
});
|
2020-11-13 18:00:22 +01:00
|
|
|
return res.data;
|
|
|
|
}
|
|
|
|
|
2021-03-05 18:25:27 +01:00
|
|
|
async fetchMemberDataByUuid(uuid: string, roomId: string): Promise<FetchMemberDataByUuidResponse> {
|
2020-11-13 18:00:22 +01:00
|
|
|
if (!ADMIN_API_URL) {
|
2021-06-24 10:09:10 +02:00
|
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
2021-06-24 10:09:10 +02:00
|
|
|
const res = await Axios.get(ADMIN_API_URL + "/api/room/access", {
|
|
|
|
params: { uuid, roomId },
|
|
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
|
|
});
|
2021-03-01 22:32:50 +01:00
|
|
|
return res.data;
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async fetchMemberDataByToken(organizationMemberToken: string): Promise<AdminApiData> {
|
|
|
|
if (!ADMIN_API_URL) {
|
2021-06-24 10:09:10 +02:00
|
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
2021-06-24 10:09:10 +02:00
|
|
|
const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, {
|
|
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
|
|
});
|
2020-11-13 18:00:22 +01:00
|
|
|
return res.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
async fetchCheckUserByToken(organizationMemberToken: string): Promise<AdminApiData> {
|
|
|
|
if (!ADMIN_API_URL) {
|
2021-06-24 10:09:10 +02:00
|
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
2021-06-24 10:09:10 +02:00
|
|
|
const res = await Axios.get(ADMIN_API_URL + "/api/check-user/" + organizationMemberToken, {
|
|
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
|
|
});
|
2020-11-13 18:00:22 +01:00
|
|
|
return res.data;
|
|
|
|
}
|
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
reportPlayer(
|
|
|
|
reportedUserUuid: string,
|
|
|
|
reportedUserComment: string,
|
|
|
|
reporterUserUuid: string,
|
|
|
|
reportWorldSlug: string
|
|
|
|
) {
|
|
|
|
return Axios.post(
|
|
|
|
`${ADMIN_API_URL}/api/report`,
|
|
|
|
{
|
2020-11-13 18:00:22 +01:00
|
|
|
reportedUserUuid,
|
|
|
|
reportedUserComment,
|
|
|
|
reporterUserUuid,
|
2021-06-24 10:09:10 +02:00
|
|
|
reportWorldSlug,
|
2020-11-13 18:00:22 +01:00
|
|
|
},
|
|
|
|
{
|
2021-06-24 10:09:10 +02:00
|
|
|
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
|
|
|
}
|
|
|
|
);
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
2021-01-15 03:19:58 +01:00
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
async verifyBanUser(
|
|
|
|
organizationMemberToken: string,
|
|
|
|
ipAddress: string,
|
|
|
|
organization: string,
|
|
|
|
world: string
|
|
|
|
): Promise<AdminBannedData> {
|
2021-01-15 03:19:58 +01:00
|
|
|
if (!ADMIN_API_URL) {
|
2021-06-24 10:09:10 +02:00
|
|
|
return Promise.reject(new Error("No admin backoffice set!"));
|
2021-01-15 03:19:58 +01:00
|
|
|
}
|
|
|
|
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
2021-06-24 10:09:10 +02:00
|
|
|
return Axios.get(
|
|
|
|
ADMIN_API_URL +
|
|
|
|
"/api/check-moderate-user/" +
|
|
|
|
organization +
|
|
|
|
"/" +
|
|
|
|
world +
|
|
|
|
"?ipAddress=" +
|
|
|
|
ipAddress +
|
|
|
|
"&token=" +
|
|
|
|
organizationMemberToken,
|
|
|
|
{ headers: { Authorization: `${ADMIN_API_TOKEN}` } }
|
2021-01-15 03:19:58 +01:00
|
|
|
).then((data) => {
|
|
|
|
return data.data;
|
|
|
|
});
|
|
|
|
}
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const adminApi = new AdminApi();
|