Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
7faec524da | |||
cd7e2e7a0f | |||
c07984c506 | |||
2235372c64 | |||
|
94a6893444 | ||
|
cd0b9a7f55 | ||
|
97fcdcce5d | ||
|
e6614d0805 | ||
|
988afab81c |
@ -51,6 +51,12 @@ router.route("/filter/:term")
|
|||||||
res.json(result).status(200).end();
|
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")
|
router.route("/:id")
|
||||||
.get(checkGuest, (req, res) => {
|
.get(checkGuest, (req, res) => {
|
||||||
|
@ -96,7 +96,7 @@ router.route("/:id/stream")
|
|||||||
router.route("/:id/stream/:rate/:audioIndex")
|
router.route("/:id/stream/:rate/:audioIndex")
|
||||||
.get((req, res) => {
|
.get((req, res) => {
|
||||||
if (!server.lists.video_quality.includes(req.params.rate)) {
|
if (!server.lists.video_quality.includes(req.params.rate)) {
|
||||||
req.end();
|
res.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
let video = getFileName(req);
|
let video = getFileName(req);
|
||||||
|
@ -101,7 +101,7 @@ app.use(fileUpload({
|
|||||||
}));
|
}));
|
||||||
const corsOptions = {
|
const corsOptions = {
|
||||||
origin: (origin, callback) => {
|
origin: (origin, callback) => {
|
||||||
if (!origin || config.allowed_domains.indexOf(origin.replace(/:\d*$/g, "")) !== -1) {
|
if (!origin || config.domain == origin.replace(/:\d*$/g, "") || config.allowed_domains.indexOf(origin.replace(/:\d*$/g, "")) !== -1) {
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
} else {
|
} else {
|
||||||
database.system.domains((domains) => {
|
database.system.domains((domains) => {
|
||||||
|
@ -311,3 +311,26 @@ exports.empty = function (callback) {
|
|||||||
callback(result.filter(f => !f.tracks || f.tracks.length == 0));
|
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,9 +97,16 @@ exports.mostListened = function (filter, callback) {
|
|||||||
}
|
}
|
||||||
}, { $match: { "album.visibility": { $in: filter } } });
|
}, { $match: { "album.visibility": { $in: filter } } });
|
||||||
} else {
|
} else {
|
||||||
aggregate.unshift({ $match: { type: 'track' } });
|
dbo.collection("history")
|
||||||
}
|
.find()
|
||||||
aggregate.push({ $sort: { counter: -1, _id: -1 } }, { $limit: 6 })
|
.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 })
|
||||||
|
|
||||||
dbo
|
dbo
|
||||||
.collection("history")
|
.collection("history")
|
||||||
@ -110,4 +117,7 @@ exports.mostListened = function (filter, callback) {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
callback(result);
|
callback(result);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user