mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 14:18:43 +08:00
dev: initial work on judge0 implementation
This commit is contained in:
parent
81ee52b00f
commit
3f99d975c0
32
src/backend/src/modules/puterexec/Judge0Client.js
Normal file
32
src/backend/src/modules/puterexec/Judge0Client.js
Normal 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 };
|
34
src/backend/src/modules/puterexec/Judge0Service.js
Normal file
34
src/backend/src/modules/puterexec/Judge0Service.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user