Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d0272351d | ||
|
|
94a6893444 | ||
|
|
cd0b9a7f55 | ||
|
|
97fcdcce5d | ||
|
|
e6614d0805 | ||
|
|
988afab81c |
@@ -10,12 +10,12 @@
|
|||||||
"http://localhost"
|
"http://localhost"
|
||||||
],
|
],
|
||||||
"database": {
|
"database": {
|
||||||
"host": "database",
|
"host": "localhost",
|
||||||
"port": 27017,
|
"port": 27017,
|
||||||
"name": "webplay"
|
"name": "webplay"
|
||||||
},
|
},
|
||||||
"redis": {
|
"redis": {
|
||||||
"host": "redis",
|
"host": "localhost",
|
||||||
"port": 6379
|
"port": 6379
|
||||||
},
|
},
|
||||||
"album_cover_files": [
|
"album_cover_files": [
|
||||||
|
|||||||
331
package-lock.json
generated
331
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@
|
|||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
"mongodb": "^4.14.0",
|
"mongodb": "^6.1.0",
|
||||||
"music-metadata": "^7.13.3",
|
"music-metadata": "^7.13.3",
|
||||||
"node-fdkaac": "^1.4.1",
|
"node-fdkaac": "^1.4.1",
|
||||||
"node-id3": "^0.2.6",
|
"node-id3": "^0.2.6",
|
||||||
|
|||||||
@@ -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) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { MongoClient } = require('mongodb');
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
const server = require("../../server");
|
const server = require("../../server");
|
||||||
const config = server.config;
|
const config = server.config;
|
||||||
|
|
||||||
@@ -14,7 +14,10 @@ exports.connect = async function () {
|
|||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
console.log("DB CONNECTING:" + config.database.host + ":" + config.database.port)
|
console.log("DB CONNECTING:" + config.database.host + ":" + config.database.port)
|
||||||
const client = await MongoClient.connect(url);
|
const client = await MongoClient.connect(url, (err, db)=> {
|
||||||
|
console.log("DB Connected")
|
||||||
|
}
|
||||||
|
);
|
||||||
dbo = client.db(database);
|
dbo = client.db(database);
|
||||||
return dbo;
|
return dbo;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -310,4 +310,27 @@ exports.empty = function (callback) {
|
|||||||
.toArray((err, result) => {
|
.toArray((err, result) => {
|
||||||
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,17 +97,27 @@ 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
|
||||||
|
.collection("history")
|
||||||
|
.aggregate(aggregate, {
|
||||||
|
allowDiskUse: true
|
||||||
|
})
|
||||||
|
.toArray((err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
callback(result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
dbo
|
|
||||||
.collection("history")
|
|
||||||
.aggregate(aggregate, {
|
|
||||||
allowDiskUse: true
|
|
||||||
})
|
|
||||||
.toArray((err, result) => {
|
|
||||||
if (err) throw err;
|
|
||||||
callback(result);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user