Merge pull request 'save-and-restore-progress-for-audio fix #12' (#14) from save-and-restore-progress-for-audio into main
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #14
This commit is contained in:
commit
159aac6a2e
@ -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": "127.0.0.1",
|
||||||
"port": 6379
|
"port": 6379
|
||||||
},
|
},
|
||||||
"album_cover_files": [
|
"album_cover_files": [
|
||||||
|
@ -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) => {
|
||||||
|
@ -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;
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user