Update app.js

This commit is contained in:
nune 2024-12-19 23:44:51 -05:00 committed by GitHub
parent 22bb0aa14f
commit ef98407318
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

19
app.js
View File

@ -8,6 +8,25 @@ const PORT = process.env.PORT || 3000;
app.use(express.static('public'));
app.use(cookieParser());
// Environment variable to toggle ASCII art
const showAsciiArt = process.env.SHOW_ASCII_ART === 'true';
const asciiArtFolder = process.env.ASCII_ART_FOLDER || path.join(__dirname, 'ascii');
// Get ASCII art files
const asciiArtFiles = showAsciiArt ? fs.readdirSync(asciiArtFolder).filter(file => file.endsWith('.txt')) : [];
// Serve a random ASCII art
app.get('/ascii', (req, res) => {
if (!showAsciiArt || asciiArtFiles.length === 0) {
res.json({ enabled: false });
return;
}
const randomFile = asciiArtFiles[Math.floor(Math.random() * asciiArtFiles.length)];
const art = fs.readFileSync(path.join(asciiArtFolder, randomFile), 'utf-8');
res.json({ enabled: true, art });
});
const autoCopyDefault = process.env.AUTO_COPY_DEFAULT === 'true';
app.get('/auto-copy-default', (req, res) => {