Modif docker + ajout de la fonction de text aléatoire
This commit is contained in:
1
backend/.env
Normal file
1
backend/.env
Normal file
@@ -0,0 +1 @@
|
||||
PORT=3000
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user