diff --git a/package.json b/package.json index c211f03..e3dd093 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "@types/debug": "^0.0.30", "@types/express": "^4.0.39", "@types/minio": "^7.0.1", - "@types/mocha": "^5.0.0", + "@types/mocha": "^7.0.0", "@types/request": "^2.0.8", "@types/sequelize": "^4.0.79", "chai": "^4.1.2", @@ -52,8 +52,8 @@ }, "apidoc": { "title": "judge-blocks API", - "url": "http://judge.cb.lk/api", - "sampleUrl": "http://judge.cb.lk/api" + "url": "https://judge2.codingblocks.com/api", + "sampleUrl": "https://judge2.codingblocks.com/api" }, "nyc": { "extension": [ diff --git a/src/routes/api/run.ts b/src/routes/api/run.ts index a45b967..7c5903b 100644 --- a/src/routes/api/run.ts +++ b/src/routes/api/run.ts @@ -50,6 +50,8 @@ const handleTimeoutForSubmission = function (submissionId: number) { case 'callback': axios.post(job.callback, errorResponse) } + + delete runPool[submissionId] } const handleSuccessForSubmission = function (result: RunResponse) { @@ -79,6 +81,8 @@ const handleSuccessForSubmission = function (result: RunResponse) { })() break; } + + delete runPool[result.id] } /** @@ -109,7 +113,7 @@ const getRunPoolElement = function (body: RunRequestBody, res: Response): RunPoo * * @apiParam {String(Base64)} source source code to run (encoded in base64) * @apiParam {Enum} lang Language of code to execute - * @apiParam {String(Base64)} input [Optional] stdin input for the program (encoded in base64) + * @apiParam {String(Base64)} stdin [Optional] stdin input for the program (encoded in base64) * @apiParam {Enum} mode [Optional] mode for request. Default = `sync`, see: https://github.com/coding-blocks/judge-api/issues/16 * @apiParam {String)} callback [Optional] callback url for request. Required for `mode = callback` * @apiParam {String)} enc [Optional] Encoding type for stdin and source. Can be `url`|`base64`. Default = 'base64' @@ -172,7 +176,6 @@ route.post('/', (req, res, next) => { setTimeout(() => { if (runPool[submission.id]) { handleTimeoutForSubmission(submission.id) - delete runPool[submission.id] } }, config.RUN.TIMEOUT) @@ -198,7 +201,6 @@ route.post('/', (req, res, next) => { successListener.on('success', (result: RunResponse) => { if (runPool[result.id]) { handleSuccessForSubmission(result) - delete runPool[result.id] } Submissions.update({ end_time: new Date() diff --git a/src/utils/s3.ts b/src/utils/s3.ts index 6ccd6c4..490c010 100644 --- a/src/utils/s3.ts +++ b/src/utils/s3.ts @@ -5,8 +5,8 @@ import config = require('../../config') const client = new Minio.Client({ endPoint: config.S3.endpoint, - port: config.S3.port, - useSSL: config.S3.ssl, + port: +config.S3.port, + useSSL: !!config.S3.ssl, accessKey: config.S3.accessKey, secretKey: config.S3.secretKey, }) diff --git a/src/validators/ApiKeyValidators.ts b/src/validators/ApiKeyValidators.ts index c056191..c693347 100644 --- a/src/validators/ApiKeyValidators.ts +++ b/src/validators/ApiKeyValidators.ts @@ -4,7 +4,8 @@ import {ApiKeyAttrs, ApiKeys} from '../db/models' export function checkValidApiKey (req: Request): Promise { return new Promise((resolve, reject) => { - let apiKey = req.header('Authorization').split('Bearer ')[1] + let apiKey = req.header('Authorization') + apiKey = apiKey && apiKey.split('Bearer ')[1] if (!apiKey) { reject(new Error('No API Key in request')) } @@ -42,4 +43,4 @@ export function checkValidApiKey (req: Request): Promise { -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index db0dc65..4d7be3a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -163,10 +163,10 @@ dependencies: "@types/node" "*" -"@types/mocha@^5.0.0": - version "5.2.5" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.5.tgz#8a4accfc403c124a0bafe8a9fc61a05ec1032073" - integrity sha512-lAVp+Kj54ui/vLUFxsJTMtWvZraZxum3w3Nwkble2dNuV5VnPA+Mi2oGX9XYJAaIvZi3tn3cbjS/qcJXRb6Bww== +"@types/mocha@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-7.0.0.tgz#ac65f97746464ec84ce15f4743cd61c449822ad4" + integrity sha512-6mh1VlA343Ax31blo37+KZ0DxDOA8b6cL963xPOOt7fMYtG07aJJ+0FRLvcDO4KrL45faOS104G7kwAjZc9l4w== "@types/node@*": version "8.0.51"