Compare commits
1 Commits
2235372c64
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| c2817fe0b3 |
@@ -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) => {
|
||||
|
||||
@@ -311,26 +311,3 @@ 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);
|
||||
}
|
||||
@@ -97,16 +97,9 @@ exports.mostListened = function (filter, callback) {
|
||||
}
|
||||
}, { $match: { "album.visibility": { $in: filter } } });
|
||||
} else {
|
||||
dbo.collection("history")
|
||||
.find()
|
||||
.project({ _id: true })
|
||||
.sort({ _id: -1 })
|
||||
.limit(1000)
|
||||
.toArray((err, ids) => {
|
||||
let arr = ids.map(h => h._id);
|
||||
|
||||
aggregate.unshift({ $match: { type: 'track', _id: { $in: arr } } });
|
||||
aggregate.push({ $sort: { counter: -1 } }, { $limit: 6 })
|
||||
aggregate.unshift({ $match: { type: 'track' } });
|
||||
}
|
||||
aggregate.push({ $sort: { counter: -1, _id: -1 } }, { $limit: 6 })
|
||||
|
||||
dbo
|
||||
.collection("history")
|
||||
@@ -117,7 +110,4 @@ exports.mostListened = function (filter, callback) {
|
||||
if (err) throw err;
|
||||
callback(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user