2021-03-23 21:05:37 -05:00
|
|
|
import { URL } from 'url';
|
2021-08-19 07:55:45 -05:00
|
|
|
import define from '../../../define';
|
|
|
|
import { addRelay } from '@/services/relay';
|
|
|
|
import { ApiError } from '../../../error';
|
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-18 23:05:32 -06:00
|
|
|
const paramDef = {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
inbox: { type: 'string' },
|
|
|
|
},
|
|
|
|
required: ['inbox'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 11:12:50 -06:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-18 23:05:32 -06:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2020-05-15 06:51:16 -05:00
|
|
|
try {
|
|
|
|
if (new URL(ps.inbox).protocol !== 'https:') throw 'https only';
|
|
|
|
} catch {
|
|
|
|
throw new ApiError(meta.errors.invalidUrl);
|
|
|
|
}
|
|
|
|
|
2020-05-10 04:42:31 -05:00
|
|
|
return await addRelay(ps.inbox);
|
|
|
|
});
|