|
|
@@ -734,7 +734,7 @@ module.exports = function(crowi, app) {
|
|
|
api.list = function(req, res) {
|
|
|
const username = req.query.user || null;
|
|
|
const path = req.query.path || null;
|
|
|
- const limit = parseInt(req.query.limit) ;
|
|
|
+ const limit = + req.query.limit || 50;
|
|
|
const offset = parseInt(req.query.offset) || 0;
|
|
|
|
|
|
const pagerOptions = { offset: offset, limit: limit };
|
|
|
@@ -1262,5 +1262,51 @@ module.exports = function(crowi, app) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ api.recentCreated = function(req, res) {
|
|
|
+ const username = req.query.user || null;
|
|
|
+ const path = req.query.path || null;
|
|
|
+ const limit = + req.query.limit || 50;
|
|
|
+ const offset = + req.query.offset || 0;
|
|
|
+
|
|
|
+ const pagerOptions = { offset: offset, limit: limit };
|
|
|
+ const queryOptions = { offset: offset, limit: limit };
|
|
|
+
|
|
|
+ // Accepts only one of these
|
|
|
+ if (username === null && path === null) {
|
|
|
+ return res.json(ApiResponse.error('Parameter user or path is required.'));
|
|
|
+ }
|
|
|
+ if (username !== null && path !== null) {
|
|
|
+ return res.json(ApiResponse.error('Parameter user or path is required.'));
|
|
|
+ }
|
|
|
+
|
|
|
+ let pageFetcher;
|
|
|
+ if (path === null) {
|
|
|
+ pageFetcher = User.findUserByUsername(username)
|
|
|
+ .then(function(user) {
|
|
|
+ if (user === null) {
|
|
|
+ throw new Error('The user not found.');
|
|
|
+ }
|
|
|
+ return Page.findListByCreator(user, queryOptions, req.user);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ pageFetcher = Page.findListByStartWith(path, req.user, queryOptions);
|
|
|
+ }
|
|
|
+
|
|
|
+ pageFetcher
|
|
|
+ .then(function(pages) {
|
|
|
+ if (pages.length > limit) {
|
|
|
+ pages.pop();
|
|
|
+ }
|
|
|
+ pagerOptions.length = pages.length;
|
|
|
+
|
|
|
+ const result = {};
|
|
|
+ result.pages = pagePathUtils.encodePagesPath(pages);
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
+ }).catch(function(err) {
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return actions;
|
|
|
};
|