2019-02-07 10:11:20 +01:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../define';
|
|
|
|
import Instance from '../../../../models/instance';
|
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['federation'],
|
|
|
|
|
2019-02-07 10:11:20 +01:00
|
|
|
requireCredential: false,
|
|
|
|
|
|
|
|
params: {
|
2019-02-08 12:56:16 +01:00
|
|
|
blocked: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.nullable.bool,
|
2019-02-08 12:56:16 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
notResponding: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.nullable.bool,
|
2019-02-08 12:56:16 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
markedAsClosed: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.nullable.bool,
|
2019-02-07 20:26:43 +01:00
|
|
|
},
|
|
|
|
|
2019-02-07 10:11:20 +01:00
|
|
|
limit: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.num.range(1, 100),
|
2019-02-07 10:11:20 +01:00
|
|
|
default: 30
|
|
|
|
},
|
|
|
|
|
|
|
|
offset: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.num.min(0),
|
2019-02-07 10:11:20 +01:00
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
|
|
|
|
sort: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.str,
|
2019-02-07 10:11:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-02-07 10:11:20 +01:00
|
|
|
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
|
|
|
|
};
|
2019-02-08 12:56:16 +01:00
|
|
|
} else if (ps.sort == '+lastCommunicatedAt') {
|
|
|
|
sort = {
|
|
|
|
lastCommunicatedAt: -1
|
|
|
|
};
|
|
|
|
} else if (ps.sort == '-lastCommunicatedAt') {
|
|
|
|
sort = {
|
|
|
|
lastCommunicatedAt: 1
|
|
|
|
};
|
2019-02-08 08:58:57 +01:00
|
|
|
} 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
|
|
|
|
};
|
2019-02-07 10:11:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sort = {
|
|
|
|
_id: -1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:26:43 +01:00
|
|
|
const q = {} as any;
|
|
|
|
|
2019-02-08 12:56:16 +01:00
|
|
|
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;
|
2019-02-07 20:26:43 +01:00
|
|
|
|
2019-02-07 10:11:20 +01:00
|
|
|
const instances = await Instance
|
2019-02-07 20:26:43 +01:00
|
|
|
.find(q, {
|
2019-02-07 10:11:20 +01:00
|
|
|
limit: ps.limit,
|
|
|
|
sort: sort,
|
|
|
|
skip: ps.offset
|
|
|
|
});
|
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
return instances;
|
|
|
|
});
|