Compare commits

...

5 Commits

Author SHA1 Message Date
2235372c64 Merge pull request 'fancy-banner. fix #18' (#21) from fancy-banner into main
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #21
2023-09-27 21:46:39 +02:00
Artem Anufrij
94a6893444 code style
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2023-09-27 21:44:58 +02:00
Artem Anufrij
cd0b9a7f55 code design
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-27 21:43:52 +02:00
Artem Anufrij
97fcdcce5d add get api for random album covers
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-27 16:52:37 +02:00
Artem Anufrij
e6614d0805 add get api for random album covers
All checks were successful
continuous-integration/drone/push Build is passing
2023-09-27 16:52:28 +02:00
2 changed files with 30 additions and 1 deletions

View File

@ -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) => {

View File

@ -310,4 +310,27 @@ 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);
}