From 3f99d975c06f2aff20eca3aeeedd908a0982aae7 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 27 Jan 2025 16:19:16 -0500 Subject: [PATCH] dev: initial work on judge0 implementation --- .../src/modules/puterexec/Judge0Client.js | 32 +++++++++++++++++ .../src/modules/puterexec/Judge0Service.js | 34 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/backend/src/modules/puterexec/Judge0Client.js create mode 100644 src/backend/src/modules/puterexec/Judge0Service.js diff --git a/src/backend/src/modules/puterexec/Judge0Client.js b/src/backend/src/modules/puterexec/Judge0Client.js new file mode 100644 index 00000000..23ad4f66 --- /dev/null +++ b/src/backend/src/modules/puterexec/Judge0Client.js @@ -0,0 +1,32 @@ +const axios = require('axios'); + +class Judge0Client { + constructor (options = {}) { + Object.assign(this, { + baseURL: 'https://judge0-ce.p.sulu.sh', + token: '', + }, options); + } + + async about () { + return await this.get_('/about'); + } + + async get_ (path) { + if ( ! path.startsWith('/') ) { + path = `/${path}`; + } + console.log('how is this url invalid??', `${this.baseURL}${path}`); + const resp = await axios.request({ + method: 'GET', + url: `${this.baseURL}${path}`, + headers: { + Authorization: `Bearer ${this.token}`, + }, + }); + + return resp.data; + } +} + +module.exports = { Judge0Client }; \ No newline at end of file diff --git a/src/backend/src/modules/puterexec/Judge0Service.js b/src/backend/src/modules/puterexec/Judge0Service.js new file mode 100644 index 00000000..872449d1 --- /dev/null +++ b/src/backend/src/modules/puterexec/Judge0Service.js @@ -0,0 +1,34 @@ +const BaseService = require("../../services/BaseService"); +const { Judge0Client } = require("./Judge0Client"); + +class Judge0Service extends BaseService { + _construct () { + this.about_ = {}; + } + + static IMPLEMENTS = { + ['puter-exec']: { + async about () { + return this.about ?? (this.about = await this.client.about()); + }, + async supported () { + return require('./languages/languages'); + }, + async exec ({ runtime, code }) { + return await this.exec_(runtime, code); + } + } + } + + async _init () { + this.client = new Judge0Client({ + token: this.config.token, + }); + } + + async exec_ (runtime, code) { + // + } +} + +module.exports = Judge0Service;