Browse Source

IT WORKS

canon
Hazel Levine 3 years ago
parent
commit
1f9a46afdc
3 changed files with 9 additions and 14 deletions
  1. +1
    -1
      .gitignore
  2. +3
    -6
      app.js
  3. +5
    -7
      src/imagefile.js

+ 1
- 1
.gitignore View File

@ -1,5 +1,5 @@
private/*
uploads/*
public/uploads/*
# Created by https://www.gitignore.io/api/node,emacs


+ 3
- 6
app.js View File

@ -10,7 +10,7 @@ const app = express();
const dbURL = `mongodb://${creds.mongoUser}:${creds.mongoPass}@localhost:27017/bunnies`;
mongoose.connect(dbURL);
app.use('/', routes);
app.use(express.static('public'));
app.use(express.static(__dirname + '/public'));
app.get('/images', (req, res) => {
routes.getImages((err, genres) => {
@ -31,11 +31,8 @@ app.get('/images/:id', (req, res) => {
});
app.get('/random', (req, res) => {
routes.getImageRandom((err, genres) => {
if (err) {
throw err;
}
res.send(genres.path);
routes.getImageRandom((genres) => {
res.redirect(genres);
});
});


+ 5
- 7
src/imagefile.js View File

@ -29,8 +29,6 @@ function getAllFiles(collection, cb) {
});
cb(files);
});
return files;
}
router.getImages = (callback, limit) => {
@ -45,11 +43,11 @@ router.addImage = (image, callback) => {
Image.create(image, callback);
}
router.getImageRandom = (id, callback) => {
Image.count().exec((err, count) => {
let random = Math.floor(Math.random() * count);
Image.findOne().skip(random);
router.getImageRandom = (callback) => {
let file = '';
getAllFiles(Image, (filesOut) => {
file = filesOut[Math.floor(Math.random()*filesOut.length)];
callback(file);
});
}


Loading…
Cancel
Save