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