diff --git a/config.json b/config.json index 15616a3..2f2b3bf 100644 --- a/config.json +++ b/config.json @@ -10,12 +10,12 @@ "http://localhost" ], "database": { - "host": "database", + "host": "localhost", "port": 27017, "name": "webplay" }, "redis": { - "host": "redis", + "host": "localhost", "port": 6379 }, "album_cover_files": [ diff --git a/router/album.js b/router/album.js index 036ea28..76e5f53 100644 --- a/router/album.js +++ b/router/album.js @@ -120,14 +120,15 @@ router.route("/:id/share") .post(passport.authenticate("jwt", { session: false }), (req, res) => { let album_id = req.params.id process.stdout.write("router/album POST albums share " + album_id + "\n"); - database.albums.byId(album_id, undefined, (result) => { - if (result != undefined && req.user.roles.indexOf("admin") > -1) { + database.albums.byId(album_id, undefined, (album) => { + if (album != undefined && req.user.roles.indexOf("admin") > -1) { database.share.exists(album_id, result => { if (result == null) { let item = { user_id: req.user._id, object_id: new ObjectId(album_id), - type: "album" + type: "album", + cover: album.covers.cover32 } database.share.add(item, (result) => { res.json(result).status(200).end(); diff --git a/router/box.js b/router/box.js index c9d17b3..b23707c 100644 --- a/router/box.js +++ b/router/box.js @@ -122,14 +122,15 @@ router.route("/:id/share") .post(passport.authenticate("jwt", { session: false }), (req, res) => { let box_id = req.params.id process.stdout.write("router/box POST box share " + box_id + "\n"); - database.boxes.byId(box_id, undefined, (result) => { - if (result != undefined && req.user.roles.indexOf("admin") > -1) { + database.boxes.byId(box_id, undefined, (box) => { + if (box != undefined && req.user.roles.indexOf("admin") > -1) { database.share.exists(box_id, result => { if (result == null) { let item = { user_id: req.user._id, object_id: new ObjectId(box_id), - type: "box" + type: "box", + cover: box.covers.cover32 } database.share.add(item, (result) => { res.json(result).status(200).end(); diff --git a/services/database/boxes.js b/services/database/boxes.js index 8575b21..4b11cf3 100644 --- a/services/database/boxes.js +++ b/services/database/boxes.js @@ -15,7 +15,6 @@ let box_project = { "videos.box_id": false, "videos.mime": false, path: false, - "covers.cover32": false, } } let boxes_project = { diff --git a/services/database/share.js b/services/database/share.js index 14fc1fc..4af7beb 100644 --- a/services/database/share.js +++ b/services/database/share.js @@ -45,6 +45,7 @@ exports.byId = function (id, callback) { exports.collection = function (callback) { dbo.collection("shares") .find({}) + .sort({ type: 1 }) .toArray((err, result) => { if (err) throw err; cb(callback, result); @@ -55,7 +56,7 @@ exports.exists = function (object_id, callback) { dbo.collection("shares") .findOne({ object_id: ObjectId(object_id) }) .then(result => { - callback(result); + cp(callback, result); }); } @@ -74,7 +75,7 @@ exports.add = function (item, callback) { ]) .toArray((err, result) => { if (err) throw err; - callback(result[0]); + cp(callback, result[0]); }) } });