|
|
@@ -22,19 +22,19 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
// register page events
|
|
|
|
|
|
- var pageEvent = crowi.event('page');
|
|
|
+ const pageEvent = crowi.event('page');
|
|
|
pageEvent.on('update', function(page, user) {
|
|
|
crowi.getIo().sockets.emit('page edited', {page, user});
|
|
|
});
|
|
|
|
|
|
|
|
|
function getPathFromRequest(req) {
|
|
|
- var path = '/' + (req.params[0] || '');
|
|
|
+ const path = '/' + (req.params[0] || '');
|
|
|
return path.replace(/\.md$/, '');
|
|
|
}
|
|
|
|
|
|
function isUserPage(path) {
|
|
|
- if (path.match(/^\/user\/[^\/]+\/?$/)) {
|
|
|
+ if (path.match(/^\/user\/[^/]+\/?$/)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -43,9 +43,9 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
// TODO: total とかでちゃんと計算する
|
|
|
function generatePager(options) {
|
|
|
- var next = null,
|
|
|
- prev = null,
|
|
|
- offset = parseInt(options.offset, 10),
|
|
|
+ let next = null,
|
|
|
+ prev = null;
|
|
|
+ const offset = parseInt(options.offset, 10),
|
|
|
limit = parseInt(options.limit, 10),
|
|
|
length = options.length || 0;
|
|
|
|
|
|
@@ -146,26 +146,26 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
|
|
|
actions.pageListShow = function(req, res) {
|
|
|
- var path = getPathFromRequest(req);
|
|
|
- var limit = 50;
|
|
|
- var offset = parseInt(req.query.offset) || 0;
|
|
|
- var SEENER_THRESHOLD = 10;
|
|
|
+ let path = getPathFromRequest(req);
|
|
|
+ const limit = 50;
|
|
|
+ const offset = parseInt(req.query.offset) || 0;
|
|
|
+ const SEENER_THRESHOLD = 10;
|
|
|
// add slash if root
|
|
|
path = path + (path == '/' ? '' : '/');
|
|
|
|
|
|
debug('Page list show', path);
|
|
|
// index page
|
|
|
- var pagerOptions = {
|
|
|
+ const pagerOptions = {
|
|
|
offset: offset,
|
|
|
limit: limit
|
|
|
};
|
|
|
- var queryOptions = {
|
|
|
+ const queryOptions = {
|
|
|
offset: offset,
|
|
|
limit: limit + 1,
|
|
|
isPopulateRevisionBody: Config.isEnabledTimeline(config),
|
|
|
};
|
|
|
|
|
|
- var renderVars = {
|
|
|
+ const renderVars = {
|
|
|
page: null,
|
|
|
path: path,
|
|
|
isPortal: false,
|
|
|
@@ -418,22 +418,22 @@ module.exports = function(crowi, app) {
|
|
|
};
|
|
|
|
|
|
actions.deletedPageListShow = function(req, res) {
|
|
|
- var path = '/trash' + getPathFromRequest(req);
|
|
|
- var limit = 50;
|
|
|
- var offset = parseInt(req.query.offset) || 0;
|
|
|
+ const path = '/trash' + getPathFromRequest(req);
|
|
|
+ const limit = 50;
|
|
|
+ const offset = parseInt(req.query.offset) || 0;
|
|
|
|
|
|
// index page
|
|
|
- var pagerOptions = {
|
|
|
+ const pagerOptions = {
|
|
|
offset: offset,
|
|
|
limit: limit
|
|
|
};
|
|
|
- var queryOptions = {
|
|
|
+ const queryOptions = {
|
|
|
offset: offset,
|
|
|
limit: limit + 1,
|
|
|
includeDeletedPage: true,
|
|
|
};
|
|
|
|
|
|
- var renderVars = {
|
|
|
+ const renderVars = {
|
|
|
page: null,
|
|
|
path: path,
|
|
|
pages: [],
|
|
|
@@ -458,8 +458,8 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
actions.search = function(req, res) {
|
|
|
// spec: ?q=query&sort=sort_order&author=author_filter
|
|
|
- var query = req.query.q;
|
|
|
- var search = require('../util/search')(crowi);
|
|
|
+ const query = req.query.q;
|
|
|
+ const search = require('../util/search')(crowi);
|
|
|
|
|
|
search.searchPageByKeyword(query)
|
|
|
.then(function(pages) {
|
|
|
@@ -469,7 +469,7 @@ module.exports = function(crowi, app) {
|
|
|
return Promise.resolve([]);
|
|
|
}
|
|
|
|
|
|
- var ids = pages.hits.hits.map(function(page) {
|
|
|
+ const ids = pages.hits.hits.map(function(page) {
|
|
|
return page._id;
|
|
|
});
|
|
|
|
|
|
@@ -586,10 +586,10 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
actions.pageShow = function(req, res) {
|
|
|
- var path = path || getPathFromRequest(req);
|
|
|
+ const path = path || getPathFromRequest(req);
|
|
|
|
|
|
// FIXME: せっかく getPathFromRequest になってるのにここが生 params[0] だとダサイ
|
|
|
- var isMarkdown = req.params[0].match(/.+\.md$/) || false;
|
|
|
+ const isMarkdown = req.params[0].match(/.+\.md$/) || false;
|
|
|
|
|
|
res.locals.path = path;
|
|
|
|
|
|
@@ -668,22 +668,22 @@ module.exports = function(crowi, app) {
|
|
|
return res.redirect(req.headers.referer);
|
|
|
}
|
|
|
|
|
|
- var pageForm = req.form.pageForm;
|
|
|
- var path = pageForm.path;
|
|
|
- var body = pageForm.body;
|
|
|
- var currentRevision = pageForm.currentRevision;
|
|
|
- var grant = pageForm.grant;
|
|
|
- var grantUserGroupId = pageForm.grantUserGroupId;
|
|
|
+ const pageForm = req.form.pageForm;
|
|
|
+ const path = pageForm.path;
|
|
|
+ const body = pageForm.body;
|
|
|
+ const currentRevision = pageForm.currentRevision;
|
|
|
+ const grant = pageForm.grant;
|
|
|
+ const grantUserGroupId = pageForm.grantUserGroupId;
|
|
|
|
|
|
// TODO: make it pluggable
|
|
|
- var notify = pageForm.notify || {};
|
|
|
+ const notify = pageForm.notify || {};
|
|
|
|
|
|
debug('notify: ', notify);
|
|
|
|
|
|
- var redirectPath = pagePathUtil.encodePagePath(path);
|
|
|
- var pageData = {};
|
|
|
- var updateOrCreate;
|
|
|
- var previousRevision = false;
|
|
|
+ const redirectPath = pagePathUtil.encodePagePath(path);
|
|
|
+ let pageData = {};
|
|
|
+ let previousRevision = false;
|
|
|
+ let updateOrCreate;
|
|
|
|
|
|
// set to render
|
|
|
res.locals.pageForm = pageForm;
|
|
|
@@ -694,7 +694,7 @@ module.exports = function(crowi, app) {
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
- var ignoreNotFound = true;
|
|
|
+ const ignoreNotFound = true;
|
|
|
Page.findPage(path, req.user, null, ignoreNotFound)
|
|
|
.then(function(data) {
|
|
|
pageData = data;
|
|
|
@@ -757,13 +757,13 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
|
|
|
|
|
|
- var api = actions.api = {};
|
|
|
+ const api = actions.api = {};
|
|
|
|
|
|
/**
|
|
|
* redirector
|
|
|
*/
|
|
|
api.redirector = function(req, res) {
|
|
|
- var id = req.params.id;
|
|
|
+ const id = req.params.id;
|
|
|
|
|
|
Page.findPageById(id)
|
|
|
.then(function(pageData) {
|
|
|
@@ -790,13 +790,13 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} user
|
|
|
*/
|
|
|
api.list = function(req, res) {
|
|
|
- var username = req.query.user || null;
|
|
|
- var path = req.query.path || null;
|
|
|
- var limit = 50;
|
|
|
- var offset = parseInt(req.query.offset) || 0;
|
|
|
+ const username = req.query.user || null;
|
|
|
+ const path = req.query.path || null;
|
|
|
+ const limit = 50;
|
|
|
+ const offset = parseInt(req.query.offset) || 0;
|
|
|
|
|
|
- var pagerOptions = { offset: offset, limit: limit };
|
|
|
- var queryOptions = { offset: offset, limit: limit + 1};
|
|
|
+ const pagerOptions = { offset: offset, limit: limit };
|
|
|
+ const queryOptions = { offset: offset, limit: limit + 1};
|
|
|
|
|
|
// Accepts only one of these
|
|
|
if (username === null && path === null) {
|
|
|
@@ -806,7 +806,7 @@ module.exports = function(crowi, app) {
|
|
|
return res.json(ApiResponse.error('Parameter user or path is required.'));
|
|
|
}
|
|
|
|
|
|
- var pageFetcher;
|
|
|
+ let pageFetcher;
|
|
|
if (path === null) {
|
|
|
pageFetcher = User.findUserByUsername(username)
|
|
|
.then(function(user) {
|
|
|
@@ -827,7 +827,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
pagerOptions.length = pages.length;
|
|
|
|
|
|
- var result = {};
|
|
|
+ const result = {};
|
|
|
result.pages = pagePathUtil.encodePagesPath(pages);
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
}).catch(function(err) {
|
|
|
@@ -845,16 +845,16 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} grant
|
|
|
*/
|
|
|
api.create = function(req, res) {
|
|
|
- var body = req.body.body || null;
|
|
|
- var pagePath = req.body.path || null;
|
|
|
- var grant = req.body.grant || null;
|
|
|
- var grantUserGroupId = req.body.grantUserGroupId || null;
|
|
|
+ const body = req.body.body || null;
|
|
|
+ const pagePath = req.body.path || null;
|
|
|
+ const grant = req.body.grant || null;
|
|
|
+ const grantUserGroupId = req.body.grantUserGroupId || null;
|
|
|
|
|
|
if (body === null || pagePath === null) {
|
|
|
return res.json(ApiResponse.error('Parameters body and path are required.'));
|
|
|
}
|
|
|
|
|
|
- var ignoreNotFound = true;
|
|
|
+ const ignoreNotFound = true;
|
|
|
Page.findPage(pagePath, req.user, null, ignoreNotFound)
|
|
|
.then(function(data) {
|
|
|
if (data !== null) {
|
|
|
@@ -866,7 +866,7 @@ module.exports = function(crowi, app) {
|
|
|
if (!data) {
|
|
|
throw new Error('Failed to create page.');
|
|
|
}
|
|
|
- var result = { page: data.toObject() };
|
|
|
+ const result = { page: data.toObject() };
|
|
|
|
|
|
result.page.lastUpdateUser = User.filterToPublicFields(data.lastUpdateUser);
|
|
|
result.page.creator = User.filterToPublicFields(data.creator);
|
|
|
@@ -892,11 +892,11 @@ module.exports = function(crowi, app) {
|
|
|
* - If revision_id is not specified => force update by the new contents.
|
|
|
*/
|
|
|
api.update = function(req, res) {
|
|
|
- var pageBody = req.body.body || null;
|
|
|
- var pageId = req.body.page_id || null;
|
|
|
- var revisionId = req.body.revision_id || null;
|
|
|
- var grant = req.body.grant || null;
|
|
|
- var grantUserGroupId = req.body.grantUserGroupId || null;
|
|
|
+ const pageBody = req.body.body || null;
|
|
|
+ const pageId = req.body.page_id || null;
|
|
|
+ const revisionId = req.body.revision_id || null;
|
|
|
+ const grant = req.body.grant || null;
|
|
|
+ const grantUserGroupId = req.body.grantUserGroupId || null;
|
|
|
|
|
|
if (pageId === null || pageBody === null) {
|
|
|
return res.json(ApiResponse.error('page_id and body are required.'));
|
|
|
@@ -908,7 +908,7 @@ module.exports = function(crowi, app) {
|
|
|
throw new Error('Revision error.');
|
|
|
}
|
|
|
|
|
|
- var grantOption = {};
|
|
|
+ const grantOption = {};
|
|
|
if (grant != null) {
|
|
|
grantOption.grant = grant;
|
|
|
}
|
|
|
@@ -917,7 +917,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
return Page.updatePage(pageData, pageBody, req.user, grantOption);
|
|
|
}).then(function(pageData) {
|
|
|
- var result = {
|
|
|
+ const result = {
|
|
|
page: pageData.toObject(),
|
|
|
};
|
|
|
result.page.lastUpdateUser = User.filterToPublicFields(result.page.lastUpdateUser);
|
|
|
@@ -955,7 +955,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
|
|
|
pageFinder.then(function(pageData) {
|
|
|
- var result = {};
|
|
|
+ const result = {};
|
|
|
result.page = pageData;
|
|
|
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
@@ -972,7 +972,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
api.seen = function(req, res) {
|
|
|
- var pageId = req.body.page_id;
|
|
|
+ const pageId = req.body.page_id;
|
|
|
if (!pageId) {
|
|
|
return res.json(ApiResponse.error('page_id required'));
|
|
|
}
|
|
|
@@ -981,7 +981,7 @@ module.exports = function(crowi, app) {
|
|
|
.then(function(page) {
|
|
|
return page.seen(req.user);
|
|
|
}).then(function(user) {
|
|
|
- var result = {};
|
|
|
+ const result = {};
|
|
|
result.seenUser = user;
|
|
|
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
@@ -999,14 +999,14 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
api.like = function(req, res) {
|
|
|
- var id = req.body.page_id;
|
|
|
+ const id = req.body.page_id;
|
|
|
|
|
|
Page.findPageByIdAndGrantedUser(id, req.user)
|
|
|
.then(function(pageData) {
|
|
|
return pageData.like(req.user);
|
|
|
})
|
|
|
.then(function(page) {
|
|
|
- var result = {page: page};
|
|
|
+ const result = {page: page};
|
|
|
res.json(ApiResponse.success(result));
|
|
|
return page;
|
|
|
})
|
|
|
@@ -1028,13 +1028,13 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
api.unlike = function(req, res) {
|
|
|
- var id = req.body.page_id;
|
|
|
+ const id = req.body.page_id;
|
|
|
|
|
|
Page.findPageByIdAndGrantedUser(id, req.user)
|
|
|
.then(function(pageData) {
|
|
|
return pageData.unlike(req.user);
|
|
|
}).then(function(data) {
|
|
|
- var result = {page: data};
|
|
|
+ const result = {page: data};
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
}).catch(function(err) {
|
|
|
debug('Unlike failed', err);
|
|
|
@@ -1050,8 +1050,8 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} path
|
|
|
*/
|
|
|
api.getUpdatePost = function(req, res) {
|
|
|
- var path = req.query.path;
|
|
|
- var UpdatePost = crowi.model('UpdatePost');
|
|
|
+ const path = req.query.path;
|
|
|
+ const UpdatePost = crowi.model('UpdatePost');
|
|
|
|
|
|
if (!path) {
|
|
|
return res.json(ApiResponse.error({}));
|
|
|
@@ -1063,7 +1063,7 @@ module.exports = function(crowi, app) {
|
|
|
return e.channel;
|
|
|
});
|
|
|
debug('Found updatePost data', data);
|
|
|
- var result = {updatePost: data};
|
|
|
+ const result = {updatePost: data};
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
}).catch(function(err) {
|
|
|
debug('Error occured while get setting', err);
|
|
|
@@ -1080,8 +1080,8 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} revision_id
|
|
|
*/
|
|
|
api.remove = function(req, res) {
|
|
|
- var pageId = req.body.page_id;
|
|
|
- var previousRevision = req.body.revision_id || null;
|
|
|
+ const pageId = req.body.page_id;
|
|
|
+ const previousRevision = req.body.revision_id || null;
|
|
|
|
|
|
// get completely flag
|
|
|
const isCompletely = (req.body.completely !== undefined);
|
|
|
@@ -1116,7 +1116,7 @@ module.exports = function(crowi, app) {
|
|
|
})
|
|
|
.then(function(data) {
|
|
|
debug('Page deleted', data.path);
|
|
|
- var result = {};
|
|
|
+ const result = {};
|
|
|
result.page = data;
|
|
|
|
|
|
res.json(ApiResponse.success(result));
|
|
|
@@ -1140,7 +1140,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} page_id Page Id.
|
|
|
*/
|
|
|
api.revertRemove = function(req, res) {
|
|
|
- var pageId = req.body.page_id;
|
|
|
+ const pageId = req.body.page_id;
|
|
|
|
|
|
// get recursively flag
|
|
|
const isRecursively = (req.body.recursively !== undefined);
|
|
|
@@ -1156,7 +1156,7 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
debug('Complete to revert deleted page', data.path);
|
|
|
- var result = {};
|
|
|
+ const result = {};
|
|
|
result.page = data;
|
|
|
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
@@ -1178,15 +1178,14 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {Bool} create_redirect
|
|
|
*/
|
|
|
api.rename = function(req, res) {
|
|
|
- var pageId = req.body.page_id;
|
|
|
- var previousRevision = req.body.revision_id || null;
|
|
|
- var newPagePath = Page.normalizePath(req.body.new_path);
|
|
|
- var options = {
|
|
|
+ const pageId = req.body.page_id;
|
|
|
+ const previousRevision = req.body.revision_id || null;
|
|
|
+ const newPagePath = Page.normalizePath(req.body.new_path);
|
|
|
+ const options = {
|
|
|
createRedirectPage: req.body.create_redirect || 0,
|
|
|
moveUnderTrees: req.body.move_trees || 0,
|
|
|
};
|
|
|
- var isRecursiveMove = req.body.move_recursively || 0;
|
|
|
- var page = {};
|
|
|
+ const isRecursiveMove = req.body.move_recursively || 0;
|
|
|
|
|
|
if (!Page.isCreatableName(newPagePath)) {
|
|
|
return res.json(ApiResponse.error(`このページ名は作成できません (${newPagePath})`));
|
|
|
@@ -1215,7 +1214,7 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
})
|
|
|
.then(function() {
|
|
|
- var result = {};
|
|
|
+ const result = {};
|
|
|
result.page = page;
|
|
|
|
|
|
return res.json(ApiResponse.success(result));
|
|
|
@@ -1240,8 +1239,8 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} new_path
|
|
|
*/
|
|
|
api.duplicate = function(req, res) {
|
|
|
- var pageId = req.body.page_id;
|
|
|
- var newPagePath = Page.normalizePath(req.body.new_path);
|
|
|
+ const pageId = req.body.page_id;
|
|
|
+ const newPagePath = Page.normalizePath(req.body.new_path);
|
|
|
|
|
|
Page.findPageById(pageId)
|
|
|
.then(function(pageData) {
|
|
|
@@ -1262,7 +1261,7 @@ module.exports = function(crowi, app) {
|
|
|
* @apiParam {String} revision_id
|
|
|
*/
|
|
|
api.unlink = function(req, res) {
|
|
|
- var pageId = req.body.page_id;
|
|
|
+ const pageId = req.body.page_id;
|
|
|
|
|
|
Page.findPageByIdAndGrantedUser(pageId, req.user)
|
|
|
.then(function(pageData) {
|
|
|
@@ -1272,7 +1271,7 @@ module.exports = function(crowi, app) {
|
|
|
.then(() => pageData);
|
|
|
}).then(function(data) {
|
|
|
debug('Redirect Page deleted', data.path);
|
|
|
- var result = {};
|
|
|
+ const result = {};
|
|
|
result.page = data;
|
|
|
|
|
|
return res.json(ApiResponse.success(result));
|