2022-02-27 11:07:39 +09:00
|
|
|
import { URL } from 'node:url';
|
2023-02-16 15:09:41 +01:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
|
import { RelayService } from '@/core/RelayService.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { ApiError } from '../../../error.js';
|
2020-05-10 18:42:31 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
inbox: { type: 'string' },
|
|
|
|
|
},
|
|
|
|
|
required: ['inbox'],
|
|
|
|
|
} as const;
|
|
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
2023-05-27 16:06:42 +00:00
|
|
|
export default class extends Endpoint<'admin/relays/add'> {
|
|
|
|
|
name = 'admin/relays/add' as const;
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
|
private relayService: RelayService,
|
|
|
|
|
) {
|
2023-05-27 16:06:42 +00:00
|
|
|
super(async (ps, me) => {
|
2022-09-18 03:27:08 +09:00
|
|
|
try {
|
2023-05-29 11:54:49 +09:00
|
|
|
if (new URL(ps.inbox).protocol !== 'https:') throw new Error('https only');
|
2022-09-18 03:27:08 +09:00
|
|
|
} catch {
|
2023-05-27 16:06:42 +00:00
|
|
|
throw new ApiError(this.meta.errors.invalidUrl);
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|
2020-05-15 20:51:16 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
return await this.relayService.addRelay(ps.inbox);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|