diff --git a/sandbox/.gitignore b/sandbox/.gitignore new file mode 100644 index 0000000..76add87 --- /dev/null +++ b/sandbox/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/sandbox/.prettierrc b/sandbox/.prettierrc new file mode 100644 index 0000000..c125846 --- /dev/null +++ b/sandbox/.prettierrc @@ -0,0 +1,8 @@ +{ + "tabWidth": 2, + "useTabs": true, + "singleQuote": true, + "trailingComma": "none", + "printWidth": 100, + "pluginSearchDirs": ["."] +} diff --git a/sandbox/package-lock.json b/sandbox/package-lock.json new file mode 100644 index 0000000..52214a5 --- /dev/null +++ b/sandbox/package-lock.json @@ -0,0 +1,95 @@ +{ + "name": "sandbox", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "sandbox", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "fs-extra": "^11.1.1" + }, + "devDependencies": { + "@types/fs-extra": "^11.0.1", + "typescript": "^5.0.4" + } + }, + "node_modules/@types/fs-extra": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.1.tgz", + "integrity": "sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==", + "dev": true, + "dependencies": { + "@types/jsonfile": "*", + "@types/node": "*" + } + }, + "node_modules/@types/jsonfile": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/@types/jsonfile/-/jsonfile-6.1.1.tgz", + "integrity": "sha512-GSgiRCVeapDN+3pqA35IkQwasaCh/0YFH5dEF6S88iDvEn901DjOeH3/QPY+XYP1DFzDZPvIvfeEgk+7br5png==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "20.1.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.1.0.tgz", + "integrity": "sha512-O+z53uwx64xY7D6roOi4+jApDGFg0qn6WHcxe5QeqjMaTezBO/mxdfFXIVAVVyNWKx84OmPB3L8kbVYOTeN34A==", + "dev": true + }, + "node_modules/fs-extra": { + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz", + "integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/typescript": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", + "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=12.20" + } + }, + "node_modules/universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "engines": { + "node": ">= 10.0.0" + } + } + } +} diff --git a/sandbox/package.json b/sandbox/package.json new file mode 100644 index 0000000..1dd1c92 --- /dev/null +++ b/sandbox/package.json @@ -0,0 +1,18 @@ +{ + "name": "sandbox", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build": "tsc" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@types/fs-extra": "^11.0.1", + "typescript": "^5.0.4" + }, + "dependencies": { + "fs-extra": "^11.1.1" + } +} diff --git a/sandbox/src/index.ts b/sandbox/src/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/sandbox/src/run/java.ts b/sandbox/src/run/java.ts new file mode 100644 index 0000000..be0756e --- /dev/null +++ b/sandbox/src/run/java.ts @@ -0,0 +1,50 @@ +import fs from 'fs-extra'; +import { join } from 'path'; +import os from 'os'; +import { exec, spawn } from 'child_process'; +import { error } from 'console'; +import util from 'util'; + +const execPromise = util.promisify(exec); + +export async function runJava( + srcDir: string, + mainFile: string, + mainClass: string, + input: string +): Promise { + const javaPath = ''; + if (javaPath == '') { + throw error('Java path not set'); + } + const tempDir = os.tmpdir(); + const buildDir = join(tempDir, 'bwcontest_java'); + if (fs.existsSync(buildDir)) { + fs.removeSync(buildDir); + } + fs.mkdirSync(buildDir); + + const compileCommand = `${join(javaPath, 'javac')} -cp ${srcDir} ${mainFile} -d ${buildDir}`; + await execPromise(compileCommand); + + const runCommand = `${join(javaPath, 'java')} -cp "${buildDir}" ${mainClass}`; + + return new Promise((resolve) => { + let outputBuffer = ''; + const child = spawn(runCommand, { shell: true }); + child.stdout.setEncoding('utf8'); + child.stdout.on('data', (data) => { + outputBuffer += data.toString(); + }); + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (data) => { + outputBuffer += data.toString(); + }); + child.stdin.write(input); + child.stdin.end(); + + child.on('close', () => { + resolve(outputBuffer); + }); + }); +} diff --git a/sandbox/tsconfig.json b/sandbox/tsconfig.json new file mode 100644 index 0000000..62fe3a2 --- /dev/null +++ b/sandbox/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "CommonJS", + "sourceMap": true, + "outDir": "./dist", + "esModuleInterop": true + }, + "include": ["./src/**/*"] +} diff --git a/web/prisma/ERD.svg b/web/prisma/ERD.svg index b492010..8da27f0 100644 --- a/web/prisma/ERD.svg +++ b/web/prisma/ERD.svg @@ -1 +1 @@ -SubmissionStateInReviewInReviewCorrectCorrectIncorrectIncorrectUserIntid🗝️StringusernameStringpasswordSessionStringtoken🗝️DateTimecreatedAtSubmissionIntid🗝️DateTimecreatedAtDateTimegradedAtSubmissionStatestateStringactualOutputStringmessageProblemIntid🗝️StringfriendlyNameStringpascalNameStringsampleInputStringsampleOutputStringrealInputStringrealOutputTeamIntid🗝️StringnameStringpasswordActiveTeamIntid🗝️StringsessionTokenDateTimesessionCreatedAtContestIntid🗝️Stringnamesessionsuserenum:stateteamproblemsubmissionscontestsSubmissioncontestsactiveTeamteamcontestteamsproblemsactiveTeams \ No newline at end of file +SubmissionStateQueuedQueuedInReviewInReviewCorrectCorrectIncorrectIncorrectUserIntid🗝️StringusernameStringpasswordSessionStringtoken🗝️DateTimecreatedAtSubmissionIntid🗝️DateTimecreatedAtDateTimegradedAtSubmissionStatestateStringactualOutputStringmessageProblemIntid🗝️StringfriendlyNameStringpascalNameStringsampleInputStringsampleOutputStringrealInputStringrealOutputTeamIntid🗝️StringnameStringpasswordActiveTeamIntid🗝️StringsessionTokenDateTimesessionCreatedAtContestIntid🗝️Stringnamesessionsuserenum:stateteamproblemsubmissionscontestsSubmissioncontestsactiveTeamteamcontestteamsproblemsactiveTeams \ No newline at end of file diff --git a/web/prisma/schema.prisma b/web/prisma/schema.prisma index 8daebea..7c6f304 100644 --- a/web/prisma/schema.prisma +++ b/web/prisma/schema.prisma @@ -26,6 +26,7 @@ model Session { } enum SubmissionState { + Queued InReview Correct Incorrect