Linting app

This commit is contained in:
David Négrier 2020-09-29 16:12:17 +02:00
parent b485c9bf46
commit 432b4a0e85
7 changed files with 46 additions and 42 deletions

View File

@ -12,27 +12,29 @@ export class AdminController {
getLoginUrlByToken(){ getLoginUrlByToken(){
this.App.get("/register/:token", async (res: HttpResponse, req: HttpRequest) => { this.App.get("/register/:token", (res: HttpResponse, req: HttpRequest) => {
if (!ADMIN_API_URL) { (async () => {
return res.writeStatus("500 Internal Server Error").end('No admin backoffice set!'); 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 let response = null
try { try {
response = await Axios.get(ADMIN_API_URL+'/api/login-url/'+token, { headers: {"Authorization" : `${ADMIN_API_TOKEN}`} }) response = await Axios.get(ADMIN_API_URL+'/api/login-url/'+token, { headers: {"Authorization" : `${ADMIN_API_TOKEN}`} })
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
return res.status(e.status || 500).send('An error happened'); return res.status(e.status || 500).send('An error happened');
} }
const organizationSlug = response.data.organizationSlug; const organizationSlug = response.data.organizationSlug;
const worldSlug = response.data.worldSlug; const worldSlug = response.data.worldSlug;
const roomSlug = response.data.roomSlug; const roomSlug = response.data.roomSlug;
return res.writeStatus("200 OK").end(JSON.stringify({organizationSlug, worldSlug, roomSlug})); res.writeStatus("200 OK").end(JSON.stringify({organizationSlug, worldSlug, roomSlug}));
})();
}); });
} }
} }

View File

@ -39,20 +39,22 @@ export class AuthenticateController extends BaseController {
res.end(); res.end();
}); });
this.App.post("/login", async (res: HttpResponse, req: HttpRequest) => { this.App.post("/login", (res: HttpResponse, req: HttpRequest) => {
this.addCorsHeaders(res); (async () => {
this.addCorsHeaders(res);
res.onAborted(() => { res.onAborted(() => {
console.warn('Login request was aborted'); console.warn('Login request was aborted');
}) })
const param = await res.json(); const param = await res.json();
const userUuid = uuid(); const userUuid = uuid();
const token = Jwt.sign({name: param.name, userUuid: userUuid} as TokenInterface, SECRET_KEY, {expiresIn: '24h'}); const token = Jwt.sign({name: param.name, userUuid: userUuid} as TokenInterface, SECRET_KEY, {expiresIn: '24h'});
res.writeStatus("200 OK").end(JSON.stringify({ res.writeStatus("200 OK").end(JSON.stringify({
token: token, token: token,
mapUrlStart: URL_ROOM_STARTED, mapUrlStart: URL_ROOM_STARTED,
userId: userUuid, userId: userUuid,
})); }));
})();
}); });
} }
} }

View File

@ -5,7 +5,7 @@ import { UwsApp } from './types';
class App extends (<UwsApp>_App) { class App extends (<UwsApp>_App) {
constructor(options: AppOptions = {}) { constructor(options: AppOptions = {}) {
super(options); super(options); // eslint-disable-line constructor-super
extend(this, new BaseApp()); extend(this, new BaseApp());
} }
} }

View File

@ -11,11 +11,11 @@ const handleBody = (res: HttpResponse, req: HttpRequest) => {
res.bodyStream = function() { res.bodyStream = function() {
const stream = new Readable(); const stream = new Readable();
stream._read = noOp; stream._read = noOp; // eslint-disable-line @typescript-eslint/unbound-method
this.onData((ab, isLast) => { this.onData((ab, isLast) => {
// uint and then slicing is bit faster than slice and then uint // 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) { if (isLast) {
stream.push(null); stream.push(null);
} }
@ -26,7 +26,7 @@ const handleBody = (res: HttpResponse, req: HttpRequest) => {
res.body = () => stob(res.bodyStream()); res.body = () => stob(res.bodyStream());
if (contType.indexOf('application/json') > -1) if (contType.includes('application/json'))
res.json = async () => JSON.parse(await res.body()); res.json = async () => JSON.parse(await res.body());
}; };

View File

@ -5,7 +5,7 @@ import { UwsApp } from './types';
class SSLApp extends (<UwsApp>_SSLApp) { class SSLApp extends (<UwsApp>_SSLApp) {
constructor(options: AppOptions) { constructor(options: AppOptions) {
super(options); super(options); // eslint-disable-line constructor-super
extend(this, new BaseApp()); extend(this, new BaseApp());
} }
} }

View File

@ -1,6 +1,6 @@
import { ReadStream } from 'fs'; 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( const ownProps = Object.getOwnPropertyNames(Object.getPrototypeOf(from)).concat(
Object.keys(from) Object.keys(from)
); );

View File

@ -149,9 +149,9 @@ export class Connection implements Connection {
private readonly socket: WebSocket; private readonly socket: WebSocket;
private userId: number|null = null; private userId: number|null = null;
private listeners: Map<string, Function[]> = new Map<string, Function[]>(); private listeners: Map<string, Function[]> = new Map<string, Function[]>();
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; Connection.websocketFactory = websocketFactory;
} }
@ -206,9 +206,9 @@ export class Connection implements Connection {
} else if (message.hasRoomjoinedmessage()) { } else if (message.hasRoomjoinedmessage()) {
const roomJoinedMessage = message.getRoomjoinedmessage() as RoomJoinedMessage; const roomJoinedMessage = message.getRoomjoinedmessage() as RoomJoinedMessage;
const users: Array<MessageUserJoined> = roomJoinedMessage.getUserList().map(this.toMessageUserJoined); const users: Array<MessageUserJoined> = roomJoinedMessage.getUserList().map(this.toMessageUserJoined.bind(this));
const groups: Array<GroupCreatedUpdatedMessageInterface> = roomJoinedMessage.getGroupList().map(this.toGroupCreatedUpdatedMessage); const groups: Array<GroupCreatedUpdatedMessageInterface> = roomJoinedMessage.getGroupList().map(this.toGroupCreatedUpdatedMessage.bind(this));
let items: { [itemId: number] : unknown } = {}; const items: { [itemId: number] : unknown } = {};
for (const item of roomJoinedMessage.getItemList()) { for (const item of roomJoinedMessage.getItemList()) {
items[item.getItemid()] = JSON.parse(item.getStatejson()); items[item.getItemid()] = JSON.parse(item.getStatejson());
} }
@ -221,7 +221,7 @@ export class Connection implements Connection {
} else if (message.hasSetuseridmessage()) { } else if (message.hasSetuseridmessage()) {
this.userId = (message.getSetuseridmessage() as SetUserIdMessage).getUserid(); this.userId = (message.getSetuseridmessage() as SetUserIdMessage).getUserid();
} else if (message.hasErrormessage()) { } else if (message.hasErrormessage()) {
console.error(EventMessage.MESSAGE_ERROR, message.getErrormessage()?.getMessage); console.error(EventMessage.MESSAGE_ERROR, message.getErrormessage()?.getMessage());
} else if (message.hasWebrtcsignaltoclientmessage()) { } else if (message.hasWebrtcsignaltoclientmessage()) {
this.dispatch(EventMessage.WEBRTC_SIGNAL, message.getWebrtcsignaltoclientmessage()); this.dispatch(EventMessage.WEBRTC_SIGNAL, message.getWebrtcsignaltoclientmessage());
} else if (message.hasWebrtcscreensharingsignaltoclientmessage()) { } else if (message.hasWebrtcscreensharingsignaltoclientmessage()) {