diff --git a/ExerciceChecker/.idea/vcs.xml b/ExerciceChecker/.idea/vcs.xml index 6c0b8635858dc7ad44b93df54b762707ce49eefc..d86e73b516141a07b5ba1f16f6f315749512bedc 100644 --- a/ExerciceChecker/.idea/vcs.xml +++ b/ExerciceChecker/.idea/vcs.xml @@ -2,5 +2,7 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> + <mapping directory="$PROJECT_DIR$/src/shared" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/src/sharedByClients" vcs="Git" /> </component> </project> \ No newline at end of file diff --git a/ExerciceChecker/src/app.ts b/ExerciceChecker/src/app.ts index a4f2ffd64f0abf492d16f4dc0565f872fb1991db..84168a52c86110ef280f8c58cd18875bb02806cc 100644 --- a/ExerciceChecker/src/app.ts +++ b/ExerciceChecker/src/app.ts @@ -4,20 +4,42 @@ const path = require('node:path'); require('dotenv').config({ path: path.join(__dirname, '../.env') }); require('./shared/helpers/TypeScriptExtensions'); // ATTENTION : This line MUST be the second of this file -import chalk from 'chalk'; -import HttpManager from './managers/HttpManager'; +import * as fs from 'fs'; +import chalk from 'chalk'; +import HttpManager from './managers/HttpManager'; +import DojoBackendManager from './managers/DojoBackendManager'; +import Config from './config/Config'; -HttpManager.registerAxiosInterceptor(); +(async () => { + HttpManager.registerAxiosInterceptor(); -console.log(chalk.blue('Dojo Exercice Checker')); + console.log(chalk.blue('Dojo Exercice Checker')); -// Step 1: Read the dojo enonce file from the enonce repository -// Step 2: Download immutables files (maybe throw or show an error if the files have been modified ?) - Can be merged with step 1 -// Step 3: Run docker-compose file -// Step 4: Wait the end of the execution of the result container -// Step 5: Get the result from the volume -// Step 6: Check content requirements and content size -// Step 7: Upload and show the results \ No newline at end of file + /* + Step 1 & 2: + - Read the dojo enonce file from the enonce repository + - Download immutables files (maybe throw or show an error if the files have been modified ?) + */ + const exerciceEnonce = await DojoBackendManager.getExerciceEnonce(); + if ( !exerciceEnonce ) { + console.error(chalk.red(`Error while getting the exercice's enonce`)); + process.exit(1); + } + + exerciceEnonce.immutable.forEach(immutableFile => { + const filePath = `${ Config.filesFolder }/${ immutableFile.file_path }`.replace(/\/\//g, '/'); + fs.mkdirSync(path.dirname(filePath), { recursive: true }); + fs.writeFileSync(filePath, immutableFile.content, { encoding: 'base64' }); + }); + + + // Step 3: Run docker-compose file + // Step 4: Wait the end of the execution of the result container + // Step 5: Get the result from the volume + // Step 6: Check content requirements and content size + // Step 7: Upload and show the results +})(); + diff --git a/ExerciceChecker/src/config/Config.ts b/ExerciceChecker/src/config/Config.ts new file mode 100644 index 0000000000000000000000000000000000000000..363c28621b4b2338de28f3a77f5170d062260f5a --- /dev/null +++ b/ExerciceChecker/src/config/Config.ts @@ -0,0 +1,19 @@ +class Config { + public readonly filesFolder: string; + + public exercice: { + id: string; secret: string; + }; + + constructor() { + this.filesFolder = process.env.FILES_FOLDER || './'; + + this.exercice = { + id : process.env.DOJO_EXERCICE_ID || '', + secret: process.env.DOJO_SECRET || '' + }; + } +} + + +export default new Config(); diff --git a/ExerciceChecker/src/managers/DojoBackendManager.ts b/ExerciceChecker/src/managers/DojoBackendManager.ts index d64a25881c49bf67ddccb315ff2a08ba42033875..943bca397c3ea21e12f8d997036f30782f355287 100644 --- a/ExerciceChecker/src/managers/DojoBackendManager.ts +++ b/ExerciceChecker/src/managers/DojoBackendManager.ts @@ -1,11 +1,23 @@ import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; import ApiRoutes from '../sharedByClients/types/ApiRoutes'; +import axios from 'axios'; +import DojoResponse from '../shared/types/Dojo/DojoResponse'; +import ExerciceEnonce from '../sharedByClients/models/ExerciceEnonce'; +import Config from '../config/Config'; class DojoBackendManager { public getApiUrl(route: ApiRoutes): string { return `${ ClientsSharedConfig.apiURL }${ route }`; } + + public async getExerciceEnonce(): Promise<ExerciceEnonce | undefined> { + try { + return (await axios.get<DojoResponse<ExerciceEnonce>>(this.getApiUrl(ApiRoutes.EXERCICE_ENONCE).replace('{{id}}', Config.exercice.id))).data.data; + } catch ( error ) { + return undefined; + } + } } diff --git a/ExerciceChecker/src/managers/HttpManager.ts b/ExerciceChecker/src/managers/HttpManager.ts index 9cf17d86d269c27be5a92a164b68777acf269ac9..432e456dd35231502321f8f4d11b410f3dc1f0ef 100644 --- a/ExerciceChecker/src/managers/HttpManager.ts +++ b/ExerciceChecker/src/managers/HttpManager.ts @@ -1,6 +1,7 @@ import axios, { AxiosRequestHeaders } from 'axios'; import FormData from 'form-data'; import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; +import Config from '../config/Config'; class HttpManager { @@ -18,9 +19,13 @@ class HttpManager { } if ( config.url && (config.url.indexOf(ClientsSharedConfig.apiURL) !== -1) ) { + config.headers['Accept-Encoding'] = 'gzip'; + if ( config.data && Object.keys(config.data).length > 0 ) { config.headers['Content-Type'] = 'multipart/form-data'; } + + config.headers.Authorization = `ExerciceSecret ${ Config.exercice.secret }`; } return config; diff --git a/ExerciceChecker/src/shared b/ExerciceChecker/src/shared index c9154d42dac81311cf1957f0d75f806737849b40..bfca2c401e4b5ff69b0a515fd9dcab49d36ee212 160000 --- a/ExerciceChecker/src/shared +++ b/ExerciceChecker/src/shared @@ -1 +1 @@ -Subproject commit c9154d42dac81311cf1957f0d75f806737849b40 +Subproject commit bfca2c401e4b5ff69b0a515fd9dcab49d36ee212 diff --git a/ExerciceChecker/src/sharedByClients b/ExerciceChecker/src/sharedByClients index 8fe8e9417a527cf2182a9acc440e68b99024487e..b78ee5ffda1f10ffacf8cde47fbf45e76a3d9094 160000 --- a/ExerciceChecker/src/sharedByClients +++ b/ExerciceChecker/src/sharedByClients @@ -1 +1 @@ -Subproject commit 8fe8e9417a527cf2182a9acc440e68b99024487e +Subproject commit b78ee5ffda1f10ffacf8cde47fbf45e76a3d9094