Implement instance blocking (#4182)
* Implement instance blocking * Add missing text * Delete unnecessary file * Covert Punycode to Unicode
This commit is contained in:
34
src/server/api/endpoints/admin/federation/update-instance.ts
Normal file
34
src/server/api/endpoints/admin/federation/update-instance.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import $ from 'cafy';
|
||||
import define from '../../../define';
|
||||
import Instance from '../../../../../models/instance';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
params: {
|
||||
host: {
|
||||
validator: $.str
|
||||
},
|
||||
|
||||
isBlocked: {
|
||||
validator: $.bool
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
const instance = await Instance.findOne({ host: ps.host });
|
||||
|
||||
if (instance == null) {
|
||||
return rej('instance not found');
|
||||
}
|
||||
|
||||
Instance.update({ host: ps.host }, {
|
||||
$set: {
|
||||
isBlocked: ps.isBlocked
|
||||
}
|
||||
});
|
||||
|
||||
res();
|
||||
}));
|
@ -6,6 +6,10 @@ export const meta = {
|
||||
requireCredential: false,
|
||||
|
||||
params: {
|
||||
state: {
|
||||
validator: $.str.optional,
|
||||
},
|
||||
|
||||
limit: {
|
||||
validator: $.num.optional.range(1, 100),
|
||||
default: 30
|
||||
@ -73,8 +77,14 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
};
|
||||
}
|
||||
|
||||
const q = {} as any;
|
||||
|
||||
if (ps.state === 'blocked') {
|
||||
q.isBlocked = true;
|
||||
}
|
||||
|
||||
const instances = await Instance
|
||||
.find({}, {
|
||||
.find(q, {
|
||||
limit: ps.limit,
|
||||
sort: sort,
|
||||
skip: ps.offset
|
||||
|
Reference in New Issue
Block a user