|
@@ -540,51 +540,43 @@ module.exports = function(crowi, app) {
|
|
|
var limit = 50;
|
|
var limit = 50;
|
|
|
var offset = parseInt(req.query.offset) || 0;
|
|
var offset = parseInt(req.query.offset) || 0;
|
|
|
|
|
|
|
|
- var user;
|
|
|
|
|
- var result = {};
|
|
|
|
|
-
|
|
|
|
|
var pagerOptions = { offset: offset, limit : limit };
|
|
var pagerOptions = { offset: offset, limit : limit };
|
|
|
var queryOptions = { offset: offset, limit : limit + 1};
|
|
var queryOptions = { offset: offset, limit : limit + 1};
|
|
|
|
|
|
|
|
|
|
+ // Accepts only one of these
|
|
|
if (username === null && path === null) {
|
|
if (username === null && path === null) {
|
|
|
- return res.json(ApiResponse.error('Parameters user or path are required.'));
|
|
|
|
|
|
|
+ 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.'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ var pageFetcher;
|
|
|
if (path === null) {
|
|
if (path === null) {
|
|
|
- User.findUserByUsername(username)
|
|
|
|
|
|
|
+ pageFetcher = User.findUserByUsername(username)
|
|
|
.then(function(user) {
|
|
.then(function(user) {
|
|
|
if (user === null) {
|
|
if (user === null) {
|
|
|
throw new Error('The user not found.');
|
|
throw new Error('The user not found.');
|
|
|
}
|
|
}
|
|
|
- result.pageUser = user;
|
|
|
|
|
return Page.findListByCreator(user, queryOptions, req.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 {
|
|
} 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));
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ pageFetcher = Page.findListByStartWith(path, req.user, queryOptions);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ pageFetcher
|
|
|
|
|
+ .then(function(pages) {
|
|
|
|
|
+ if (pages.length > limit) {
|
|
|
|
|
+ pages.pop();
|
|
|
|
|
+ }
|
|
|
|
|
+ pagerOptions.length = pages.length;
|
|
|
|
|
+
|
|
|
|
|
+ var result = {};
|
|
|
|
|
+ result.pages = pages;
|
|
|
|
|
+ return res.json(ApiResponse.success(result));
|
|
|
|
|
+ }).catch(function(err) {
|
|
|
|
|
+ return res.json(ApiResponse.error(err));
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|