2019-02-07 18:11:20 +09:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../define';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { Instances } from '../../../../models';
|
|
|
|
import fetchMeta from '../../../../misc/fetch-meta';
|
2019-02-07 18:11:20 +09:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['federation'],
|
|
|
|
|
2019-02-07 18:11:20 +09:00
|
|
|
requireCredential: false,
|
|
|
|
|
|
|
|
params: {
|
2019-02-08 20:56:16 +09:00
|
|
|
blocked: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.nullable.bool,
|
2019-02-08 20:56:16 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
notResponding: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.nullable.bool,
|
2019-02-08 20:56:16 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
markedAsClosed: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.nullable.bool,
|
2019-02-08 04:26:43 +09:00
|
|
|
},
|
|
|
|
|
2019-02-07 18:11:20 +09:00
|
|
|
limit: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.num.range(1, 100),
|
2019-02-07 18:11:20 +09:00
|
|
|
default: 30
|
|
|
|
},
|
|
|
|
|
|
|
|
offset: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.num.min(0),
|
2019-02-07 18:11:20 +09:00
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
|
|
|
|
sort: {
|
2019-02-13 16:33:07 +09:00
|
|
|
validator: $.optional.str,
|
2019-02-07 18:11:20 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-04-07 21:50:36 +09:00
|
|
|
const query = Instances.createQueryBuilder('instance');
|
|
|
|
|
|
|
|
switch (ps.sort) {
|
|
|
|
case '+notes': query.orderBy('instance.notesCount', 'DESC'); break;
|
|
|
|
case '-notes': query.orderBy('instance.notesCount', 'ASC'); break;
|
|
|
|
case '+usersCount': query.orderBy('instance.usersCount', 'DESC'); break;
|
|
|
|
case '-usersCount': query.orderBy('instance.usersCount', 'ASC'); break;
|
|
|
|
case '+followingCount': query.orderBy('instance.followingCount', 'DESC'); break;
|
|
|
|
case '-followingCount': query.orderBy('instance.followingCount', 'ASC'); break;
|
|
|
|
case '+followersCount': query.orderBy('instance.followersCount', 'DESC'); break;
|
|
|
|
case '-followersCount': query.orderBy('instance.followersCount', 'ASC'); break;
|
|
|
|
case '+caughtAt': query.orderBy('instance.caughtAt', 'DESC'); break;
|
|
|
|
case '-caughtAt': query.orderBy('instance.caughtAt', 'ASC'); break;
|
|
|
|
case '+lastCommunicatedAt': query.orderBy('instance.lastCommunicatedAt', 'DESC'); break;
|
|
|
|
case '-lastCommunicatedAt': query.orderBy('instance.lastCommunicatedAt', 'ASC'); break;
|
|
|
|
case '+driveUsage': query.orderBy('instance.driveUsage', 'DESC'); break;
|
|
|
|
case '-driveUsage': query.orderBy('instance.driveUsage', 'ASC'); break;
|
|
|
|
case '+driveFiles': query.orderBy('instance.driveFiles', 'DESC'); break;
|
|
|
|
case '-driveFiles': query.orderBy('instance.driveFiles', 'ASC'); break;
|
|
|
|
|
|
|
|
default: query.orderBy('instance.id', 'DESC'); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof ps.blocked === 'boolean') {
|
|
|
|
const meta = await fetchMeta();
|
|
|
|
if (ps.blocked) {
|
|
|
|
query.andWhere('instance.host IN (:...blocks)', { blocks: meta.blockedHosts });
|
|
|
|
} else {
|
|
|
|
query.andWhere('instance.host NOT IN (:...blocks)', { blocks: meta.blockedHosts });
|
2019-02-07 18:11:20 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
if (typeof ps.notResponding === 'boolean') {
|
|
|
|
if (ps.notResponding) {
|
|
|
|
query.andWhere('instance.isNotResponding = TRUE');
|
|
|
|
} else {
|
|
|
|
query.andWhere('instance.isNotResponding = FALSE');
|
|
|
|
}
|
|
|
|
}
|
2019-02-08 04:26:43 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
if (typeof ps.markedAsClosed === 'boolean') {
|
|
|
|
if (ps.markedAsClosed) {
|
|
|
|
query.andWhere('instance.isMarkedAsClosed = TRUE');
|
|
|
|
} else {
|
|
|
|
query.andWhere('instance.isMarkedAsClosed = FALSE');
|
|
|
|
}
|
|
|
|
}
|
2019-02-08 04:26:43 +09:00
|
|
|
|
2019-04-13 01:43:22 +09:00
|
|
|
const instances = await query.take(ps.limit!).skip(ps.offset).getMany();
|
2019-02-07 18:11:20 +09:00
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
return instances;
|
|
|
|
});
|