-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: initial work on judge0 implementation
- Loading branch information
1 parent
81ee52b
commit 3f99d97
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |