working run api calls
This commit is contained in:
+32
-1
@@ -1,3 +1,5 @@
|
||||
import axios from "axios";
|
||||
|
||||
var cookies: string | undefined;
|
||||
|
||||
export function getCookies(): string | undefined {
|
||||
@@ -7,6 +9,35 @@ export function setCookies(c: string) {
|
||||
cookies = c;
|
||||
}
|
||||
|
||||
export async function submitRun() {}
|
||||
export async function addRun(problem: string, mode: string): Promise<string> {
|
||||
return (
|
||||
await axios.put(
|
||||
"http://localhost:3000/api/run",
|
||||
{
|
||||
problem,
|
||||
category: mode,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Cookie: cookies,
|
||||
},
|
||||
},
|
||||
)
|
||||
).data.runId;
|
||||
}
|
||||
|
||||
export async function submitRun(runId: string) {
|
||||
await axios.post(
|
||||
"http://localhost:3000/api/run",
|
||||
{
|
||||
runId,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Cookie: cookies,
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function addRunMoves() {}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import * as vscode from "vscode";
|
||||
import { addRun, submitRun } from "./client";
|
||||
|
||||
export var currentRun: {
|
||||
interval: NodeJS.Timeout;
|
||||
problemId: string;
|
||||
start: Date;
|
||||
id: string;
|
||||
} | null = null;
|
||||
|
||||
export async function startRun(
|
||||
@@ -38,7 +40,10 @@ export async function startRun(
|
||||
|
||||
let start = Date.now();
|
||||
|
||||
const runId = await addRun(problemId, mode);
|
||||
|
||||
currentRun = {
|
||||
id: runId,
|
||||
problemId,
|
||||
start: new Date(),
|
||||
interval: setInterval(() => {
|
||||
@@ -60,6 +65,7 @@ export async function startRun(
|
||||
export async function stopRun() {
|
||||
if (currentRun) {
|
||||
clearTimeout(currentRun.interval);
|
||||
submitRun(currentRun.id);
|
||||
currentRun = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user