File size: 696 Bytes
59724ed c29a8b7 3101956 59724ed 3101956 59724ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 7860;
const imageFolderPath = path.join(__dirname, 'api');
app.get('/', (req, res) => {
res.send('api');
});
app.get('/mm', (req, res) => {
const r18FolderPath = path.join(__dirname, 'api', 'mm');
const images = fs.readdirSync(r18FolderPath);
const randomImage = getRandomImage(images);
res.sendFile(path.join(r18FolderPath, randomImage));
});
function getRandomImage(images) {
const randomIndex = Math.floor(Math.random() * images.length);
return images[randomIndex];
}
app.listen(port, () => {
console.log(`App listening on port ${port}!`);
}); |