From cbe02a448910f6dc841a1ee56cb60e4105ef2f74 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Wed, 29 Jan 2025 13:57:50 -0500 Subject: [PATCH] dev: puterjs exec module --- .../src/modules/puterexec/Judge0Client.js | 25 +++++++++++-------- .../src/services/drivers/DriverService.js | 1 + src/puter-js/src/index.js | 2 ++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/backend/src/modules/puterexec/Judge0Client.js b/src/backend/src/modules/puterexec/Judge0Client.js index 15c2c556..3404784f 100644 --- a/src/backend/src/modules/puterexec/Judge0Client.js +++ b/src/backend/src/modules/puterexec/Judge0Client.js @@ -44,17 +44,22 @@ class Judge0Client { path = `/${path}`; } - const resp = await axios.request({ - method: 'POST', - url: `${this.baseURL}${path}`, - headers: { - Authorization: `Bearer ${this.token}`, - 'Content-Type': 'application/json', - }, - data, - }); + try { + const resp = await axios.request({ + method: 'POST', + url: `${this.baseURL}${path}`, + headers: { + Authorization: `Bearer ${this.token}`, + 'Content-Type': 'application/json', + }, + data, + }); - return resp.data; + return resp.data; + } catch (e) { + console.error('error response', e.response.data); + throw e; + } } } diff --git a/src/backend/src/services/drivers/DriverService.js b/src/backend/src/services/drivers/DriverService.js index f0ddc5aa..fe48171e 100644 --- a/src/backend/src/services/drivers/DriverService.js +++ b/src/backend/src/services/drivers/DriverService.js @@ -216,6 +216,7 @@ class DriverService extends BaseService { ['puter-tts']: 'aws-polly', ['puter-chat-completion']: 'openai-completion', ['puter-image-generation']: 'openai-image-generation', + 'puter-exec': 'judge0', 'puter-apps': 'es:app', 'puter-subdomains': 'es:subdomain', 'puter-notifications': 'es:notification', diff --git a/src/puter-js/src/index.js b/src/puter-js/src/index.js index 87b9db49..8e85f48a 100644 --- a/src/puter-js/src/index.js +++ b/src/puter-js/src/index.js @@ -23,6 +23,7 @@ import { PSocket, wispInfo } from './modules/networking/PSocket.js'; import { PTLSSocket } from "./modules/networking/PTLS.js" import { PWispHandler } from './modules/networking/PWispHandler.js'; import { make_http_api } from './lib/http.js'; +import Exec from './modules/Exec.js'; // TODO: This is for a safe-guard below; we should check if we can // generalize this behavior rather than hard-coding it. @@ -98,6 +99,7 @@ window.puter = (function() { this.registerModule('kv', KV); this.registerModule('drivers', Drivers); this.registerModule('debug', Debug); + this.registerModule('exec', Exec); // Path this.path = path;