Fix prettier issues and re order locale parameter

This commit is contained in:
CEC 2022-04-20 17:03:21 +02:00
parent 55cb6577b4
commit 8182ccb11c
6 changed files with 92 additions and 63 deletions

View File

@ -169,11 +169,11 @@ export class AuthenticateController extends BaseHttpController {
//Get user data from Admin Back Office //Get user data from Admin Back Office
//This is very important to create User Local in LocalStorage in WorkAdventure //This is very important to create User Local in LocalStorage in WorkAdventure
const resUserData = await adminService.fetchMemberDataByUuid( const resUserData = await adminService.fetchMemberDataByUuid(
req.header("accept-language"),
authTokenData.identifier, authTokenData.identifier,
playUri as string, playUri as string,
IPAddress, IPAddress,
[] [],
req.header("accept-language")
); );
if (authTokenData.accessToken == undefined) { if (authTokenData.accessToken == undefined) {
@ -225,7 +225,13 @@ export class AuthenticateController extends BaseHttpController {
//Get user data from Admin Back Office //Get user data from Admin Back Office
//This is very important to create User Local in LocalStorage in WorkAdventure //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 }); return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale });
} catch (e) { } catch (e) {
@ -328,7 +334,11 @@ 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 adminService.fetchMemberDataByToken(req.header("accept-language"), organizationMemberToken, playUri); const data = await adminService.fetchMemberDataByToken(
organizationMemberToken,
playUri,
req.header("accept-language")
);
const userUuid = data.userUuid; const userUuid = data.userUuid;
const email = data.email; const email = data.email;
const roomUrl = data.roomUrl; const roomUrl = data.roomUrl;
@ -506,7 +516,7 @@ export class AuthenticateController extends BaseHttpController {
userRoomToken: undefined, userRoomToken: undefined,
}; };
try { try {
data = await adminService.fetchMemberDataByUuid("en", email, playUri, IPAddress, []); data = await adminService.fetchMemberDataByUuid(email, playUri, IPAddress, []);
} catch (err) { } catch (err) {
console.error("openIDCallback => fetchMemberDataByUuid", err); console.error("openIDCallback => fetchMemberDataByUuid", err);
} }

View File

@ -107,7 +107,11 @@ export class MapController extends BaseHttpController {
(async () => { (async () => {
try { try {
const mapDetails = isMapDetailsData.parse( 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; if (DISABLE_ANONYMOUS) mapDetails.authenticationMandatory = true;

View File

@ -29,7 +29,11 @@ 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 {
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; let userId: string | undefined = undefined;
if (authToken != undefined) { if (authToken != undefined) {
let authTokenData: AuthTokenData; let authTokenData: AuthTokenData;
@ -64,7 +68,7 @@ class AdminApi implements AdminInterface {
}; };
const res = await Axios.get<unknown, AxiosResponse<unknown>>(ADMIN_API_URL + "/api/map", { 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, params,
}); });
@ -87,11 +91,11 @@ class AdminApi implements AdminInterface {
} }
async fetchMemberDataByUuid( async fetchMemberDataByUuid(
locale: string,
userIdentifier: string, userIdentifier: string,
playUri: string, playUri: string,
ipAddress: string, ipAddress: string,
characterLayers: string[] characterLayers: string[],
locale?: string
): Promise<FetchMemberDataByUuidResponse> { ): Promise<FetchMemberDataByUuidResponse> {
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: {
@ -100,7 +104,7 @@ class AdminApi implements AdminInterface {
ipAddress, ipAddress,
characterLayers, characterLayers,
}, },
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale }, headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" },
paramsSerializer: (p) => { paramsSerializer: (p) => {
return qs.stringify(p, { arrayFormat: "brackets" }); 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. //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 },
headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale }, headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" },
}); });
const adminApiData = isAdminApiData.safeParse(res.data); const adminApiData = isAdminApiData.safeParse(res.data);
@ -138,11 +146,11 @@ class AdminApi implements AdminInterface {
} }
reportPlayer( reportPlayer(
locale: string,
reportedUserUuid: string, reportedUserUuid: string,
reportedUserComment: string, reportedUserComment: string,
reporterUserUuid: string, reporterUserUuid: string,
reportWorldSlug: string reportWorldSlug: string,
locale?: string
) { ) {
return Axios.post( return Axios.post(
`${ADMIN_API_URL}/api/report`, `${ADMIN_API_URL}/api/report`,
@ -153,12 +161,17 @@ class AdminApi implements AdminInterface {
reportWorldSlug, 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. //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 +
@ -169,15 +182,15 @@ class AdminApi implements AdminInterface {
encodeURIComponent(userUuid) + encodeURIComponent(userUuid) +
"&roomUrl=" + "&roomUrl=" +
encodeURIComponent(roomUrl), encodeURIComponent(roomUrl),
{ headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale } } { headers: { Authorization: `${ADMIN_API_TOKEN}`, "Accept-Language": locale ?? "en" } }
).then((data) => { ).then((data) => {
return data.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), { 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) => { }).then((data) => {
return data.data; return data.data;
}); });

View File

@ -4,7 +4,6 @@ import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
import { AdminApiData } from "../Messages/JsonMessages/AdminApiData"; import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
export interface AdminInterface { export interface AdminInterface {
/** /**
* @var playUri: is url of the room * @var playUri: is url of the room
* @var userIdentifier: can to be undefined or email or uuid * @var userIdentifier: can to be undefined or email or uuid
@ -13,11 +12,11 @@ export interface AdminInterface {
* @return MapDetailsData|RoomRedirect * @return MapDetailsData|RoomRedirect
*/ */
fetchMemberDataByUuid( fetchMemberDataByUuid(
locale: string,
userIdentifier: string, userIdentifier: string,
playUri: string, playUri: string,
ipAddress: string, ipAddress: string,
characterLayers: string[] characterLayers: string[],
locale?: string
): Promise<FetchMemberDataByUuidResponse>; ): Promise<FetchMemberDataByUuidResponse>;
/** /**
@ -25,7 +24,7 @@ export interface AdminInterface {
* @var userId: can to be undefined or email or uuid * @var userId: can to be undefined or email or uuid
* @return MapDetailsData|RoomRedirect * @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 * @param locale
@ -33,7 +32,11 @@ export interface AdminInterface {
* @param playUri * @param playUri
* @return AdminApiData * @return AdminApiData
*/ */
fetchMemberDataByToken(locale: string, organizationMemberToken: string, playUri: string | null): Promise<AdminApiData>; fetchMemberDataByToken(
organizationMemberToken: string,
playUri: string | null,
locale?: string
): Promise<AdminApiData>;
/** /**
* @param locale * @param locale
@ -43,11 +46,11 @@ export interface AdminInterface {
* @param reportWorldSlug * @param reportWorldSlug
*/ */
reportPlayer( reportPlayer(
locale: string,
reportedUserUuid: string, reportedUserUuid: string,
reportedUserComment: string, reportedUserComment: string,
reporterUserUuid: string, reporterUserUuid: string,
reportWorldSlug: string reportWorldSlug: string,
locale?: string
): Promise<unknown>; ): Promise<unknown>;
/** /**
@ -57,14 +60,14 @@ export interface AdminInterface {
* @param roomUrl * @param roomUrl
* @return AdminBannedData * @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 locale
* @param roomUrl * @param roomUrl
* @return string[] * @return string[]
*/ */
getUrlRoomsFromSameWorld(locale: string, roomUrl: string): Promise<string[]>; getUrlRoomsFromSameWorld(roomUrl: string, locale?: string): Promise<string[]>;
/** /**
* @param accessToken * @param accessToken

View File

@ -10,17 +10,16 @@ import { AdminApiData } from "../Messages/JsonMessages/AdminApiData";
* 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 {
fetchMemberDataByUuid( fetchMemberDataByUuid(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
userIdentifier: string, userIdentifier: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
playUri: string, playUri: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
ipAddress: string, ipAddress: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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> { ): Promise<FetchMemberDataByUuidResponse> {
return Promise.resolve({ return Promise.resolve({
email: userIdentifier, email: userIdentifier,
@ -34,11 +33,11 @@ class LocalAdmin implements AdminInterface {
} }
fetchMapDetails( fetchMapDetails(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
playUri: string, playUri: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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> { ): Promise<MapDetailsData | RoomRedirect> {
const roomUrl = new URL(playUri); const roomUrl = new URL(playUri);
@ -64,19 +63,17 @@ class LocalAdmin implements AdminInterface {
} }
async fetchMemberDataByToken( async fetchMemberDataByToken(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
organizationMemberToken: string, organizationMemberToken: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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> { ): Promise<AdminApiData> {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
reportPlayer( reportPlayer(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
reportedUserUuid: string, reportedUserUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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 // eslint-disable-next-line @typescript-eslint/no-unused-vars
reporterUserUuid: string, reporterUserUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
async verifyBanUser( async verifyBanUser(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
userUuid: string, userUuid: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
ipAddress: string, ipAddress: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // 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> { ): Promise<AdminBannedData> {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }
async getUrlRoomsFromSameWorld( async getUrlRoomsFromSameWorld(
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
locale: string, roomUrl: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
roomUrl: string locale?: string
): Promise<string[]> { ): Promise<string[]> {
return Promise.reject(new Error("No admin backoffice set!")); return Promise.reject(new Error("No admin backoffice set!"));
} }

View File

@ -125,10 +125,10 @@ export class SocketManager implements ZoneEventListener {
.on("end", () => { .on("end", () => {
console.warn( console.warn(
"Admin connection lost to back server '" + "Admin connection lost to back server '" +
apiClient.getChannel().getTarget() + apiClient.getChannel().getTarget() +
"' for room '" + "' for room '" +
roomId + roomId +
"'" "'"
); );
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start. // Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
if (!client.disconnecting) { if (!client.disconnecting) {
@ -139,10 +139,10 @@ export class SocketManager implements ZoneEventListener {
.on("error", (err: Error) => { .on("error", (err: Error) => {
console.error( console.error(
"Error in connection to back server '" + "Error in connection to back server '" +
apiClient.getChannel().getTarget() + apiClient.getChannel().getTarget() +
"' for room '" + "' for room '" +
roomId + roomId +
"':", "':",
err err
); );
if (!client.disconnecting) { if (!client.disconnecting) {
@ -231,10 +231,10 @@ export class SocketManager implements ZoneEventListener {
.on("end", () => { .on("end", () => {
console.warn( console.warn(
"Connection lost to back server '" + "Connection lost to back server '" +
apiClient.getChannel().getTarget() + apiClient.getChannel().getTarget() +
"' for room '" + "' for room '" +
client.roomId + client.roomId +
"'" "'"
); );
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start. // Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
if (!client.disconnecting) { if (!client.disconnecting) {
@ -245,10 +245,10 @@ export class SocketManager implements ZoneEventListener {
.on("error", (err: Error) => { .on("error", (err: Error) => {
console.error( console.error(
"Error in connection to back server '" + "Error in connection to back server '" +
apiClient.getChannel().getTarget() + apiClient.getChannel().getTarget() +
"' for room '" + "' for room '" +
client.roomId + client.roomId +
"':", "':",
err err
); );
if (!client.disconnecting) { if (!client.disconnecting) {