diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-02-07 18:11:20 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-02-07 18:11:20 +0900 |
| commit | c3140f57b99f9f11437279695b05ee3eccff41ca (patch) | |
| tree | d3f3e30c509c54f7443dc7712479842c03ab5b35 /src/server/api/endpoints/federation/instances.ts | |
| parent | Improve instance stats (diff) | |
| download | sharkey-c3140f57b99f9f11437279695b05ee3eccff41ca.tar.gz sharkey-c3140f57b99f9f11437279695b05ee3eccff41ca.tar.bz2 sharkey-c3140f57b99f9f11437279695b05ee3eccff41ca.zip | |
連合しているインスタンスを一覧できるように
Diffstat (limited to 'src/server/api/endpoints/federation/instances.ts')
| -rw-r--r-- | src/server/api/endpoints/federation/instances.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/server/api/endpoints/federation/instances.ts b/src/server/api/endpoints/federation/instances.ts new file mode 100644 index 0000000000..723cbe8fd5 --- /dev/null +++ b/src/server/api/endpoints/federation/instances.ts @@ -0,0 +1,84 @@ +import $ from 'cafy'; +import define from '../../define'; +import Instance from '../../../../models/instance'; + +export const meta = { + requireCredential: false, + + params: { + limit: { + validator: $.num.optional.range(1, 100), + default: 30 + }, + + offset: { + validator: $.num.optional.min(0), + default: 0 + }, + + sort: { + validator: $.str.optional, + } + } +}; + +export default define(meta, (ps, me) => new Promise(async (res, rej) => { + let sort; + + if (ps.sort) { + if (ps.sort == '+notes') { + sort = { + notesCount: -1 + }; + } else if (ps.sort == '-notes') { + sort = { + notesCount: 1 + }; + } else if (ps.sort == '+users') { + sort = { + usersCount: -1 + }; + } else if (ps.sort == '-users') { + sort = { + usersCount: 1 + }; + } else if (ps.sort == '+following') { + sort = { + followingCount: -1 + }; + } else if (ps.sort == '-following') { + sort = { + followingCount: 1 + }; + } else if (ps.sort == '+followers') { + sort = { + followersCount: -1 + }; + } else if (ps.sort == '-followers') { + sort = { + followersCount: 1 + }; + } else if (ps.sort == '+caughtAt') { + sort = { + caughtAt: -1 + }; + } else if (ps.sort == '-caughtAt') { + sort = { + caughtAt: 1 + }; + } + } else { + sort = { + _id: -1 + }; + } + + const instances = await Instance + .find({}, { + limit: ps.limit, + sort: sort, + skip: ps.offset + }); + + res(instances); +})); |