This project provides an API to interact with the Ejudge platform using Puppeteer for web scraping. The main functionality includes user authentication, handling solutions, getting results, and parsing tasks. Prerequisites
To run this project, you need to have Node.js and npm installed on your machine. Installation
git clone https://github.com/Task-Testing-System-Devs/test-system-handler.git
cd test-system-handler
npm install
node puppeteerApi.js
curl --location --request GET 'http://localhost:3000/api/master/get-user' \
--header 'Content-Type: application/json' \
--data '{
"contest_id" : 1,
"other_user_id" : 1
}'
curl --location 'http://localhost:3000/api/master/contest-status-json?contest_id=1'
{
"message": "Contest status fetched successfully",
"data": {
"ok": true,
"server_time": 1710243391,
"action": "contest-status-json",
"result": {
"contest": {
"id": 1,
"name": "Test contest",
"score_system": 0,
"is_virtual": false,
"is_unlimited": false,
"duration": 18000,
"is_upsolving": false,
"is_started": true,
"start_time": 1709472887,
"is_clients_suspended": false,
"is_testing_suspended": false,
"is_stopped": true,
"stop_time": 1709490887,
"is_freezable": true,
"is_frozen": false,
"unfreeze_time": 1709498087
},
"online": {
"user_count": -1,
"max_user_count": 0,
"max_time": 0
},
"compilers": [
{
"id": 2,
"short_name": "gcc",
"long_name": "GNU C 11.4.0",
"src_sfx": ".c"
},
{
"id": 3,
"short_name": "g++",
"long_name": "GNU C++ 11.4.0",
"src_sfx": ".cpp"
},
{
"id": 23,
"short_name": "python3",
"long_name": "Python3 3.10.12",
"src_sfx": ".py"
},
],
"problems": [
{
"id": 1,
"short_name": "A",
"long_name": "Sum 1"
},
{
"id": 2,
"short_name": "B",
"long_name": "Sum 2"
}
]
}
}
}curl --location 'http://localhost:3000/api/master/problem-statement-json?contest_id=1&problem=1'
{
"message": "Problem statement fetched successfully",
"data": {
"title": "Задача A",
"description": "На стандартном потоке ввода задаются два целых числа, не меньшие\n-32000 и не большие 32000.\nНа стандартный поток вывода напечатайте сумму этих чисел.\n",
"examples": [
{
"input": "1\n2",
"output": "3"
}
]
}
}curl --location 'http://localhost:3000/api/master/submit-run' \
--form 'contest_id="1"' \
--form 'problem="1"' \
--form 'lang_id="23"' \
--form 'file=@"/Users/startsev/Desktop/test.py"'
{
"message": "Submission handled successfully",
"data": {
"ok": true,
"server_time": 1710244287,
"result": {
"run_id": 15,
"run_uuid": "e8b889da-844c-454e-9379-01b108b1e28c"
}
}
}curl --location 'http://localhost:3000/api/master/get-submit?contest_id=1&run_id=2'
{
"message": "Submit info fetched successfully",
"data": {
"ok": true,
"server_time": 1710244846,
"result": {
"run": {
"run_id": 2,
"run_uuid": "212bbfa8-9f74-4280-bcab-38eefda21835",
"serial_id": 3,
"status": 5,
"status_str": "WA",
"run_time": 1709994179,
"nsec": 388618000,
"run_time_us": 1709994179388618,
"duration": 521292,
"user_id": 1,
"user_login": "ejudge",
"user_name": "ejudge administrator",
"prob_id": 2,
"prob_name": "B",
"lang_id": 23,
"lang_name": "python3",
"ip": "38.180.14.27",
"sha1": "32c2f38995b6a3c761707453ad63814eeeb6cf87",
"size": 39,
"is_hidden": true,
"passed_mode": 1,
"raw_test": 0,
"verdict_bits": 16,
"last_change_us": 1709994179460414
}
}
}
}This endpoint allows for the registration of users, either students or teachers, by uploading a CSV file containing their information. The process is asynchronous; once a file is uploaded, the registration process begins immediately in the background.
http://localhost:3000/api/register-users
To upload a CSV file for user registration, use the following curl command. Replace students.csv with the path to your CSV file and set the userType form field to either student or teacher based on the type of users in the file.
curl -X POST http://localhost:3000/api/register-users \
-F "file=@students.csv" \
-F "userType=student"
The CSV file should have the following structure, with headers matching the user attributes:
For students:
first_name,last_name,middle_name,email,role,password,department,group
John,Doe,Johnovich,johndoe@example.com,student,qwerty,Computer Science,10A1
Jane,Doe,Janevich,janedoe@example.com,student,qwerty,Mathematics,10B2
For teachers:
first_name,last_name,middle_name,email,role,password
Alan,Smith,Alanovich,alansmith@example.com,teacher,qwerty
Eva,Brown,Evavich,evabrown@example.com,teacher,qwerty
Upon successful upload, the response will provide information about the file and note that the registration process has started:
{
"message": "The file students.csv has been uploaded and the registration process for students has started. Please check the server logs for completion status.",
"fileInfo": {
"originalName": "students.csv",
"mimeType": "text/csv",
"size": "217 bytes"
}
}The server will process each user registration in the background. If a user cannot be registered, for example, due to an email address already being in use, the error will be logged to the server console:
Error registering janedoe@example.com: Email address already in use
Error registering johndoe@example.com: Email address already in use
- Ensure the
uploads/directory exists in your server's root directory for file uploads. - The registration process is asynchronous; monitor server logs for completion status and any errors.
- Adjust the endpoints (
studentEndpointandteacherEndpoint) as necessary to match your server configuration.
The server has rate limiting implemented to protect against abuse (DDoS). It allows a maximum of 300 requests within a 5-minute window.
The server has basic error handling implemented. If an error occurs while processing a request, it will return a 500 status code with an error message.
Go to the root folder of your project and run the following command to build a Docker image:
docker-compose build --no-cache
Run the container with your image using the following command:
sudo docker-compose up
You are all set!