|
@@ -44,32 +44,54 @@ module.exports = { register: app => {
|
|
|
const result = Security.removeFromSession(req, req.params.id);
|
|
const result = Security.removeFromSession(req, req.params.id);
|
|
|
app.routerUtils.jsonResponse(res, result);
|
|
app.routerUtils.jsonResponse(res, result);
|
|
|
});
|
|
});
|
|
|
- app.router.del("/api/media/:id/tag/:tag", async (req, res) => {
|
|
|
|
|
|
|
+ app.router.post("/api/media/:id/tag/del/:tag", async (req, res) => {
|
|
|
app.routerUtils.onApiRequest(req, res);
|
|
app.routerUtils.onApiRequest(req, res);
|
|
|
if (!req.params.id ||!req.params.tag)
|
|
if (!req.params.id ||!req.params.tag)
|
|
|
return app.routerUtils.onBadRequest(res);
|
|
return app.routerUtils.onBadRequest(res);
|
|
|
- let data = await MediaService.fetchOne(app, req.params.id, req.sessionObj?.accessList);
|
|
|
|
|
- if (!data || data.accessType !== ACCESS_GRANT.write)
|
|
|
|
|
- return app.routerUtils.onPageNotFound(res);
|
|
|
|
|
- await app.databaseHelper.remove(MediaFileTagModel, { md5sum: data.fixedSum, tag: decodeURIComponent(req.params.tag), fromMeta: 0 });
|
|
|
|
|
- app.routerUtils.jsonResponse(res, MediaToJson(await MediaService.fetchOne(app, req.params.id, req.sessionObj?.accessList)));
|
|
|
|
|
|
|
+ let checksum = [ req.params.id ];
|
|
|
|
|
+ if (req.params.id === "list") {
|
|
|
|
|
+ if (!req.body?.['list[]'])
|
|
|
|
|
+ return app.routerUtils.onBadRequest(res);
|
|
|
|
|
+ checksum = req.body['list[]'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let data = await MediaService.fetchMultiple(app, checksum, req.sessionObj?.accessList);
|
|
|
|
|
+ data = Object.keys(data).map(x => data[x]).filter(x => x.ACCESS_TYPE != ACCESS_GRANT.write);
|
|
|
|
|
+
|
|
|
|
|
+ await app.databaseHelper.remove(MediaFileTagModel, { md5sum: data.map(x => x.fixedSum), tag: decodeURIComponent(req.params.tag), fromMeta: 0 });
|
|
|
|
|
+ const allMedias = await MediaService.fetchMultiple(app, checksum, req.sessionObj?.accessList);
|
|
|
|
|
+ app.routerUtils.jsonResponse(res, Object.keys(allMedias).map(x => allMedias[x]).map(x => MediaToJson(x)));
|
|
|
});
|
|
});
|
|
|
app.router.put("/api/media/:id/tag", async (req, res) => {
|
|
app.router.put("/api/media/:id/tag", async (req, res) => {
|
|
|
app.routerUtils.onApiRequest(req, res);
|
|
app.routerUtils.onApiRequest(req, res);
|
|
|
- if (!req.params.id ||!req.body?.tag)
|
|
|
|
|
|
|
+ const requestedTag = req.body?.tag;
|
|
|
|
|
+ if (!req.params.id ||!requestedTag)
|
|
|
return app.routerUtils.onBadRequest(res);
|
|
return app.routerUtils.onBadRequest(res);
|
|
|
- let data = await MediaService.fetchOne(app, req.params.id, req.sessionObj?.accessList);
|
|
|
|
|
- if (!data || data.accessType !== ACCESS_GRANT.write)
|
|
|
|
|
- return app.routerUtils.onPageNotFound(res);
|
|
|
|
|
- const requestedTag = req.body.tag;
|
|
|
|
|
- for (let existingTag of [...data.tags, ...data.fixedTags]) {
|
|
|
|
|
- if (existingTag === requestedTag || existingTag.startsWith(`${requestedTag}/`)) {
|
|
|
|
|
- return app.routerUtils.jsonResponse(res, data);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ let checksum = [ req.params.id ];
|
|
|
|
|
+ if (req.params.id === "list") {
|
|
|
|
|
+ if (!req.body?.['list[]'])
|
|
|
|
|
+ return app.routerUtils.onBadRequest(res);
|
|
|
|
|
+ checksum = req.body['list[]'];
|
|
|
}
|
|
}
|
|
|
- let tag = new MediaFileTagModel(data.fixedSum, requestedTag, false);
|
|
|
|
|
- await app.databaseHelper.insertOne(tag);
|
|
|
|
|
- app.routerUtils.jsonResponse(res, MediaToJson(await MediaService.fetchOne(app, req.params.id, req.sessionObj?.accessList)));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ let data = await MediaService.fetchMultiple(app, checksum, req.sessionObj?.accessList);
|
|
|
|
|
+ data = Object.keys(data)
|
|
|
|
|
+ .map(x => data[x])
|
|
|
|
|
+ .filter(x => {
|
|
|
|
|
+ if (x.ACCESS_TYPE != ACCESS_GRANT.write)
|
|
|
|
|
+ return true;
|
|
|
|
|
+ for (let existingTag of [...x.tags, ...x.fixedTags]) {
|
|
|
|
|
+ if (existingTag === requestedTag || existingTag.startsWith(`${requestedTag}/`)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ let tag = data.map(x => new MediaFileTagModel(x.fixedSum, requestedTag, false));
|
|
|
|
|
+ await app.databaseHelper.insertMultipleSameTable(tag);
|
|
|
|
|
+ const allMedias = await MediaService.fetchMultiple(app, checksum, req.sessionObj?.accessList);
|
|
|
|
|
+ app.routerUtils.jsonResponse(res, Object.keys(allMedias).map(x => allMedias[x]).map(x => MediaToJson(x)));
|
|
|
});
|
|
});
|
|
|
app.router.patch("/api/media/:id/meta/:key", async (req, res) => {
|
|
app.router.patch("/api/media/:id/meta/:key", async (req, res) => {
|
|
|
app.routerUtils.onApiRequest(req, res);
|
|
app.routerUtils.onApiRequest(req, res);
|