2023-01-13 05:40:33 +01:00
|
|
|
import { URL } from "node:url";
|
|
|
|
import define from "../../../define.js";
|
|
|
|
import { addRelay } from "@/services/relay.js";
|
|
|
|
import { ApiError } from "../../../error.js";
|
2020-05-10 11:42:31 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2023-01-13 05:40:33 +01:00
|
|
|
tags: ["admin"],
|
2020-05-10 11:42:31 +02:00
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
|
|
|
requireModerator: true,
|
2020-05-10 11:42:31 +02:00
|
|
|
|
2020-05-15 13:51:16 +02:00
|
|
|
errors: {
|
|
|
|
invalidUrl: {
|
2023-01-13 05:40:33 +01:00
|
|
|
message: "Invalid URL",
|
|
|
|
code: "INVALID_URL",
|
|
|
|
id: "fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c",
|
2020-05-15 13:51:16 +02:00
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "object",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
2021-03-06 14:34:11 +01:00
|
|
|
properties: {
|
|
|
|
id: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "string",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
|
|
|
format: "id",
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
inbox: {
|
2023-01-13 05:40:33 +01:00
|
|
|
description: "URL of the inbox, must be a https scheme URL",
|
|
|
|
type: "string",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
|
|
|
format: "url",
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
status: {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "string",
|
|
|
|
optional: false,
|
|
|
|
nullable: false,
|
|
|
|
default: "requesting",
|
|
|
|
enum: ["requesting", "accepted", "rejected"],
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2020-05-10 11:42:31 +02:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2023-01-13 05:40:33 +01:00
|
|
|
type: "object",
|
2022-02-19 06:05:32 +01:00
|
|
|
properties: {
|
2023-01-13 05:40:33 +01:00
|
|
|
inbox: { type: "string" },
|
2022-02-19 06:05:32 +01:00
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
required: ["inbox"],
|
2022-02-19 06:05:32 +01:00
|
|
|
} as const;
|
|
|
|
|
2023-01-13 05:54:33 +01:00
|
|
|
|
2022-02-19 06:05:32 +01:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2020-05-15 13:51:16 +02:00
|
|
|
try {
|
2023-01-13 05:40:33 +01:00
|
|
|
if (new URL(ps.inbox).protocol !== "https:") throw new Error("https only");
|
2020-05-15 13:51:16 +02:00
|
|
|
} catch {
|
|
|
|
throw new ApiError(meta.errors.invalidUrl);
|
|
|
|
}
|
|
|
|
|
2020-05-10 11:42:31 +02:00
|
|
|
return await addRelay(ps.inbox);
|
|
|
|
});
|