Compare commits
No commits in common. "2235372c645af307e2baf4ee7293157ddae4002f" and "988afab81c0de4fbc4f6d8c46b64c1d45f1a90cf" have entirely different histories.
2235372c64
...
988afab81c
@ -51,12 +51,6 @@ router.route("/filter/:term")
|
||||
res.json(result).status(200).end();
|
||||
});
|
||||
})
|
||||
router.route("/random/:count")
|
||||
.get(passport.authenticate("jwt", { session: false }), (req, res) => {
|
||||
database.albums.randomCovers(req.params.count, 64, (result) => {
|
||||
res.json(result).status(200).end();
|
||||
});
|
||||
})
|
||||
|
||||
router.route("/:id")
|
||||
.get(checkGuest, (req, res) => {
|
||||
|
@ -310,27 +310,4 @@ exports.empty = function (callback) {
|
||||
.toArray((err, result) => {
|
||||
callback(result.filter(f => !f.tracks || f.tracks.length == 0));
|
||||
});
|
||||
};
|
||||
|
||||
exports.randomCovers = function (count, size, callback) {
|
||||
dbo
|
||||
.collection("albums")
|
||||
.find({ "covers.cover64": { $exists: true } })
|
||||
.project({ "covers.cover64": true })
|
||||
.toArray((err, result) => {
|
||||
if (result.length > count) {
|
||||
let res = [];
|
||||
while (count-- > 0) {
|
||||
let rnd = randomNumber(0, result.length);
|
||||
res.push(result[rnd]);
|
||||
}
|
||||
callback(res);
|
||||
} else {
|
||||
callback(result);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function randomNumber(min, max) {
|
||||
return Math.floor(Math.random() * (max - min) + min);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user