|
@@ -28,9 +28,14 @@ module.exports = { register: app => {
|
|
|
app.routerUtils.onApiRequest(req, res);
|
|
app.routerUtils.onApiRequest(req, res);
|
|
|
if (!req.post?.linkIds?.length)
|
|
if (!req.post?.linkIds?.length)
|
|
|
return app.routerUtils.httpResponse(res, 400, "Missing argument");
|
|
return app.routerUtils.httpResponse(res, 400, "Missing argument");
|
|
|
- for (let i of JSON.parse(req.post.linkIds)) {
|
|
|
|
|
- if (await app.databaseHelper.findOne(AccessModel, { type: ACCESS_TYPE.link, typeData: i }))
|
|
|
|
|
- Security.addLinkToSession(req, i);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (let i of JSON.parse(req.post.linkIds)) {
|
|
|
|
|
+ if (await app.databaseHelper.findOne(AccessModel, { type: ACCESS_TYPE.link, typeData: i }))
|
|
|
|
|
+ Security.addLinkToSession(req, i);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ return app.routerUtils.onBadRequest(res);
|
|
|
}
|
|
}
|
|
|
app.routerUtils.jsonResponse(res, req.sessionObj.accessList);
|
|
app.routerUtils.jsonResponse(res, req.sessionObj.accessList);
|
|
|
});
|
|
});
|
|
@@ -145,11 +150,11 @@ module.exports = { register: app => {
|
|
|
if (!data)
|
|
if (!data)
|
|
|
return app.routerUtils.onPageNotFound(res);
|
|
return app.routerUtils.onPageNotFound(res);
|
|
|
const fileName = Path.basename(data.path);
|
|
const fileName = Path.basename(data.path);
|
|
|
- res.setHeader("Content-Disposition", `attachment; filename="${fileName}"`);
|
|
|
|
|
res.setHeader("Cache-Control", "private, max-age=2630000"); // 1 month cache
|
|
res.setHeader("Cache-Control", "private, max-age=2630000"); // 1 month cache
|
|
|
if (data.accessType === ACCESS_GRANT.readNoMeta || req.body?.trim !== undefined) {
|
|
if (data.accessType === ACCESS_GRANT.readNoMeta || req.body?.trim !== undefined) {
|
|
|
console.log("remove meta");//-> trim metadata
|
|
console.log("remove meta");//-> trim metadata
|
|
|
}
|
|
}
|
|
|
|
|
+ res.setHeader("Content-Disposition", `attachment; filename="${fileName}"`);
|
|
|
res.setHeader("Content-Type", mime.lookup(data.path));
|
|
res.setHeader("Content-Type", mime.lookup(data.path));
|
|
|
res.setHeader("Content-Length", fs.statSync(data.path)?.size || undefined);
|
|
res.setHeader("Content-Length", fs.statSync(data.path)?.size || undefined);
|
|
|
fs.createReadStream(data.path).pipe(res);
|
|
fs.createReadStream(data.path).pipe(res);
|