連合しているインスタンスを一覧できるように

This commit is contained in:
syuilo
2019-02-07 18:11:20 +09:00
parent 7275bc6d3b
commit c3140f57b9
7 changed files with 277 additions and 55 deletions

View File

@ -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);
}));

View File

@ -0,0 +1,20 @@
import $ from 'cafy';
import define from '../../define';
import Instance from '../../../../models/instance';
export const meta = {
requireCredential: false,
params: {
host: {
validator: $.str
}
}
};
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
const instance = await Instance
.findOne({ host: ps.host });
res(instance);
}));

View File

@ -1,51 +0,0 @@
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);
}));