Skip to content

Commit

Permalink
fix helper crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlauer-Hax committed Nov 29, 2023
1 parent b2a1c94 commit c8fe24e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules/
.DS_Store
helper/.env
helper/testinput.txt
deno.lock
21 changes: 12 additions & 9 deletions helper/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "https://deno.land/x/[email protected]/load.ts";
import { exists } from "https://deno.land/[email protected]/fs/mod.ts";

const date = new Date()
if (date.getMonth() === 11) {
Expand All @@ -25,7 +26,7 @@ function websocket() {
const ws = new WebSocket('ws://localhost:9000/wss');

let latestsolution: string;
ws.onmessage = (event) => {
ws.onmessage = async (event) => {
const json = JSON.parse(event.data);
if (json.type === 'solutions') {
console.log('Solutions received, triggering latest solution...');
Expand All @@ -34,18 +35,20 @@ function websocket() {
type: 'data',
name: latestsolution,
}));
const testinput = Deno.readTextFileSync('./testinput.txt');
if (testinput !== '') {
ws.send(JSON.stringify({
type: 'run',
solution: latestsolution,
input: testinput,
}));
if (await exists('./testinput.txt')) {
const testinput = Deno.readTextFileSync('./testinput.txt');
if (testinput !== '') {
ws.send(JSON.stringify({
type: 'run',
solution: latestsolution,
input: testinput,
}));
}
}
} else if (json.type === 'result') {
console.log(`${json.data}`);
} else if (json.type === 'data') {
ws.send(JSON.stringify({type: 'run',solution: latestsolution,input: json.data}));
ws.send(JSON.stringify({ type: 'run', solution: latestsolution, input: json.data }));
}
};

Expand Down

0 comments on commit c8fe24e

Please sign in to comment.