dev: initial work on judge0 implementation

This commit is contained in:
KernelDeimos 2025-01-27 16:19:16 -05:00
parent 81ee52b00f
commit 3f99d975c0
2 changed files with 66 additions and 0 deletions

View File

@ -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 };

View File

@ -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;