1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
import $ from 'cafy';
import define from '../../define';
import Instance from '../../../../models/instance';
export const meta = {
tags: ['federation'],
requireCredential: false,
params: {
blocked: {
validator: $.optional.nullable.bool,
},
notResponding: {
validator: $.optional.nullable.bool,
},
markedAsClosed: {
validator: $.optional.nullable.bool,
},
limit: {
validator: $.optional.num.range(1, 100),
default: 30
},
offset: {
validator: $.optional.num.min(0),
default: 0
},
sort: {
validator: $.optional.str,
}
}
};
export default define(meta, async (ps, me) => {
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 if (ps.sort == '+lastCommunicatedAt') {
sort = {
lastCommunicatedAt: -1
};
} else if (ps.sort == '-lastCommunicatedAt') {
sort = {
lastCommunicatedAt: 1
};
} else if (ps.sort == '+driveUsage') {
sort = {
driveUsage: -1
};
} else if (ps.sort == '-driveUsage') {
sort = {
driveUsage: 1
};
} else if (ps.sort == '+driveFiles') {
sort = {
driveFiles: -1
};
} else if (ps.sort == '-driveFiles') {
sort = {
driveFiles: 1
};
}
} else {
sort = {
_id: -1
};
}
const q = {} as any;
if (typeof ps.blocked === 'boolean') q.isBlocked = ps.blocked;
if (typeof ps.notResponding === 'boolean') q.isNotResponding = ps.notResponding;
if (typeof ps.markedAsClosed === 'boolean') q.isMarkedAsClosed = ps.markedAsClosed;
const instances = await Instance
.find(q, {
limit: ps.limit,
sort: sort,
skip: ps.offset
});
return instances;
});
|