Modif docker + ajout de la fonction de text aléatoire

This commit is contained in:
ElPoyo
2025-09-29 16:48:38 +02:00
parent 5d0993bda3
commit 4e11fd9a06
5 changed files with 43 additions and 7 deletions

1
backend/.env Normal file
View File

@@ -0,0 +1 @@
PORT=3000

View File

@@ -21,7 +21,7 @@ app.use(cors())
app.use(express.json())
// Chemin vers le dossier texts (dossier parent)
const TEXTS_DIR = process.env.TEXTS_PATH || path.join(__dirname, '..', 'texts')
const TEXTS_DIR = process.env.TEXTS_PATH || "C:\\Users\\paulf\\Documents\\texts"
/**
* Service pour scanner et charger les textes depuis le dossier texts/
@@ -322,6 +322,15 @@ class TextService {
categories: categories.size
}
}
async getRandomText() {
const allTexts = await this.scanTexts()
if (allTexts.length === 0) {
throw new Error('Aucun texte disponible')
}
const randomIndex = Math.floor(Math.random() * allTexts.length)
return allTexts[randomIndex]
}
}
// Instance du service