Skip to content

Commit

Permalink
dev: initial work on judge0 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Jan 27, 2025
1 parent 81ee52b commit 3f99d97
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/backend/src/modules/puterexec/Judge0Client.js
Original file line number Diff line number Diff line change
@@ -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 };
34 changes: 34 additions & 0 deletions src/backend/src/modules/puterexec/Judge0Service.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 3f99d97

Please sign in to comment.