fancy-banner. fix #18 #21
@ -51,6 +51,12 @@ 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) => {
|
||||
|
@ -311,3 +311,26 @@ exports.empty = function (callback) {
|
||||
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