From 432b4a0e85f41c587c6c00d69849ce8e87c17949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Tue, 29 Sep 2020 16:12:17 +0200 Subject: [PATCH] Linting app --- back/src/Controller/AdminController.ts | 36 ++++++++++--------- back/src/Controller/AuthenticateController.ts | 28 ++++++++------- back/src/Server/server/app.ts | 2 +- back/src/Server/server/baseapp.ts | 6 ++-- back/src/Server/server/sslapp.ts | 2 +- back/src/Server/server/utils.ts | 2 +- front/src/Connection.ts | 12 +++---- 7 files changed, 46 insertions(+), 42 deletions(-) diff --git a/back/src/Controller/AdminController.ts b/back/src/Controller/AdminController.ts index 78280523..7bb536ca 100644 --- a/back/src/Controller/AdminController.ts +++ b/back/src/Controller/AdminController.ts @@ -12,27 +12,29 @@ export class AdminController { getLoginUrlByToken(){ - this.App.get("/register/:token", async (res: HttpResponse, req: HttpRequest) => { - if (!ADMIN_API_URL) { - return res.writeStatus("500 Internal Server Error").end('No admin backoffice set!'); - } + this.App.get("/register/:token", (res: HttpResponse, req: HttpRequest) => { + (async () => { + if (!ADMIN_API_URL) { + return res.writeStatus("500 Internal Server Error").end('No admin backoffice set!'); + } - const query = parse(req.getQuery()); + const query = parse(req.getQuery()); - const token:string = query.token as string; + const token:string = query.token as string; - let response = null - try { - response = await Axios.get(ADMIN_API_URL+'/api/login-url/'+token, { headers: {"Authorization" : `${ADMIN_API_TOKEN}`} }) - } catch (e) { - console.log(e.message) - return res.status(e.status || 500).send('An error happened'); - } + let response = null + try { + response = await Axios.get(ADMIN_API_URL+'/api/login-url/'+token, { headers: {"Authorization" : `${ADMIN_API_TOKEN}`} }) + } catch (e) { + console.log(e.message) + return res.status(e.status || 500).send('An error happened'); + } - const organizationSlug = response.data.organizationSlug; - const worldSlug = response.data.worldSlug; - const roomSlug = response.data.roomSlug; - return res.writeStatus("200 OK").end(JSON.stringify({organizationSlug, worldSlug, roomSlug})); + const organizationSlug = response.data.organizationSlug; + const worldSlug = response.data.worldSlug; + const roomSlug = response.data.roomSlug; + res.writeStatus("200 OK").end(JSON.stringify({organizationSlug, worldSlug, roomSlug})); + })(); }); } } diff --git a/back/src/Controller/AuthenticateController.ts b/back/src/Controller/AuthenticateController.ts index b7fd093c..6585054d 100644 --- a/back/src/Controller/AuthenticateController.ts +++ b/back/src/Controller/AuthenticateController.ts @@ -39,20 +39,22 @@ export class AuthenticateController extends BaseController { res.end(); }); - this.App.post("/login", async (res: HttpResponse, req: HttpRequest) => { - this.addCorsHeaders(res); + this.App.post("/login", (res: HttpResponse, req: HttpRequest) => { + (async () => { + this.addCorsHeaders(res); - res.onAborted(() => { - console.warn('Login request was aborted'); - }) - const param = await res.json(); - const userUuid = uuid(); - const token = Jwt.sign({name: param.name, userUuid: userUuid} as TokenInterface, SECRET_KEY, {expiresIn: '24h'}); - res.writeStatus("200 OK").end(JSON.stringify({ - token: token, - mapUrlStart: URL_ROOM_STARTED, - userId: userUuid, - })); + res.onAborted(() => { + console.warn('Login request was aborted'); + }) + const param = await res.json(); + const userUuid = uuid(); + const token = Jwt.sign({name: param.name, userUuid: userUuid} as TokenInterface, SECRET_KEY, {expiresIn: '24h'}); + res.writeStatus("200 OK").end(JSON.stringify({ + token: token, + mapUrlStart: URL_ROOM_STARTED, + userId: userUuid, + })); + })(); }); } } diff --git a/back/src/Server/server/app.ts b/back/src/Server/server/app.ts index 800353c2..3b98a9b3 100644 --- a/back/src/Server/server/app.ts +++ b/back/src/Server/server/app.ts @@ -5,7 +5,7 @@ import { UwsApp } from './types'; class App extends (_App) { constructor(options: AppOptions = {}) { - super(options); + super(options); // eslint-disable-line constructor-super extend(this, new BaseApp()); } } diff --git a/back/src/Server/server/baseapp.ts b/back/src/Server/server/baseapp.ts index d723c33d..0c07c17e 100644 --- a/back/src/Server/server/baseapp.ts +++ b/back/src/Server/server/baseapp.ts @@ -11,11 +11,11 @@ const handleBody = (res: HttpResponse, req: HttpRequest) => { res.bodyStream = function() { const stream = new Readable(); - stream._read = noOp; + stream._read = noOp; // eslint-disable-line @typescript-eslint/unbound-method this.onData((ab, isLast) => { // uint and then slicing is bit faster than slice and then uint - stream.push(new Uint8Array(ab.slice((ab as any).byteOffset, ab.byteLength))); + stream.push(new Uint8Array(ab.slice((ab as any).byteOffset, ab.byteLength))); // eslint-disable-line @typescript-eslint/no-explicit-any if (isLast) { stream.push(null); } @@ -26,7 +26,7 @@ const handleBody = (res: HttpResponse, req: HttpRequest) => { res.body = () => stob(res.bodyStream()); - if (contType.indexOf('application/json') > -1) + if (contType.includes('application/json')) res.json = async () => JSON.parse(await res.body()); }; diff --git a/back/src/Server/server/sslapp.ts b/back/src/Server/server/sslapp.ts index 60b17aa4..46ae89a5 100644 --- a/back/src/Server/server/sslapp.ts +++ b/back/src/Server/server/sslapp.ts @@ -5,7 +5,7 @@ import { UwsApp } from './types'; class SSLApp extends (_SSLApp) { constructor(options: AppOptions) { - super(options); + super(options); // eslint-disable-line constructor-super extend(this, new BaseApp()); } } diff --git a/back/src/Server/server/utils.ts b/back/src/Server/server/utils.ts index f7f3e4b5..80ea3938 100644 --- a/back/src/Server/server/utils.ts +++ b/back/src/Server/server/utils.ts @@ -1,6 +1,6 @@ import { ReadStream } from 'fs'; -function extend(who: any, from: any, overwrite = true) { +function extend(who: any, from: any, overwrite = true) { // eslint-disable-line @typescript-eslint/no-explicit-any const ownProps = Object.getOwnPropertyNames(Object.getPrototypeOf(from)).concat( Object.keys(from) ); diff --git a/front/src/Connection.ts b/front/src/Connection.ts index 6da46c2d..e0c3121d 100644 --- a/front/src/Connection.ts +++ b/front/src/Connection.ts @@ -149,9 +149,9 @@ export class Connection implements Connection { private readonly socket: WebSocket; private userId: number|null = null; private listeners: Map = new Map(); - private static websocketFactory: null|((url: string)=>any) = null; + private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any - public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { + public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any Connection.websocketFactory = websocketFactory; } @@ -206,9 +206,9 @@ export class Connection implements Connection { } else if (message.hasRoomjoinedmessage()) { const roomJoinedMessage = message.getRoomjoinedmessage() as RoomJoinedMessage; - const users: Array = roomJoinedMessage.getUserList().map(this.toMessageUserJoined); - const groups: Array = roomJoinedMessage.getGroupList().map(this.toGroupCreatedUpdatedMessage); - let items: { [itemId: number] : unknown } = {}; + const users: Array = roomJoinedMessage.getUserList().map(this.toMessageUserJoined.bind(this)); + const groups: Array = roomJoinedMessage.getGroupList().map(this.toGroupCreatedUpdatedMessage.bind(this)); + const items: { [itemId: number] : unknown } = {}; for (const item of roomJoinedMessage.getItemList()) { items[item.getItemid()] = JSON.parse(item.getStatejson()); } @@ -221,7 +221,7 @@ export class Connection implements Connection { } else if (message.hasSetuseridmessage()) { this.userId = (message.getSetuseridmessage() as SetUserIdMessage).getUserid(); } else if (message.hasErrormessage()) { - console.error(EventMessage.MESSAGE_ERROR, message.getErrormessage()?.getMessage); + console.error(EventMessage.MESSAGE_ERROR, message.getErrormessage()?.getMessage()); } else if (message.hasWebrtcsignaltoclientmessage()) { this.dispatch(EventMessage.WEBRTC_SIGNAL, message.getWebrtcsignaltoclientmessage()); } else if (message.hasWebrtcscreensharingsignaltoclientmessage()) {