From 5f9d43842029c1012c4a75f69777f54bc07b83ba Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Fri, 17 Feb 2023 10:21:58 +0100 Subject: [PATCH] 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) })