diff --git a/ExpressAPI/src/config/Config.ts b/ExpressAPI/src/config/Config.ts index acf4e9d6de7341f7100d1e6c13814f3bd2be1a8a..83edf27abaa5442c746cdc427cccae875c2686c2 100644 --- a/ExpressAPI/src/config/Config.ts +++ b/ExpressAPI/src/config/Config.ts @@ -1,4 +1,7 @@ import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility'; +import { Exercice } from '../types/DatabaseTypes'; +import path from 'path'; +import fs from 'fs'; class Config { @@ -23,7 +26,7 @@ class Config { }; public exercice: { - maxSameName: number; resultsFolder: string; default: { description: string; visibility: string; }; + maxSameName: number; resultsFolder: string, pipelineResultsFolder: string; default: { description: string; visibility: string; }; }; public readonly userPasswordLength: number; @@ -73,9 +76,10 @@ class Config { }; this.exercice = { - maxSameName : Number(process.env.EXERCICE_MAX_SAME_NAME || 0), - resultsFolder: process.env.EXERCICE_RESULTS_FOLDER ?? '', //Do not use convertWithEnvVars() because it is used in the exercice creation and muste be interpreted at exercice runtime - default : { + maxSameName : Number(process.env.EXERCICE_MAX_SAME_NAME || 0), + resultsFolder : process.env.EXERCICE_RESULTS_FOLDER?.convertWithEnvVars() ?? '', + pipelineResultsFolder: process.env.EXERCICE_PIPELINE_RESULTS_FOLDER ?? '', //Do not use convertWithEnvVars() because it is used in the exercice creation and muste be interpreted at exercice runtime + default : { description: process.env.EXERCICE_DEFAULT_DESCRIPTION?.convertWithEnvVars() ?? '', visibility : process.env.EXERCICE_DEFAULT_VISIBILITY || GitlabVisibility.PRIVATE } @@ -84,6 +88,14 @@ class Config { this.userPasswordLength = Number(process.env.USER_PASSWORD_LENGTH || 0); this.userPasswordSaltRounds = Number(process.env.USER_PASSWORD_SALT_ROUNDS || 10); } + + public getResultsFolder(exercice: Exercice): string { + const folderPath = path.join(this.exercice.resultsFolder, exercice.enonceName, exercice.id); + + fs.mkdirSync(folderPath, { recursive: true }); + + return folderPath; + } } diff --git a/ExpressAPI/src/routes/ExerciceRoutes.ts b/ExpressAPI/src/routes/ExerciceRoutes.ts index 42cbff97a98872488819411b83f78f36e9c1b658..265212d4e77e34fd8c047af48ccfa89e251cb681 100644 --- a/ExpressAPI/src/routes/ExerciceRoutes.ts +++ b/ExpressAPI/src/routes/ExerciceRoutes.ts @@ -68,7 +68,7 @@ class ExerciceRoutes implements RoutesManager { await GitlabManager.addRepositoryVariable(repository.id, 'DOJO_EXERCICE_ID', exerciceId, false, true); await GitlabManager.addRepositoryVariable(repository.id, 'DOJO_SECRET', secret, false, true); - await GitlabManager.addRepositoryVariable(repository.id, 'DOJO_RESULTS_FOLDER', Config.exercice.resultsFolder, false, false); + await GitlabManager.addRepositoryVariable(repository.id, 'DOJO_RESULTS_FOLDER', Config.exercice.pipelineResultsFolder, false, false); break; } catch ( error ) {