Compare commits
21 Commits
2d1e117b66
...
mongodb-6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d0272351d | ||
|
|
94a6893444 | ||
|
|
cd0b9a7f55 | ||
|
|
97fcdcce5d | ||
|
|
e6614d0805 | ||
|
|
988afab81c | ||
| 94007dc7da | |||
|
|
7145a0b1cd | ||
| 77948e93b6 | |||
|
|
07cc31ede3 | ||
|
|
1051f05cce | ||
| 159aac6a2e | |||
|
|
85367e844d | ||
|
|
d7879a654a | ||
| 449accb003 | |||
| 392b6c007a | |||
|
|
a2e01bdbb7 | ||
|
|
831597f015 | ||
|
|
e4c1f14300 | ||
| 2c4e661b9d | |||
|
|
4aea43a8bb |
@@ -4,7 +4,7 @@
|
|||||||
WebPlay Server provides REST-API for your media files. In then next step, you can use [WebPlay Client](/WebPlay/client) to access your content.
|
WebPlay Server provides REST-API for your media files. In then next step, you can use [WebPlay Client](/WebPlay/client) to access your content.
|
||||||
|
|
||||||
## How to install your own instance (Docker)
|
## How to install your own instance (Docker)
|
||||||
[Documentation](/WebPlay/docker#requirements)
|
[Documentation](/WebPlay/docker#setup-your-own-webplay-instance)
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
Join our Matrix room: <a href="https://matrix.to/#/#WebPlay:matrix.anufrij.de">#WebPlay:matrix.anufrij.de</a>
|
Join our Matrix room: <a href="https://matrix.to/#/#WebPlay:matrix.anufrij.de">#WebPlay:matrix.anufrij.de</a>
|
||||||
|
|||||||
@@ -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": [
|
||||||
|
|||||||
717
package-lock.json
generated
717
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@@ -10,31 +10,31 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"body-parser": "^1.19.1",
|
"body-parser": "^1.20.1",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.17.2",
|
"express": "^4.18.2",
|
||||||
"express-fileupload": "^1.3.1",
|
"express-fileupload": "^1.4.0",
|
||||||
"express-session": "^1.17.2",
|
"express-session": "^1.17.3",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"mime-types": "^2.1.34",
|
"mime-types": "^2.1.35",
|
||||||
"mongodb": "^4.3.1",
|
"mongodb": "^6.1.0",
|
||||||
"music-metadata": "^7.11.8",
|
"music-metadata": "^7.13.3",
|
||||||
"node-fdkaac": "^1.4.1",
|
"node-fdkaac": "^1.4.1",
|
||||||
"node-id3": "^0.2.3",
|
"node-id3": "^0.2.6",
|
||||||
"node-lame": "^1.3.2",
|
"node-lame": "^1.3.2",
|
||||||
"passport": "^0.5.2",
|
"passport": "^0.6.0",
|
||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.1",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"redis": "^4.5.1",
|
"redis": "^4.6.4",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"sharp": "0.27.2",
|
"sharp": "0.27.2",
|
||||||
"socket.io": "^4.4.1",
|
"socket.io": "^4.6.0",
|
||||||
"systeminformation": "^5.11.2"
|
"systeminformation": "^5.17.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"nodemon": "^2.0.15"
|
"nodemon": "^2.0.20"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) => {
|
||||||
@@ -127,6 +133,7 @@ router.route("/:id/share")
|
|||||||
let item = {
|
let item = {
|
||||||
user_id: req.user._id,
|
user_id: req.user._id,
|
||||||
object_id: new ObjectId(album_id),
|
object_id: new ObjectId(album_id),
|
||||||
|
title: album.title,
|
||||||
type: "album",
|
type: "album",
|
||||||
cover: album.covers.cover32
|
cover: album.covers.cover32
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ router.route("/:id/share")
|
|||||||
let item = {
|
let item = {
|
||||||
user_id: req.user._id,
|
user_id: req.user._id,
|
||||||
object_id: new ObjectId(box_id),
|
object_id: new ObjectId(box_id),
|
||||||
|
title: box.title,
|
||||||
type: "box",
|
type: "box",
|
||||||
cover: box.covers.cover32
|
cover: box.covers.cover32
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ router
|
|||||||
if (radio) {
|
if (radio) {
|
||||||
if (req.files.file) {
|
if (req.files.file) {
|
||||||
resize_image_for_radio(req.files.file.data, (result) => {
|
resize_image_for_radio(req.files.file.data, (result) => {
|
||||||
radio.cover32 = result.cover32;
|
radio.covers.cover32 = result.cover32;
|
||||||
radio.cover64 = result.cover64;
|
radio.covers.cover64 = result.cover64;
|
||||||
radio.cover128 = result.cover128;
|
radio.covers.cover128 = result.cover128;
|
||||||
database.radios.update(radio);
|
database.radios.update(radio);
|
||||||
res.json(radio).end();
|
res.json(radio).end();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -138,11 +138,6 @@ router
|
|||||||
|
|
||||||
router
|
router
|
||||||
.route("/history")
|
.route("/history")
|
||||||
.get(passport.authenticate("jwt", { session: false }), (req, res) => {
|
|
||||||
database.historyList(req.user._id, result => {
|
|
||||||
res.json(result).end();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.post(passport.authenticate("jwt", { session: false }), (req, res) => {
|
.post(passport.authenticate("jwt", { session: false }), (req, res) => {
|
||||||
let item = req.body;
|
let item = req.body;
|
||||||
item.userId = req.user._id;
|
item.userId = req.user._id;
|
||||||
@@ -159,6 +154,31 @@ router
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/progress")
|
||||||
|
.post(passport.authenticate("jwt", { session: false }), (req, res) => {
|
||||||
|
let item = req.body;
|
||||||
|
item.userId = req.user._id;
|
||||||
|
database.progress.update(item);
|
||||||
|
res.status(200).end();
|
||||||
|
});
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/progress/:parent")
|
||||||
|
.get(passport.authenticate("jwt", { session: false }), (req, res) => {
|
||||||
|
database.progress.get(req.params.parent, result => {
|
||||||
|
res.json(result).end();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.delete(passport.authenticate("jwt", { session: false }), (req, res) => {
|
||||||
|
let item = {
|
||||||
|
parentId: req.params.parent,
|
||||||
|
userId: req.user._id
|
||||||
|
}
|
||||||
|
database.progress.delete(item);
|
||||||
|
res.status(200).end();
|
||||||
|
});
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/settings")
|
.route("/settings")
|
||||||
.put(passport.authenticate("jwt", { session: false }), (req, res) => {
|
.put(passport.authenticate("jwt", { session: false }), (req, res) => {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const status = {
|
|||||||
process.stdout.write("server DEF arrays\n");
|
process.stdout.write("server DEF arrays\n");
|
||||||
const lists = {
|
const lists = {
|
||||||
audio_quality: ["64", "96", "128", "192", "256", "320"],
|
audio_quality: ["64", "96", "128", "192", "256", "320"],
|
||||||
video_quality: ["480", "720", "1080"],
|
video_quality: ["240", "360", "480", "720", "1080"],
|
||||||
user_role: ["admin", "moderator", "user"],
|
user_role: ["admin", "moderator", "user"],
|
||||||
lang: ["ENG", "GER", "RUS"],
|
lang: ["ENG", "GER", "RUS"],
|
||||||
visibility: ["global", "instance", "owner", "hidden"]
|
visibility: ["global", "instance", "owner", "hidden"]
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -62,6 +62,9 @@ exports.artists = artists;
|
|||||||
const boxes = require("./boxes");
|
const boxes = require("./boxes");
|
||||||
exports.boxes = boxes;
|
exports.boxes = boxes;
|
||||||
|
|
||||||
|
const progress = require("./progress");
|
||||||
|
exports.progress = progress;
|
||||||
|
|
||||||
const videos = require("./videos");
|
const videos = require("./videos");
|
||||||
exports.videos = videos;
|
exports.videos = videos;
|
||||||
|
|
||||||
|
|||||||
27
services/database/progress.js
Normal file
27
services/database/progress.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
const { ObjectId } = require('mongodb');
|
||||||
|
const connector = require("./CONNECTOR");
|
||||||
|
var dbo;
|
||||||
|
connector.connect().then((ret) => {
|
||||||
|
dbo = ret;
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.get = function (parentId, callback) {
|
||||||
|
dbo.collection("progress")
|
||||||
|
.findOne({ parentId: parentId }, (err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
callback(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.update = function (item) {
|
||||||
|
dbo.collection("progress").deleteMany({ userId: ObjectId(item.userId), parentId: item.parentId }, () => {
|
||||||
|
dbo.collection("progress").insertOne(item, (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.delete = function (item) {
|
||||||
|
dbo.collection("progress").deleteMany({ userId: ObjectId(item.userId), parentId: item.parentId }, (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -13,6 +13,9 @@ exports.collection = function (callback) {
|
|||||||
.toArray((err, result) => {
|
.toArray((err, result) => {
|
||||||
result.forEach(item => {
|
result.forEach(item => {
|
||||||
item.type = "radio";
|
item.type = "radio";
|
||||||
|
if (!item.covers) {
|
||||||
|
item.covers = {};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
callback(result);
|
callback(result);
|
||||||
});
|
});
|
||||||
@@ -23,6 +26,9 @@ exports.byId = function (id, callback) {
|
|||||||
.collection("radios")
|
.collection("radios")
|
||||||
.findOne({ _id: ObjectId(id) }, (err, result) => {
|
.findOne({ _id: ObjectId(id) }, (err, result) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
if (!result.covers) {
|
||||||
|
result.covers = {};
|
||||||
|
}
|
||||||
callback(result);
|
callback(result);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -63,9 +69,7 @@ exports.update = function (radio, callback) {
|
|||||||
$set: {
|
$set: {
|
||||||
name: radio.name,
|
name: radio.name,
|
||||||
url: radio.url,
|
url: radio.url,
|
||||||
cover32: radio.cover32,
|
covers: radio.covers
|
||||||
cover64: radio.cover64,
|
|
||||||
cover128: radio.cover128
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ upsert: false },
|
{ upsert: false },
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ exports.exists = function (object_id, callback) {
|
|||||||
dbo.collection("shares")
|
dbo.collection("shares")
|
||||||
.findOne({ object_id: ObjectId(object_id) })
|
.findOne({ object_id: ObjectId(object_id) })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
cp(callback, result);
|
cb(callback, result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ exports.add = function (item, callback) {
|
|||||||
])
|
])
|
||||||
.toArray((err, result) => {
|
.toArray((err, result) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
cp(callback, result[0]);
|
cb(callback, result[0]);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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