This commit is contained in:
tamaina
2023-05-27 16:06:42 +00:00
parent 53ad4b18e5
commit 5268a55996
9 changed files with 130 additions and 146 deletions

View File

@@ -4,48 +4,6 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { RelayService } from '@/core/RelayService.js';
import { ApiError } from '../../../error.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
errors: {
invalidUrl: {
message: 'Invalid URL',
code: 'INVALID_URL',
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c',
},
},
res: {
type: 'object',
optional: false, nullable: false,
properties: {
id: {
type: 'string',
optional: false, nullable: false,
format: 'id',
},
inbox: {
type: 'string',
optional: false, nullable: false,
format: 'url',
},
status: {
type: 'string',
optional: false, nullable: false,
default: 'requesting',
enum: [
'requesting',
'accepted',
'rejected',
],
},
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
@@ -56,15 +14,16 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'admin/relays/add'> {
name = 'admin/relays/add' as const;
constructor(
private relayService: RelayService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
try {
if (new URL(ps.inbox).protocol !== 'https:') throw 'https only';
} catch {
throw new ApiError(meta.errors.invalidUrl);
throw new ApiError(this.meta.errors.invalidUrl);
}
return await this.relayService.addRelay(ps.inbox);