|
|
@@ -526,6 +526,67 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * @api {get} /pages.list List pages by user
|
|
|
+ * @apiName ListPage
|
|
|
+ * @apiGroup Page
|
|
|
+ *
|
|
|
+ * @apiParam {String} path
|
|
|
+ * @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;
|
|
|
+
|
|
|
+ var user;
|
|
|
+ var result = {};
|
|
|
+
|
|
|
+ var pagerOptions = { offset: offset, limit : limit };
|
|
|
+ var queryOptions = { offset: offset, limit : limit + 1};
|
|
|
+
|
|
|
+ if (username === null && path === null) {
|
|
|
+ return res.json(ApiResponse.error('Parameters user or path are required.'));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (path === null) {
|
|
|
+ User.findUserByUsername(username)
|
|
|
+ .then(function(user) {
|
|
|
+ if (user === null) {
|
|
|
+ throw new Error('The user not found.');
|
|
|
+ }
|
|
|
+ result.pageUser = user;
|
|
|
+ return Page.findListByCreator(user, queryOptions, req.user);
|
|
|
+ }).then(function(pages) {
|
|
|
+ if (pages.length > limit) {
|
|
|
+ pages.pop();
|
|
|
+ }
|
|
|
+ pagerOptions.length = pages.length;
|
|
|
+
|
|
|
+ result.pages = pages;
|
|
|
+ result.searchPath = '/';
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
+ }).catch(function(err) {
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ Page.findListByStartWith(path, req.user, queryOptions)
|
|
|
+ .then(function(pageList) {
|
|
|
+ if (pageList.length > limit) {
|
|
|
+ pageList.pop();
|
|
|
+ }
|
|
|
+ pagerOptions.length = pageList.length;
|
|
|
+
|
|
|
+ result.pages = pageList;
|
|
|
+ result.searchPath = /\/$/.test(path) ? path : path + '/';
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
+ }).catch(function(err) {
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* @api {post} /pages.create Create new page
|
|
|
* @apiName CreatePage
|