|
@@ -1,5 +1,4 @@
|
|
|
const loggerFactory = require('@alias/logger');
|
|
const loggerFactory = require('@alias/logger');
|
|
|
-const shareLinks = require('../routes/apiv3/share-links');
|
|
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:middleware:certify-shared-fire');
|
|
const logger = loggerFactory('growi:middleware:certify-shared-fire');
|
|
|
|
|
|
|
@@ -10,11 +9,9 @@ module.exports = (crowi) => {
|
|
|
const fileId = req.params.id || null;
|
|
const fileId = req.params.id || null;
|
|
|
|
|
|
|
|
if (fileId == null) {
|
|
if (fileId == null) {
|
|
|
- return next();
|
|
|
|
|
|
|
+ next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- console.log('hoge');
|
|
|
|
|
-
|
|
|
|
|
// No need to check shared page if user exists
|
|
// No need to check shared page if user exists
|
|
|
if (req.user != null) {
|
|
if (req.user != null) {
|
|
|
next();
|
|
next();
|
|
@@ -26,22 +23,23 @@ module.exports = (crowi) => {
|
|
|
const attachment = await Attachment.findOne({ _id: fileId });
|
|
const attachment = await Attachment.findOne({ _id: fileId });
|
|
|
|
|
|
|
|
if (attachment == null) {
|
|
if (attachment == null) {
|
|
|
- return next();
|
|
|
|
|
|
|
+ next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const shareLinks = await ShareLink.find({ relatedPage: attachment.page });
|
|
const shareLinks = await ShareLink.find({ relatedPage: attachment.page });
|
|
|
|
|
|
|
|
// If sharelinks don't exist, skip it
|
|
// If sharelinks don't exist, skip it
|
|
|
if (shareLinks.length === 0) {
|
|
if (shareLinks.length === 0) {
|
|
|
- return next();
|
|
|
|
|
|
|
+ next();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Is there a valid share link
|
|
// Is there a valid share link
|
|
|
await Promise.all(shareLinks.map((sharelink) => {
|
|
await Promise.all(shareLinks.map((sharelink) => {
|
|
|
if (!sharelink.isExpired()) {
|
|
if (!sharelink.isExpired()) {
|
|
|
logger.debug('Confirmed target file belong to a share page');
|
|
logger.debug('Confirmed target file belong to a share page');
|
|
|
- return req.isSharedPage = true;
|
|
|
|
|
|
|
+ req.isSharedPage = true;
|
|
|
}
|
|
}
|
|
|
|
|
+ return;
|
|
|
}));
|
|
}));
|
|
|
|
|
|
|
|
next();
|
|
next();
|