mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-15 06:27:34 -07:00
[API] Add /instances
This commit is contained in:
parent
3a934173e8
commit
4892b5b273
1 changed files with 51 additions and 0 deletions
51
src/server/api/endpoints/instances.ts
Normal file
51
src/server/api/endpoints/instances.ts
Normal file
|
@ -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);
|
||||
}));
|
Loading…
Reference in a new issue