Browse Source

IT WORKS

canon
Hazel Levine 3 years ago
parent
commit
1f9a46afdc
  1. 2
      .gitignore
  2. 9
      app.js
  3. 12
      src/imagefile.js

2
.gitignore

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

9
app.js

@ -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);
});
});

12
src/imagefile.js

@ -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