add: mark instance as NSFW

Closes transfem-org/Sharkey#197
This commit is contained in:
Mar0xy 2023-12-05 22:19:53 +01:00
parent 6f9ba940b9
commit 93869a5f34
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
11 changed files with 85 additions and 16 deletions

View file

@ -23,8 +23,9 @@ export const paramDef = {
properties: {
host: { type: 'string' },
isSuspended: { type: 'boolean' },
isNSFW: { type: 'boolean' },
},
required: ['host', 'isSuspended'],
required: ['host'],
} as const;
@Injectable()
@ -44,23 +45,31 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new Error('instance not found');
}
await this.federatedInstanceService.update(instance.id, {
isSuspended: ps.isSuspended,
});
if (ps.isSuspended != null) {
await this.federatedInstanceService.update(instance.id, {
isSuspended: ps.isSuspended,
});
if (instance.isSuspended !== ps.isSuspended) {
if (ps.isSuspended) {
this.moderationLogService.log(me, 'suspendRemoteInstance', {
id: instance.id,
host: instance.host,
});
} else {
this.moderationLogService.log(me, 'unsuspendRemoteInstance', {
id: instance.id,
host: instance.host,
});
if (instance.isSuspended !== ps.isSuspended) {
if (ps.isSuspended) {
this.moderationLogService.log(me, 'suspendRemoteInstance', {
id: instance.id,
host: instance.host,
});
} else {
this.moderationLogService.log(me, 'unsuspendRemoteInstance', {
id: instance.id,
host: instance.host,
});
}
}
}
if (ps.isNSFW != null) {
await this.federatedInstanceService.update(instance.id, {
isNSFW: ps.isNSFW,
});
}
});
}
}

View file

@ -40,6 +40,7 @@ export const paramDef = {
federating: { type: 'boolean', nullable: true },
subscribing: { type: 'boolean', nullable: true },
publishing: { type: 'boolean', nullable: true },
nsfw: { type: 'boolean', nullable: true },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 },
offset: { type: 'integer', default: 0 },
sort: { type: 'string' },
@ -103,6 +104,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
}
if (typeof ps.nsfw === 'boolean') {
if (ps.nsfw) {
query.andWhere('instance.isNSFW = TRUE');
} else {
query.andWhere('instance.isNSFW = FALSE');
}
}
if (typeof ps.silenced === "boolean") {
const meta = await this.metaService.fetch(true);