summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-11-15 06:21:13 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-11-15 06:21:13 +0900
commit1dba82aae598953018652999ee737a2599852da7 (patch)
treee14835198adacdd33fec8e9f2b98a3acbb3712f9 /src/server/api
parent[Client] Prevent cache locale file (diff)
downloadsharkey-1dba82aae598953018652999ee737a2599852da7.tar.gz
sharkey-1dba82aae598953018652999ee737a2599852da7.tar.bz2
sharkey-1dba82aae598953018652999ee737a2599852da7.zip
[API] Add /instances
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/endpoints/instances.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/server/api/endpoints/instances.ts b/src/server/api/endpoints/instances.ts
new file mode 100644
index 0000000000..b7c686a353
--- /dev/null
+++ b/src/server/api/endpoints/instances.ts
@@ -0,0 +1,51 @@
+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.or('+notes|-notes'),
+ }
+ }
+};
+
+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 {
+ _sort = {
+ _id: -1
+ };
+ }
+
+ const instances = await Instance
+ .find({}, {
+ limit: ps.limit,
+ sort: _sort,
+ skip: ps.offset
+ });
+
+ res(instances);
+}));