summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/users/search_by_username.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-08-06 18:28:27 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-08-06 18:28:27 +0900
commit5f208a7d99cf985e9c613e2d65656ae4d46aa68a (patch)
tree0c74b4e4c8214454eae9b8da9303d3909def3676 /src/server/api/endpoints/users/search_by_username.ts
parent非公開の投稿に自分以外が返信したりRenoteしたりできな... (diff)
downloadsharkey-5f208a7d99cf985e9c613e2d65656ae4d46aa68a.tar.gz
sharkey-5f208a7d99cf985e9c613e2d65656ae4d46aa68a.tar.bz2
sharkey-5f208a7d99cf985e9c613e2d65656ae4d46aa68a.zip
ユーザー検索APIを統合
Diffstat (limited to 'src/server/api/endpoints/users/search_by_username.ts')
-rw-r--r--src/server/api/endpoints/users/search_by_username.ts70
1 files changed, 0 insertions, 70 deletions
diff --git a/src/server/api/endpoints/users/search_by_username.ts b/src/server/api/endpoints/users/search_by_username.ts
deleted file mode 100644
index bfab378389..0000000000
--- a/src/server/api/endpoints/users/search_by_username.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import $ from 'cafy';
-import User, { pack, ILocalUser } from '../../../../models/user';
-const escapeRegexp = require('escape-regexp');
-
-/**
- * Search a user by username
- */
-export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
- // Get 'query' parameter
- const [query, queryError] = $.str.get(params.query);
- if (queryError) return rej('invalid query param');
-
- // Get 'offset' parameter
- const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
- if (offsetErr) return rej('invalid offset param');
-
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
- if (limitErr) return rej('invalid limit param');
-
- let users = await User
- .find({
- host: null,
- usernameLower: new RegExp('^' + escapeRegexp(query.toLowerCase()))
- }, {
- limit: limit,
- skip: offset
- });
-
- if (users.length < limit) {
- const otherUsers = await User
- .find({
- host: { $ne: null },
- usernameLower: new RegExp('^' + escapeRegexp(query.toLowerCase()))
- }, {
- limit: limit - users.length
- });
-
- users = users.concat(otherUsers);
- }
-
- if (users.length < limit) {
- const otherUsers = await User
- .find({
- _id: { $nin: users.map(u => u._id) },
- host: null,
- usernameLower: new RegExp(escapeRegexp(query.toLowerCase()))
- }, {
- limit: limit - users.length
- });
-
- users = users.concat(otherUsers);
- }
-
- if (users.length < limit) {
- const otherUsers = await User
- .find({
- _id: { $nin: users.map(u => u._id) },
- host: { $ne: null },
- usernameLower: new RegExp(escapeRegexp(query.toLowerCase()))
- }, {
- limit: limit - users.length
- });
-
- users = users.concat(otherUsers);
- }
-
- // Serialize
- res(await Promise.all(users.map(user => pack(user, me, { detail: true }))));
-});