-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecute-code.ts
More file actions
32 lines (29 loc) · 929 Bytes
/
execute-code.ts
File metadata and controls
32 lines (29 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Input } from "@shared/types";
import { IpcMainInvokeEvent } from "electron";
import https from "https";
import axios from "axios";
export const handleExecuteCode = async (_: IpcMainInvokeEvent, payload: Input) => {
const agent = new https.Agent({
rejectUnauthorized: false
});
const axiosInstance = axios.create({
httpsAgent: agent
});
const baseAPI = "https://145.223.97.55:9292";
const start = performance.now();
try {
const { data } = await axiosInstance.post(`${baseAPI}/run`, payload);
const end = performance.now();
return {
output: data.output,
responseTime: Math.round(end - start)
};
} catch (error: any) {
const end = performance.now();
const output = error?.response?.data?.details || error?.message || "Unknown error occurred";
return {
output,
responseTime: Math.round(end - start)
};
}
};