From 5f9d43842029c1012c4a75f69777f54bc07b83ba Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Fri, 17 Feb 2023 10:21:58 +0100 Subject: [PATCH 1/3] share: provide collection api fix#2 --- config.json | 4 ++-- router/share.js | 18 ++++++++++++++---- services/database/share.js | 9 +++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) 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/share.js b/router/share.js index 0e4d774..c387a40 100644 --- a/router/share.js +++ b/router/share.js @@ -3,10 +3,20 @@ var express = require("express"); var router = new express.Router(); const database = require("../services/database"); -router.route("/:id").get((req, res) => { - database.share.byId(req.params.id, (result) => { - res.json(result).status(200).end(); +const server = require("../server"); +var passport = server.passport; + +router.route("/") + .get(passport.authenticate("jwt", { session: false }), (req, res) => { + database.share.collection(result => { + res.json(result).status(200).end(); + }) + }) +router.route("/:id") + .get((req, res) => { + database.share.byId(req.params.id, result => { + res.json(result).status(200).end(); }); -}); + }); module.exports = router; diff --git a/services/database/share.js b/services/database/share.js index 86fe374..14fc1fc 100644 --- a/services/database/share.js +++ b/services/database/share.js @@ -42,6 +42,15 @@ exports.byId = function (id, callback) { }); } +exports.collection = function (callback) { + dbo.collection("shares") + .find({}) + .toArray((err, result) => { + if (err) throw err; + cb(callback, result); + }); +} + exports.exists = function (object_id, callback) { dbo.collection("shares") .findOne({ object_id: ObjectId(object_id) }) -- 2.45.2 From 481966768d4a38c0a4e4ea506e723c89806c2670 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Fri, 17 Feb 2023 10:23:34 +0100 Subject: [PATCH 2/3] code style fix #2 --- router/share.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/share.js b/router/share.js index c387a40..65ce517 100644 --- a/router/share.js +++ b/router/share.js @@ -11,7 +11,7 @@ router.route("/") database.share.collection(result => { res.json(result).status(200).end(); }) - }) + }); router.route("/:id") .get((req, res) => { database.share.byId(req.params.id, result => { -- 2.45.2 From 1c8163c8351fdcd6499dd3c16d4cbc2363d545f5 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Fri, 17 Feb 2023 10:24:41 +0100 Subject: [PATCH 3/3] config for production --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index 2f2b3bf..15616a3 100644 --- a/config.json +++ b/config.json @@ -10,12 +10,12 @@ "http://localhost" ], "database": { - "host": "localhost", + "host": "database", "port": 27017, "name": "webplay" }, "redis": { - "host": "localhost", + "host": "redis", "port": 6379 }, "album_cover_files": [ -- 2.45.2