diff --git a/server/api/services/code.service.js b/server/api/services/code.service.js index 3e12e1f..3bb9e29 100644 --- a/server/api/services/code.service.js +++ b/server/api/services/code.service.js @@ -7,8 +7,8 @@ const ROOT_DIR = `${process.cwd()}`; const SOURCE_DIR = path.join(ROOT_DIR, 'executor'); const TARGET_DIR = `/app/codes`; const IMAGE_NAME = 'executor:1.0'; -//const VOL_NAME = `my_vol`; -const VOL_NAME = SOURCE_DIR; +const VOL_NAME = `my_vol`; +//const VOL_NAME = SOURCE_DIR; class CodeService { async execute(code, input, lang, id) { @@ -77,6 +77,10 @@ class CodeService { fileName += '.java'; break; } + case 'c': { + fileName += '.c'; + break; + } default: { throw { message: 'Invalid language' }; } @@ -114,6 +118,10 @@ class CodeService { command = `cd ${TARGET_DIR} && javac ${file} && java Input < ${input}`; break; } + case 'c': { + command = `cd ${TARGET_DIR} && gcc -o ${id} ${file} && ./${id} < ${input}`; + break; + } default: { throw { message: 'Invalid language' }; } @@ -157,9 +165,9 @@ class CodeService { if (err) throw { message: err }; }); } - if (lang == 'c++') { + if (lang == 'c++' || lang == 'c') { fs.unlinkSync(path.join(SOURCE_DIR, id), err => { - if (err) throw { message: err }; + if (err) throw err; }); } if (lang == 'java') { diff --git a/server/api/services/validation.service.js b/server/api/services/validation.service.js index 96ab2cc..b6dc249 100644 --- a/server/api/services/validation.service.js +++ b/server/api/services/validation.service.js @@ -45,6 +45,11 @@ class ValidationService { isValid: true }; } + case 'c': { + return { + isValid: true + }; + } default: { return { isValid: false,