2023-07-27 00:31:52 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-02-26 20:07:39 -06:00
|
|
|
import { URL } from 'node:url';
|
2023-02-16 08:09:41 -06:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { RelayService } from '@/core/RelayService.js';
|
2022-02-26 20:07:39 -06:00
|
|
|
import { ApiError } from '../../../error.js';
|
2020-05-10 04:42:31 -05:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 07:27:10 -06:00
|
|
|
requireCredential: true,
|
|
|
|
requireModerator: true,
|
2020-05-10 04:42:31 -05:00
|
|
|
|
2020-05-15 06:51:16 -05:00
|
|
|
errors: {
|
|
|
|
invalidUrl: {
|
|
|
|
message: 'Invalid URL',
|
|
|
|
code: 'INVALID_URL',
|
2021-12-09 08:58:30 -06:00
|
|
|
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c',
|
2020-05-15 06:51:16 -05:00
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
properties: {
|
|
|
|
id: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'id',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
inbox: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
format: 'url',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
status: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
default: 'requesting',
|
|
|
|
enum: [
|
|
|
|
'requesting',
|
|
|
|
'accepted',
|
2021-12-09 08:58:30 -06:00
|
|
|
'rejected',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 07:27:10 -06:00
|
|
|
} as const;
|
2020-05-10 04:42:31 -05:00
|
|
|
|
2022-02-19 22:15:40 -06:00
|
|
|
export const paramDef = {
|
2022-02-18 23:05:32 -06:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
inbox: { type: 'string' },
|
|
|
|
},
|
|
|
|
required: ['inbox'],
|
|
|
|
} as const;
|
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
@Injectable()
|
2023-08-17 07:20:58 -05:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-17 13:27:08 -05:00
|
|
|
constructor(
|
|
|
|
private relayService: RelayService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
try {
|
2023-05-28 21:54:49 -05:00
|
|
|
if (new URL(ps.inbox).protocol !== 'https:') throw new Error('https only');
|
2022-09-17 13:27:08 -05:00
|
|
|
} catch {
|
|
|
|
throw new ApiError(meta.errors.invalidUrl);
|
|
|
|
}
|
2020-05-15 06:51:16 -05:00
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
return await this.relayService.addRelay(ps.inbox);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|