More eslint fixes (+ ignoring no-unsafe-argument rule for now)

This commit is contained in:
David Négrier 2021-12-16 15:57:37 +01:00
parent 98d3a58861
commit 0c281db411
9 changed files with 76 additions and 21 deletions

View File

@ -41,7 +41,8 @@ module.exports = {
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/restrict-template-expressions": "off"
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unsafe-argument": "off",
},
"settings": {
"svelte3/typescript": true,

View File

@ -12,6 +12,8 @@ import { userIsConnected } from "../Stores/MenuStore";
import { analyticsClient } from "../Administration/AnalyticsClient";
import { axiosWithRetry } from "./AxiosUtils";
import axios from "axios";
import { isRegisterData } from "../Messages/JsonMessages/RegisterData";
import { isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
class ConnectionManager {
private localUser!: LocalUser;
@ -126,6 +128,10 @@ class ConnectionManager {
const data = await Axios.post(`${PUSHER_URL}/register`, { organizationMemberToken }).then(
(res) => res.data
);
if (!isRegisterData(data)) {
console.error("Invalid data received from /register route. Data: ", data);
throw new Error("Invalid data received from /register route.");
}
this.localUser = new LocalUser(data.userUuid, data.textures, data.email);
this.authToken = data.authToken;
localUserStore.saveUser(this.localUser);
@ -326,7 +332,9 @@ class ConnectionManager {
}
const { authToken, userUuid, textures, email } = await Axios.get(`${PUSHER_URL}/login-callback`, {
params: { code, nonce, token, playUri: this.currentRoom?.key },
}).then((res) => res.data);
}).then((res) => {
return res.data;
});
localUserStore.setAuthToken(authToken);
this.localUser = new LocalUser(userUuid, textures, email);
localUserStore.saveUser(this.localUser);

View File

@ -426,7 +426,7 @@ export const localStreamStore = derived<Readable<MediaStreamConstraints>, LocalS
// TODO: does it make sense to pop this error when retrying?
set({
type: "error",
error: e,
error: e instanceof Error ? e : new Error("An unknown error happened"),
});
// Let's try without video constraints
if (constraints.video !== false) {
@ -444,7 +444,7 @@ export const localStreamStore = derived<Readable<MediaStreamConstraints>, LocalS
console.info("Error. Unable to get microphone and/or camera access.", constraints, e);
set({
type: "error",
error: e,
error: e instanceof Error ? e : new Error("An unknown error happened"),
});
}
}

View File

@ -153,7 +153,7 @@ export const screenSharingLocalStreamStore = derived<Readable<MediaStreamConstra
console.info("Error. Unable to share screen.", e);
set({
type: "error",
error: e,
error: e instanceof Error ? e : new Error("An unknown error happened"),
});
}
})();

View File

@ -7,7 +7,7 @@ class TouchScreenManager {
//found here: https://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript#4819886
detectTouchscreen(): boolean {
return "ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
}
}

View File

@ -0,0 +1,23 @@
import * as tg from "generic-type-guard";
import { isCharacterTexture} from "./CharacterTexture";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isAdminApiData = new tg.IsInterface()
.withProperties({
roomUrl: tg.isString,
email: tg.isNullable(tg.isString),
mapUrlStart: tg.isString,
tags: tg.isArray(tg.isString),
policy_type: tg.isNumber,
userUuid: tg.isString,
textures: tg.isArray(isCharacterTexture),
})
.withOptionalProperties({
messages: tg.isArray(tg.isUnknown),
})
.get();
export type AdminApiData = tg.GuardedType<typeof isAdminApiData>;

View File

@ -0,0 +1,24 @@
import * as tg from "generic-type-guard";
import { isCharacterTexture} from "./CharacterTexture";
/*
* WARNING! The original file is in /messages/JsonMessages.
* All other files are automatically copied from this file on container startup / build
*/
export const isRegisterData = new tg.IsInterface()
.withProperties({
roomUrl: tg.isString,
email: tg.isNullable(tg.isString),
organizationMemberToken: tg.isNullable(tg.isString),
mapUrlStart: tg.isString,
userUuid: tg.isString,
textures: tg.isArray(isCharacterTexture),
authToken: tg.isString,
})
.withOptionalProperties({
messages: tg.isArray(tg.isUnknown),
})
.get();
export type RegisterData = tg.GuardedType<typeof isRegisterData>;

View File

@ -6,6 +6,7 @@ import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
import { parse } from "query-string";
import { openIDClient } from "../Services/OpenIDClient";
import { DISABLE_ANONYMOUS, FRONT_URL } from "../Enum/EnvironmentVariable";
import { RegisterData } from "../../../messages/JsonMessages/RegisterData";
export interface TokenInterface {
userUuid: string;
@ -191,7 +192,7 @@ export class AuthenticateController extends BaseController {
mapUrlStart,
organizationMemberToken,
textures,
})
} as RegisterData)
);
} catch (e) {
console.error("register => ERROR", e);

View File

@ -1,20 +1,10 @@
import { ADMIN_API_TOKEN, ADMIN_API_URL, ADMIN_URL, OPID_PROFILE_SCREEN_PROVIDER } from "../Enum/EnvironmentVariable";
import Axios from "axios";
import { GameRoomPolicyTypes } from "_Model/PusherRoom";
import { CharacterTexture} from "../Messages/JsonMessages/CharacterTexture";
import { MapDetailsData} from "../Messages/JsonMessages/MapDetailsData";
import { RoomRedirect} from "../Messages/JsonMessages/RoomRedirect";
export interface AdminApiData {
roomUrl: string;
email: string | null;
mapUrlStart: string;
tags: string[];
policy_type: number;
userUuid: string;
messages?: unknown[];
textures: CharacterTexture[];
}
import { CharacterTexture } from "../Messages/JsonMessages/CharacterTexture";
import { MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
import { AdminApiData, isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
export interface AdminBannedData {
is_banned: boolean;
@ -77,6 +67,10 @@ class AdminApi {
const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, {
headers: { Authorization: `${ADMIN_API_TOKEN}` },
});
if (!isAdminApiData(res.data)) {
console.error("Message received from /api/login-url is not in the expected format. Message: ", res.data);
throw new Error("Message received from /api/login-url is not in the expected format.");
}
return res.data;
}
@ -88,6 +82,10 @@ class AdminApi {
const res = await Axios.get(ADMIN_API_URL + "/api/check-user/" + organizationMemberToken, {
headers: { Authorization: `${ADMIN_API_TOKEN}` },
});
if (!isAdminApiData(res.data)) {
console.error("Message received from /api/check-user is not in the expected format. Message: ", res.data);
throw new Error("Message received from /api/check-user is not in the expected format.");
}
return res.data;
}