clean up indentation (blame/praise VS Code for this 😜)

This commit is contained in:
Maciek Nowacki 2021-03-02 13:51:53 -07:00
parent eccba2876e
commit 76e321c3f7

View File

@ -26,15 +26,15 @@ class XhrListener {
logger.debugLog.info("XhrListener running"); logger.debugLog.info("XhrListener running");
} }
public relayEvent(event: string, channel: string):boolean { public relayEvent(event: string, channel: string): boolean {
logger.debugLog.info(`XhrListener:relayEvent(event: ${event}, channel: ${channel})`); logger.debugLog.info(`XhrListener:relayEvent(event: ${event}, channel: ${channel})`);
for (let c of this.#cm.channels) { for (let c of this.#cm.channels) {
if (channel === c.id) { if (channel === c.id) {
let dmCount:number = 0; let dmCount: number = 0;
for (let client of c.clients) { for (let client of c.clients) {
let nonce:string = crypto.randomBytes(4).toString("hex"); let nonce: string = crypto.randomBytes(4).toString("hex");
// TODO: verify the nonce against the received reply, which we currently ignore // TODO: verify the nonce against the received reply, which we currently ignore
client.directMessage(JSON.stringify({message_type:"broadcast", message:{event_type:event, seq_id:nonce}})); client.directMessage(JSON.stringify({ message_type: "broadcast", message: { event_type: event, seq_id: nonce } }));
dmCount++; dmCount++;
} }
// dmCount of 1 would be normal. more than 1 is odd, but not necessarily bad. 0 means Exam UI has gone away somehow. // dmCount of 1 would be normal. more than 1 is odd, but not necessarily bad. 0 means Exam UI has gone away somehow.
@ -45,7 +45,7 @@ class XhrListener {
return false; return false;
} }
public onRequestEnded(body: Uint8Array[], request: IncomingMessage, response: ServerResponse):void { public onRequestEnded(body: Uint8Array[], request: IncomingMessage, response: ServerResponse): void {
logger.debugLog.info("XhrListener:onRequestEnded()"); logger.debugLog.info("XhrListener:onRequestEnded()");
if (request.method === 'OPTIONS') { if (request.method === 'OPTIONS') {
logger.debugLog.info("handling CORS preflight"); logger.debugLog.info("handling CORS preflight");
@ -59,14 +59,14 @@ class XhrListener {
logger.debugLog.info("parsing Archimedes event: " + body); logger.debugLog.info("parsing Archimedes event: " + body);
let endpoint = url.parse(request.url).pathname let endpoint = url.parse(request.url).pathname
let returnVal: [number, string] = [-1, ""]; let returnVal: [number, string] = [-1, ""];
let authorized:boolean = request.headers['x-proctoru-signature'] === AUTH_TOKEN; let authorized: boolean = request.headers['x-proctoru-signature'] === AUTH_TOKEN;
// body of POST is JSON: '{"examId":"proctor_u_id"}' // body of POST is JSON: '{"examId":"proctor_u_id"}'
switch (true) { switch (true) {
// match /event/pause* // match /event/pause*
case /^\/event\/pause([/]+.*)*$/.test(endpoint): case /^\/event\/pause([/]+.*)*$/.test(endpoint):
if (authorized) { if (authorized) {
let amsg:ArchimedesMessage = JSON.parse(Buffer.concat(body).toString()); let amsg: ArchimedesMessage = JSON.parse(Buffer.concat(body).toString());
if (this.relayEvent("pauseExam", amsg.examId)) { if (this.relayEvent("pauseExam", amsg.examId)) {
returnVal = [200, "pause event was successfully relayed"]; returnVal = [200, "pause event was successfully relayed"];
} else { } else {
@ -80,7 +80,7 @@ class XhrListener {
// match /event/resume* // match /event/resume*
case /^\/event\/resume([/]+.*)*$/.test(endpoint): case /^\/event\/resume([/]+.*)*$/.test(endpoint):
if (authorized) { if (authorized) {
let amsg:ArchimedesMessage = JSON.parse(Buffer.concat(body).toString()); let amsg: ArchimedesMessage = JSON.parse(Buffer.concat(body).toString());
if (this.relayEvent("resumeExam", amsg.examId)) { if (this.relayEvent("resumeExam", amsg.examId)) {
returnVal = [200, "resume event was successfully relayed"]; returnVal = [200, "resume event was successfully relayed"];
} else { } else {
@ -100,15 +100,15 @@ class XhrListener {
response.writeHead(authorized ? 400 : 401); response.writeHead(authorized ? 400 : 401);
response.end(); response.end();
} else { } else {
response.writeHead(returnVal[0], {'Content-Type': 'application/json'}); response.writeHead(returnVal[0], { 'Content-Type': 'application/json' });
response.end(JSON.stringify(returnVal[1])); response.end(JSON.stringify(returnVal[1]));
} }
} }
} }
private onRequest(request: IncomingMessage, response: ServerResponse):void { private onRequest(request: IncomingMessage, response: ServerResponse): void {
logger.debugLog.info("XhrListener:onRequest()"); logger.debugLog.info("XhrListener:onRequest()");
let body:Uint8Array[] = []; let body: Uint8Array[] = [];
request.on('data', post_block => body.push(post_block)); request.on('data', post_block => body.push(post_block));
request.on('end', () => { request.on('end', () => {