Fix prettier issues and re order locale parameter
This commit is contained in:
parent
55cb6577b4
commit
8182ccb11c
@ -169,11 +169,11 @@ export class AuthenticateController extends BaseHttpController {
|
||||
//Get user data from Admin Back Office
|
||||
//This is very important to create User Local in LocalStorage in WorkAdventure
|
||||
const resUserData = await adminService.fetchMemberDataByUuid(
|
||||
req.header("accept-language"),
|
||||
authTokenData.identifier,
|
||||
playUri as string,
|
||||
IPAddress,
|
||||
[]
|
||||
[],
|
||||
req.header("accept-language")
|
||||
);
|
||||
|
||||
if (authTokenData.accessToken == undefined) {
|
||||
@ -225,7 +225,13 @@ export class AuthenticateController extends BaseHttpController {
|
||||
|
||||
//Get user data from Admin Back Office
|
||||
//This is very important to create User Local in LocalStorage in WorkAdventure
|
||||
const data = await adminService.fetchMemberDataByUuid(req.header("accept-language"), email, playUri as string, IPAddress, []);
|
||||
const data = await adminService.fetchMemberDataByUuid(
|
||||
email,
|
||||
playUri as string,
|
||||
IPAddress,
|
||||
[],
|
||||
req.header("accept-language")
|
||||
);
|
||||
|
||||
return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale });
|
||||
} catch (e) {
|
||||
@ -328,7 +334,11 @@ export class AuthenticateController extends BaseHttpController {
|
||||
|
||||
try {
|
||||
if (typeof organizationMemberToken != "string") throw new Error("No organization token");
|
||||
const data = await adminService.fetchMemberDataByToken(req.header("accept-language"), organizationMemberToken, playUri);
|
||||
const data = await adminService.fetchMemberDataByToken(
|
||||
organizationMemberToken,
|
||||
playUri,
|
||||
req.header("accept-language")
|
||||
);
|
||||
const userUuid = data.userUuid;
|
||||
const email = data.email;
|
||||
const roomUrl = data.roomUrl;
|
||||
@ -506,7 +516,7 @@ export class AuthenticateController extends BaseHttpController {
|
||||
userRoomToken: undefined,
|
||||
};
|
||||
try {
|
||||
data = await adminService.fetchMemberDataByUuid("en", email, playUri, IPAddress, []);
|
||||
data = await adminService.fetchMemberDataByUuid(email, playUri, IPAddress, []);
|
||||
} catch (err) {
|
||||
console.error("openIDCallback => fetchMemberDataByUuid", err);
|
||||
}
|
||||
|
@ -107,7 +107,11 @@ export class MapController extends BaseHttpController {
|
||||
(async () => {
|
||||
try {
|
||||
const mapDetails = isMapDetailsData.parse(
|
||||
await adminService.fetchMapDetails(req.header("accept-language"), query.playUri as string, query.authToken as string)
|
||||
await adminService.fetchMapDetails(
|
||||
req.header("accept-language"),
|
||||
query.playUri as string,
|
||||
query.authToken as string
|
||||
)
|
||||
);
|
||||
|
||||
if (DISABLE_ANONYMOUS) mapDetails.authenticationMandatory = true;
|
||||
|
@ -29,7 +29,11 @@ export const isFetchMemberDataByUuidResponse = z.object({
|
||||
export type FetchMemberDataByUuidResponse = z.infer<typeof isFetchMemberDataByUuidResponse>;
|
||||
|
||||
class AdminApi implements AdminInterface {
|
||||
async fetchMapDetails(locale: string, playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect> {
|
||||
async fetchMapDetails(
|
||||
playUri: string,
|
||||
authToken?: string,
|
||||
locale?: string
|
||||
): Promise<MapDetailsData | RoomRedirect> {
|
||||
let userId: string | undefined = undefined;
|
||||
if (authToken != undefined) {
|
||||
let authTokenData: AuthTokenData;
|
||||
@ -64,7 +68,7 @@ class AdminApi implements AdminInterface {
|
||||
};
|
||||
|
||||
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/map", {
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" },
|
||||
params,
|
||||
});
|
||||
|
||||
@ -87,11 +91,11 @@ class AdminApi implements AdminInterface {
|
||||
}
|
||||
|
||||
async fetchMemberDataByUuid(
|
||||
locale: string,
|
||||
userIdentifier: string,
|
||||
playUri: string,
|
||||
ipAddress: string,
|
||||
characterLayers: string[]
|
||||
characterLayers: string[],
|
||||
locale?: string
|
||||
): Promise<FetchMemberDataByUuidResponse> {
|
||||
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/room/access", {
|
||||
params: {
|
||||
@ -100,7 +104,7 @@ class AdminApi implements AdminInterface {
|
||||
ipAddress,
|
||||
characterLayers,
|
||||
},
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" },
|
||||
paramsSerializer: (p) => {
|
||||
return qs.stringify(p, { arrayFormat: "brackets" });
|
||||
},
|
||||
@ -119,11 +123,15 @@ class AdminApi implements AdminInterface {
|
||||
);
|
||||
}
|
||||
|
||||
async fetchMemberDataByToken(locale: string, organizationMemberToken: string, playUri: string | null): Promise<AdminApiData> {
|
||||
async fetchMemberDataByToken(
|
||||
organizationMemberToken: string,
|
||||
playUri: string | null,
|
||||
locale?: string
|
||||
): Promise<AdminApiData> {
|
||||
//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, {
|
||||
params: { playUri },
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" },
|
||||
});
|
||||
|
||||
const adminApiData = isAdminApiData.safeParse(res.data);
|
||||
@ -138,11 +146,11 @@ class AdminApi implements AdminInterface {
|
||||
}
|
||||
|
||||
reportPlayer(
|
||||
locale: string,
|
||||
reportedUserUuid: string,
|
||||
reportedUserComment: string,
|
||||
reporterUserUuid: string,
|
||||
reportWorldSlug: string
|
||||
reportWorldSlug: string,
|
||||
locale?: string
|
||||
) {
|
||||
return Axios.post(
|
||||
`${ADMIN_API_URL}/api/report`,
|
||||
@ -153,12 +161,17 @@ class AdminApi implements AdminInterface {
|
||||
reportWorldSlug,
|
||||
},
|
||||
{
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" },
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async verifyBanUser(locale: string, userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData> {
|
||||
async verifyBanUser(
|
||||
userUuid: string,
|
||||
ipAddress: string,
|
||||
roomUrl: string,
|
||||
locale?: string
|
||||
): Promise<AdminBannedData> {
|
||||
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
||||
return Axios.get(
|
||||
ADMIN_API_URL +
|
||||
@ -169,15 +182,15 @@ class AdminApi implements AdminInterface {
|
||||
encodeURIComponent(userUuid) +
|
||||
"&roomUrl=" +
|
||||
encodeURIComponent(roomUrl),
|
||||
{ headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale } }
|
||||
{ headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" } }
|
||||
).then((data) => {
|
||||
return data.data;
|
||||
});
|
||||
}
|
||||
|
||||
async getUrlRoomsFromSameWorld(locale: string, roomUrl: string): Promise<string[]> {
|
||||
async getUrlRoomsFromSameWorld(roomUrl: string, locale?: string): Promise<string[]> {
|
||||
return Axios.get(ADMIN_API_URL + "/api/room/sameWorld" + "?roomUrl=" + encodeURIComponent(roomUrl), {
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale },
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" },
|
||||
}).then((data) => {
|
||||
return data.data;
|
||||
});
|
||||
|
@ -4,7 +4,6 @@ import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
||||
import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
||||
|
||||
export interface AdminInterface {
|
||||
|
||||
/**
|
||||
* @var playUri: is url of the room
|
||||
* @var userIdentifier: can to be undefined or email or uuid
|
||||
@ -13,11 +12,11 @@ export interface AdminInterface {
|
||||
* @return MapDetailsData|RoomRedirect
|
||||
*/
|
||||
fetchMemberDataByUuid(
|
||||
locale: string,
|
||||
userIdentifier: string,
|
||||
playUri: string,
|
||||
ipAddress: string,
|
||||
characterLayers: string[]
|
||||
characterLayers: string[],
|
||||
locale?: string
|
||||
): Promise<FetchMemberDataByUuidResponse>;
|
||||
|
||||
/**
|
||||
@ -25,7 +24,7 @@ export interface AdminInterface {
|
||||
* @var userId: can to be undefined or email or uuid
|
||||
* @return MapDetailsData|RoomRedirect
|
||||
*/
|
||||
fetchMapDetails(locale: string, playUri: string, authToken?: string): Promise<MapDetailsData | RoomRedirect>;
|
||||
fetchMapDetails(playUri: string, authToken?: string, locale?: string): Promise<MapDetailsData | RoomRedirect>;
|
||||
|
||||
/**
|
||||
* @param locale
|
||||
@ -33,7 +32,11 @@ export interface AdminInterface {
|
||||
* @param playUri
|
||||
* @return AdminApiData
|
||||
*/
|
||||
fetchMemberDataByToken(locale: string, organizationMemberToken: string, playUri: string | null): Promise<AdminApiData>;
|
||||
fetchMemberDataByToken(
|
||||
organizationMemberToken: string,
|
||||
playUri: string | null,
|
||||
locale?: string
|
||||
): Promise<AdminApiData>;
|
||||
|
||||
/**
|
||||
* @param locale
|
||||
@ -43,11 +46,11 @@ export interface AdminInterface {
|
||||
* @param reportWorldSlug
|
||||
*/
|
||||
reportPlayer(
|
||||
locale: string,
|
||||
reportedUserUuid: string,
|
||||
reportedUserComment: string,
|
||||
reporterUserUuid: string,
|
||||
reportWorldSlug: string
|
||||
reportWorldSlug: string,
|
||||
locale?: string
|
||||
): Promise<unknown>;
|
||||
|
||||
/**
|
||||
@ -57,14 +60,14 @@ export interface AdminInterface {
|
||||
* @param roomUrl
|
||||
* @return AdminBannedData
|
||||
*/
|
||||
verifyBanUser(locale: string, userUuid: string, ipAddress: string, roomUrl: string): Promise<AdminBannedData>;
|
||||
verifyBanUser(userUuid: string, ipAddress: string, roomUrl: string, locale?: string): Promise<AdminBannedData>;
|
||||
|
||||
/**
|
||||
* @param locale
|
||||
* @param roomUrl
|
||||
* @return string[]
|
||||
*/
|
||||
getUrlRoomsFromSameWorld(locale: string, roomUrl: string): Promise<string[]>;
|
||||
getUrlRoomsFromSameWorld(roomUrl: string, locale?: string): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* @param accessToken
|
||||
|
@ -10,17 +10,16 @@ import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
||||
* A local class mocking a real admin if no admin is configured.
|
||||
*/
|
||||
class LocalAdmin implements AdminInterface {
|
||||
|
||||
fetchMemberDataByUuid(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale: string,
|
||||
userIdentifier: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
playUri: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
ipAddress: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
characterLayers: string[]
|
||||
characterLayers: string[],
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale?: string
|
||||
): Promise<FetchMemberDataByUuidResponse> {
|
||||
return Promise.resolve({
|
||||
email: userIdentifier,
|
||||
@ -34,11 +33,11 @@ class LocalAdmin implements AdminInterface {
|
||||
}
|
||||
|
||||
fetchMapDetails(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale: string,
|
||||
playUri: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
authToken?: string
|
||||
authToken?: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale?: string
|
||||
): Promise<MapDetailsData | RoomRedirect> {
|
||||
const roomUrl = new URL(playUri);
|
||||
|
||||
@ -64,19 +63,17 @@ class LocalAdmin implements AdminInterface {
|
||||
}
|
||||
|
||||
async fetchMemberDataByToken(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
organizationMemberToken: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
playUri: string | null
|
||||
playUri: string | null,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale?: string
|
||||
): Promise<AdminApiData> {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
reportPlayer(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
reportedUserUuid: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@ -84,29 +81,31 @@ class LocalAdmin implements AdminInterface {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
reporterUserUuid: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
reportWorldSlug: string
|
||||
reportWorldSlug: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale?: string
|
||||
) {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
async verifyBanUser(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale: string,
|
||||
// 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
|
||||
roomUrl: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale?: string
|
||||
): Promise<AdminBannedData> {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
||||
async getUrlRoomsFromSameWorld(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
locale: string,
|
||||
roomUrl: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
roomUrl: string
|
||||
locale?: string
|
||||
): Promise<string[]> {
|
||||
return Promise.reject(new Error("No admin backoffice set!"));
|
||||
}
|
||||
|
@ -125,10 +125,10 @@ export class SocketManager implements ZoneEventListener {
|
||||
.on("end", () => {
|
||||
console.warn(
|
||||
"Admin connection lost to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
roomId +
|
||||
"'"
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
roomId +
|
||||
"'"
|
||||
);
|
||||
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
||||
if (!client.disconnecting) {
|
||||
@ -139,10 +139,10 @@ export class SocketManager implements ZoneEventListener {
|
||||
.on("error", (err: Error) => {
|
||||
console.error(
|
||||
"Error in connection to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
roomId +
|
||||
"':",
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
roomId +
|
||||
"':",
|
||||
err
|
||||
);
|
||||
if (!client.disconnecting) {
|
||||
@ -231,10 +231,10 @@ export class SocketManager implements ZoneEventListener {
|
||||
.on("end", () => {
|
||||
console.warn(
|
||||
"Connection lost to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
client.roomId +
|
||||
"'"
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
client.roomId +
|
||||
"'"
|
||||
);
|
||||
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
||||
if (!client.disconnecting) {
|
||||
@ -245,10 +245,10 @@ export class SocketManager implements ZoneEventListener {
|
||||
.on("error", (err: Error) => {
|
||||
console.error(
|
||||
"Error in connection to back server '" +
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
client.roomId +
|
||||
"':",
|
||||
apiClient.getChannel().getTarget() +
|
||||
"' for room '" +
|
||||
client.roomId +
|
||||
"':",
|
||||
err
|
||||
);
|
||||
if (!client.disconnecting) {
|
||||
|
Loading…
Reference in New Issue
Block a user