wip sharing api
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Artem Anufrij
2023-02-16 18:19:42 +01:00
parent a75f7975e7
commit 50c682e31f
7 changed files with 56 additions and 12 deletions

View File

@@ -2,16 +2,46 @@ const redis = require("../redis")
const { ObjectId } = require('mongodb');
const connector = require("./CONNECTOR");
const database = require("./index");
var dbo;
connector.connect().then((ret) => {
dbo = ret;
});
exports.byId = function (id, callback) {
let _id;
try {
_id = ObjectId(id);
} catch {
cb(callback);
return;
}
dbo.collection("shares")
.findOne({ _id: ObjectId(id) })
.findOne({ _id: _id })
.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")
.deleteMany({ object_id: ObjectId(item.object_id) }, (err) => {
if (err) throw err;
if (callback) {
callback();
}
cb(callback);
});
}
function cb(callback, value) {
if (callback) {
callback(value);
}
}