2021-03-24 11:05:37 +09:00
|
|
|
import { URL } from 'url';
|
2021-08-19 21:55:45 +09:00
|
|
|
import define from '../../../define';
|
|
|
|
import { addRelay } from '@/services/relay';
|
|
|
|
import { ApiError } from '../../../error';
|
2020-05-10 18:42:31 +09:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
|
|
|
requireModerator: true,
|
2020-05-10 18:42:31 +09:00
|
|
|
|
2020-05-15 20:51:16 +09:00
|
|
|
errors: {
|
|
|
|
invalidUrl: {
|
|
|
|
message: 'Invalid URL',
|
|
|
|
code: 'INVALID_URL',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c',
|
2020-05-15 20:51:16 +09:00
|
|
|
},
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
properties: {
|
|
|
|
id: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 23:58:30 +09:00
|
|
|
format: 'id',
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
inbox: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 23:58:30 +09:00
|
|
|
format: 'url',
|
2021-03-06 22:34:11 +09:00
|
|
|
},
|
|
|
|
status: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 22:34:11 +09:00
|
|
|
default: 'requesting',
|
|
|
|
enum: [
|
|
|
|
'requesting',
|
|
|
|
'accepted',
|
2021-12-09 23:58:30 +09:00
|
|
|
'rejected',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2020-05-10 18:42:31 +09:00
|
|
|
|
2022-02-19 14:05:32 +09:00
|
|
|
const paramDef = {
|
|
|
|
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-02-19 14:05:32 +09:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2020-05-15 20:51:16 +09:00
|
|
|
try {
|
|
|
|
if (new URL(ps.inbox).protocol !== 'https:') throw 'https only';
|
|
|
|
} catch {
|
|
|
|
throw new ApiError(meta.errors.invalidUrl);
|
|
|
|
}
|
|
|
|
|
2020-05-10 18:42:31 +09:00
|
|
|
return await addRelay(ps.inbox);
|
|
|
|
});
|