Sharing #1
@ -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": [
|
||||||
|
@ -143,8 +143,7 @@ router.route("/:id/share")
|
|||||||
let album_id = req.params.id
|
let album_id = req.params.id
|
||||||
if (req.user.roles.indexOf("admin") > -1) {
|
if (req.user.roles.indexOf("admin") > -1) {
|
||||||
let item = {
|
let item = {
|
||||||
object_id: new ObjectId(album_id),
|
object_id: new ObjectId(album_id)
|
||||||
type: "album"
|
|
||||||
}
|
}
|
||||||
database.share.delete(item, () => {
|
database.share.delete(item, () => {
|
||||||
res.status(200).end();
|
res.status(200).end();
|
||||||
|
@ -145,8 +145,7 @@ router.route("/:id/share")
|
|||||||
let box_id = req.params.id
|
let box_id = req.params.id
|
||||||
if (req.user.roles.indexOf("admin") > -1) {
|
if (req.user.roles.indexOf("admin") > -1) {
|
||||||
let item = {
|
let item = {
|
||||||
object_id: new ObjectId(box_id),
|
object_id: new ObjectId(box_id)
|
||||||
type: "box"
|
|
||||||
}
|
}
|
||||||
database.share.delete(item, () => {
|
database.share.delete(item, () => {
|
||||||
res.status(200).end();
|
res.status(200).end();
|
||||||
|
@ -12,5 +12,6 @@ exports.systemRouter = require("./system")
|
|||||||
exports.statusRouter = require("./status");
|
exports.statusRouter = require("./status");
|
||||||
exports.settingsRouter = require("./settings");
|
exports.settingsRouter = require("./settings");
|
||||||
exports.searchRouter = require("./search");
|
exports.searchRouter = require("./search");
|
||||||
|
exports.shareRouter = require("./share");
|
||||||
// exports.activitypubRouter = require("./activitypub");
|
// exports.activitypubRouter = require("./activitypub");
|
||||||
// exports.wellknownRouter = require("./well-known");
|
// exports.wellknownRouter = require("./well-known");
|
12
router/share.js
Normal file
12
router/share.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
console.log("router/share INIT");
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
@ -135,6 +135,7 @@ app.use("/api/search", router.searchRouter);
|
|||||||
app.use("/api/settings", router.settingsRouter);
|
app.use("/api/settings", router.settingsRouter);
|
||||||
app.use("/api/status", router.statusRouter);
|
app.use("/api/status", router.statusRouter);
|
||||||
app.use("/api/system", router.systemRouter);
|
app.use("/api/system", router.systemRouter);
|
||||||
|
app.use("/api/shares", router.shareRouter);
|
||||||
app.use("/api/tracks", router.trackRouter);
|
app.use("/api/tracks", router.trackRouter);
|
||||||
app.use("/api/user", router.loginRouter);
|
app.use("/api/user", router.loginRouter);
|
||||||
app.use("/api/user", router.userRouter);
|
app.use("/api/user", router.userRouter);
|
||||||
|
@ -2,16 +2,46 @@ const redis = require("../redis")
|
|||||||
|
|
||||||
const { ObjectId } = require('mongodb');
|
const { ObjectId } = require('mongodb');
|
||||||
const connector = require("./CONNECTOR");
|
const connector = require("./CONNECTOR");
|
||||||
|
const database = require("./index");
|
||||||
var dbo;
|
var dbo;
|
||||||
connector.connect().then((ret) => {
|
connector.connect().then((ret) => {
|
||||||
dbo = ret;
|
dbo = ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
exports.byId = function (id, callback) {
|
exports.byId = function (id, callback) {
|
||||||
|
let _id;
|
||||||
|
try {
|
||||||
|
_id = ObjectId(id);
|
||||||
|
} catch {
|
||||||
|
cb(callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
dbo.collection("shares")
|
dbo.collection("shares")
|
||||||
.findOne({ _id: ObjectId(id) })
|
.findOne({ _id: _id })
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
callback(result);
|
if (result) {
|
||||||
|
switch (result.type) {
|
||||||
|
case "album":
|
||||||
|
console.log(result.type);
|
||||||
|
database.albums.byId(result.object_id, undefined, (album) => {
|
||||||
|
result.object = album;
|
||||||
|
cb(callback, result);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "box":
|
||||||
|
console.log(result.type);
|
||||||
|
database.boxes.byId(result.object_id, undefined, (box) => {
|
||||||
|
result.object = box;
|
||||||
|
cb(callback, result);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log(result.type);
|
||||||
|
cb(callback, result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cb(callback);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +81,12 @@ exports.delete = function (item, callback) {
|
|||||||
dbo.collection("shares")
|
dbo.collection("shares")
|
||||||
.deleteMany({ object_id: ObjectId(item.object_id) }, (err) => {
|
.deleteMany({ object_id: ObjectId(item.object_id) }, (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
if (callback) {
|
cb(callback);
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function cb(callback, value) {
|
||||||
|
if (callback) {
|
||||||
|
callback(value);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user