fixing lots of openapi crap
This commit is contained in:
parent
777e7208dc
commit
6b3a3b750f
159364
assets/schemas.json
159364
assets/schemas.json
File diff suppressed because it is too large
Load Diff
7
openapitools.json
Normal file
7
openapitools.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
|
||||||
|
"spaces": 2,
|
||||||
|
"generator-cli": {
|
||||||
|
"version": "6.4.0"
|
||||||
|
}
|
||||||
|
}
|
@ -27,34 +27,46 @@ require("missing-native-js-functions");
|
|||||||
|
|
||||||
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
|
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
|
||||||
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
|
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json");
|
||||||
let schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }));
|
const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }));
|
||||||
|
// const specification = JSON.parse(
|
||||||
for (var schema in schemas) {
|
// fs.readFileSync(openapiPath, { encoding: "utf8" }),
|
||||||
const part = schemas[schema];
|
// );
|
||||||
for (var key in part.properties) {
|
let specification = {
|
||||||
if (part.properties[key].anyOf) {
|
openapi: "3.1.0",
|
||||||
const nullIndex = part.properties[key].anyOf.findIndex(
|
info: {
|
||||||
(x) => x.type == "null",
|
title: "Fosscord Server",
|
||||||
);
|
description:
|
||||||
if (nullIndex != -1) {
|
"Fosscord is a free open source selfhostable discord compatible chat, voice and video platform",
|
||||||
part.properties[key].nullable = true;
|
license: {
|
||||||
part.properties[key].anyOf.splice(nullIndex, 1);
|
name: "AGPLV3",
|
||||||
|
url: "https://www.gnu.org/licenses/agpl-3.0.en.html",
|
||||||
if (part.properties[key].anyOf.length == 1) {
|
},
|
||||||
Object.assign(
|
version: "1.0.0",
|
||||||
part.properties[key],
|
},
|
||||||
part.properties[key].anyOf[0],
|
externalDocs: {
|
||||||
);
|
description: "Fosscord Docs",
|
||||||
delete part.properties[key].anyOf;
|
url: "https://docs.fosscord.com",
|
||||||
}
|
},
|
||||||
}
|
servers: [
|
||||||
}
|
{
|
||||||
}
|
url: "https://staging.fosscord.com/api/",
|
||||||
}
|
description: "Official Fosscord Instance",
|
||||||
|
},
|
||||||
const specification = JSON.parse(
|
],
|
||||||
fs.readFileSync(openapiPath, { encoding: "utf8" }),
|
components: {
|
||||||
);
|
securitySchemes: {
|
||||||
|
bearer: {
|
||||||
|
type: "http",
|
||||||
|
scheme: "bearer",
|
||||||
|
description: "Bearer/Bot prefixes are not required.",
|
||||||
|
bearerFormat: "JWT",
|
||||||
|
in: "header",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tags: [],
|
||||||
|
paths: {},
|
||||||
|
};
|
||||||
|
|
||||||
function combineSchemas(schemas) {
|
function combineSchemas(schemas) {
|
||||||
var definitions = {};
|
var definitions = {};
|
||||||
@ -72,6 +84,11 @@ function combineSchemas(schemas) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const key in definitions) {
|
for (const key in definitions) {
|
||||||
|
const reg = new RegExp(/^[a-zA-Z0-9\.\-_]+$/, "gm");
|
||||||
|
if (!reg.test(key)) {
|
||||||
|
console.error(`Invalid schema name: ${key} (${reg.test(key)})`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
specification.components = specification.components || {};
|
specification.components = specification.components || {};
|
||||||
specification.components.schemas =
|
specification.components.schemas =
|
||||||
specification.components.schemas || {};
|
specification.components.schemas || {};
|
||||||
@ -102,30 +119,20 @@ function getTag(key) {
|
|||||||
function apiRoutes() {
|
function apiRoutes() {
|
||||||
const routes = getRouteDescriptions();
|
const routes = getRouteDescriptions();
|
||||||
|
|
||||||
const tags = Array.from(routes.keys()).map((x) => getTag(x));
|
// populate tags
|
||||||
specification.tags = specification.tags || [];
|
const tags = Array.from(routes.keys())
|
||||||
specification.tags = [...specification.tags.map((x) => x.name), ...tags]
|
.map((x) => getTag(x))
|
||||||
.unique()
|
.sort((a, b) => a.localeCompare(b));
|
||||||
.map((x) => ({ name: x }));
|
specification.tags = tags.unique().map((x) => ({ name: x }));
|
||||||
|
|
||||||
specification.components = specification.components || {};
|
|
||||||
specification.components.securitySchemes = {
|
|
||||||
bearer: {
|
|
||||||
type: "http",
|
|
||||||
scheme: "bearer",
|
|
||||||
description: "Bearer/Bot prefixes are not required.",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
routes.forEach((route, pathAndMethod) => {
|
routes.forEach((route, pathAndMethod) => {
|
||||||
const [p, method] = pathAndMethod.split("|");
|
const [p, method] = pathAndMethod.split("|");
|
||||||
const path = p.replace(/:(\w+)/g, "{$1}");
|
const path = p.replace(/:(\w+)/g, "{$1}");
|
||||||
|
|
||||||
specification.paths = specification.paths || {};
|
|
||||||
let obj = specification.paths[path]?.[method] || {};
|
let obj = specification.paths[path]?.[method] || {};
|
||||||
obj["x-right-required"] = route.right;
|
obj["x-right-required"] = route.right;
|
||||||
obj["x-permission-required"] = route.permission;
|
obj["x-permission-required"] = route.permission;
|
||||||
obj["x-fires-event"] = route.test?.event;
|
obj["x-fires-event"] = route.event;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!NO_AUTHORIZATION_ROUTES.some((x) => {
|
!NO_AUTHORIZATION_ROUTES.some((x) => {
|
||||||
@ -136,12 +143,17 @@ function apiRoutes() {
|
|||||||
obj.security = [{ bearer: [] }];
|
obj.security = [{ bearer: [] }];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (route.body) {
|
if (route.description) obj.description = route.description;
|
||||||
|
if (route.summary) obj.summary = route.summary;
|
||||||
|
|
||||||
|
if (route.requestBody) {
|
||||||
obj.requestBody = {
|
obj.requestBody = {
|
||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: { $ref: `#/components/schemas/${route.body}` },
|
schema: {
|
||||||
|
$ref: `#/components/schemas/${route.requestBody}`,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}.merge(obj.requestBody);
|
}.merge(obj.requestBody);
|
||||||
@ -150,16 +162,9 @@ function apiRoutes() {
|
|||||||
if (route.responses) {
|
if (route.responses) {
|
||||||
for (const [k, v] of Object.entries(route.responses)) {
|
for (const [k, v] of Object.entries(route.responses)) {
|
||||||
let schema = {
|
let schema = {
|
||||||
allOf: [
|
|
||||||
{
|
|
||||||
$ref: `#/components/schemas/${v.body}`,
|
$ref: `#/components/schemas/${v.body}`,
|
||||||
},
|
|
||||||
{
|
|
||||||
example: v.body,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
if (!v.body) schema = schema.allOf[0];
|
// if (!v.body) schema = schema.allOf[0];
|
||||||
|
|
||||||
obj.responses = {
|
obj.responses = {
|
||||||
[k]: {
|
[k]: {
|
||||||
@ -173,12 +178,16 @@ function apiRoutes() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {}),
|
: {
|
||||||
|
description: "No description available",
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
}.merge(obj.responses);
|
}.merge(obj.responses);
|
||||||
delete obj.responses.default;
|
delete obj.responses.default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handles path parameters
|
||||||
if (p.includes(":")) {
|
if (p.includes(":")) {
|
||||||
obj.parameters = p.match(/:\w+/g)?.map((x) => ({
|
obj.parameters = p.match(/:\w+/g)?.map((x) => ({
|
||||||
name: x.replace(":", ""),
|
name: x.replace(":", ""),
|
||||||
@ -188,16 +197,17 @@ function apiRoutes() {
|
|||||||
description: x.replace(":", ""),
|
description: x.replace(":", ""),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.tags = [...(obj.tags || []), getTag(p)].unique();
|
obj.tags = [...(obj.tags || []), getTag(p)].unique();
|
||||||
|
|
||||||
specification.paths[path] = {
|
specification.paths[path] = {
|
||||||
...specification.paths[path],
|
|
||||||
[method]: obj,
|
[method]: obj,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
console.log("Generating OpenAPI Specification...");
|
||||||
combineSchemas(schemas);
|
combineSchemas(schemas);
|
||||||
apiRoutes();
|
apiRoutes();
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ const Excluded = [
|
|||||||
"PropertiesSchema",
|
"PropertiesSchema",
|
||||||
"AsyncSchema",
|
"AsyncSchema",
|
||||||
"AnySchema",
|
"AnySchema",
|
||||||
|
"SMTPConnection.CustomAuthenticationResponse",
|
||||||
|
"TransportMakeRequestResponse",
|
||||||
];
|
];
|
||||||
|
|
||||||
function modify(obj) {
|
function modify(obj) {
|
||||||
|
@ -114,7 +114,7 @@ router.post(
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "BotModifySchema",
|
requestBody: "BotModifySchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "Application",
|
body: "Application",
|
||||||
|
@ -55,7 +55,7 @@ router.get(
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "ApplicationModifySchema",
|
requestBody: "ApplicationModifySchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "Application",
|
body: "Application",
|
||||||
|
@ -48,7 +48,7 @@ router.get(
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "ApplicationCreateSchema",
|
requestBody: "ApplicationCreateSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "Application",
|
body: "Application",
|
||||||
|
@ -31,7 +31,7 @@ const router = Router();
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "ForgotPasswordSchema",
|
requestBody: "ForgotPasswordSchema",
|
||||||
responses: {
|
responses: {
|
||||||
204: {},
|
204: {},
|
||||||
400: {
|
400: {
|
||||||
|
@ -37,7 +37,7 @@ export default router;
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "LoginSchema",
|
requestBody: "LoginSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "TokenResponse",
|
body: "TokenResponse",
|
||||||
|
@ -26,7 +26,7 @@ const router = Router();
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "TotpSchema",
|
requestBody: "TotpSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "TokenResponse",
|
body: "TokenResponse",
|
||||||
|
@ -42,7 +42,7 @@ function toArrayBuffer(buf: Buffer) {
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "WebAuthnTotpSchema",
|
requestBody: "WebAuthnTotpSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: { body: "TokenResponse" },
|
200: { body: "TokenResponse" },
|
||||||
400: { body: "APIErrorResponse" },
|
400: { body: "APIErrorResponse" },
|
||||||
|
@ -16,25 +16,25 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
|
||||||
import {
|
import {
|
||||||
Config,
|
|
||||||
generateToken,
|
|
||||||
Invite,
|
|
||||||
FieldErrors,
|
|
||||||
User,
|
|
||||||
adjustEmail,
|
|
||||||
RegisterSchema,
|
|
||||||
ValidRegistrationToken,
|
|
||||||
} from "@spacebar/util";
|
|
||||||
import {
|
|
||||||
route,
|
|
||||||
getIpAdress,
|
|
||||||
IPAnalysis,
|
IPAnalysis,
|
||||||
|
getIpAdress,
|
||||||
isProxy,
|
isProxy,
|
||||||
|
route,
|
||||||
verifyCaptcha,
|
verifyCaptcha,
|
||||||
} from "@spacebar/api";
|
} from "@spacebar/api";
|
||||||
|
import {
|
||||||
|
Config,
|
||||||
|
FieldErrors,
|
||||||
|
Invite,
|
||||||
|
RegisterSchema,
|
||||||
|
User,
|
||||||
|
ValidRegistrationToken,
|
||||||
|
adjustEmail,
|
||||||
|
generateToken,
|
||||||
|
} from "@spacebar/util";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { MoreThan } from "typeorm";
|
import { MoreThan } from "typeorm";
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ const router: Router = Router();
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "RegisterSchema",
|
requestBody: "RegisterSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: { body: "TokenResponse" },
|
200: { body: "TokenResponse" },
|
||||||
400: { body: "APIErrorOrCaptchaResponse" },
|
400: { body: "APIErrorOrCaptchaResponse" },
|
||||||
|
@ -35,7 +35,7 @@ const router = Router();
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "PasswordResetSchema",
|
requestBody: "PasswordResetSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "TokenResponse",
|
body: "TokenResponse",
|
||||||
|
@ -41,7 +41,7 @@ async function getToken(user: User) {
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "VerifyEmailSchema",
|
requestBody: "VerifyEmailSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
body: "TokenResponse",
|
body: "TokenResponse",
|
||||||
|
@ -25,7 +25,7 @@ const router = Router();
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "BackupCodesChallengeSchema",
|
requestBody: "BackupCodesChallengeSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: { body: "BackupCodesChallengeResponse" },
|
200: { body: "BackupCodesChallengeResponse" },
|
||||||
400: { body: "APIErrorResponse" },
|
400: { body: "APIErrorResponse" },
|
||||||
|
@ -107,7 +107,7 @@ router.delete(
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "ChannelModifySchema",
|
requestBody: "ChannelModifySchema",
|
||||||
permission: "MANAGE_CHANNELS",
|
permission: "MANAGE_CHANNELS",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
@ -35,7 +35,7 @@ const router: Router = Router();
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "InviteCreateSchema",
|
requestBody: "InviteCreateSchema",
|
||||||
permission: "CREATE_INSTANT_INVITE",
|
permission: "CREATE_INSTANT_INVITE",
|
||||||
right: "CREATE_INVITES",
|
right: "CREATE_INVITES",
|
||||||
responses: {
|
responses: {
|
||||||
|
@ -34,7 +34,7 @@ const router = Router();
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "MessageAcknowledgeSchema",
|
requestBody: "MessageAcknowledgeSchema",
|
||||||
responses: {
|
responses: {
|
||||||
200: {},
|
200: {},
|
||||||
403: {},
|
403: {},
|
||||||
|
@ -52,7 +52,7 @@ const messageUpload = multer({
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "MessageEditSchema",
|
requestBody: "MessageEditSchema",
|
||||||
permission: "SEND_MESSAGES",
|
permission: "SEND_MESSAGES",
|
||||||
right: "SEND_MESSAGES",
|
right: "SEND_MESSAGES",
|
||||||
responses: {
|
responses: {
|
||||||
@ -152,7 +152,7 @@ router.put(
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
route({
|
route({
|
||||||
body: "MessageCreateSchema",
|
requestBody: "MessageCreateSchema",
|
||||||
permission: "SEND_MESSAGES",
|
permission: "SEND_MESSAGES",
|
||||||
right: "SEND_BACKDATED_EVENTS",
|
right: "SEND_BACKDATED_EVENTS",
|
||||||
responses: {
|
responses: {
|
||||||
|
@ -39,7 +39,7 @@ export default router;
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "BulkDeleteSchema",
|
requestBody: "BulkDeleteSchema",
|
||||||
responses: {
|
responses: {
|
||||||
204: {},
|
204: {},
|
||||||
400: {
|
400: {
|
||||||
|
@ -220,7 +220,7 @@ router.post(
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
route({
|
route({
|
||||||
body: "MessageCreateSchema",
|
requestBody: "MessageCreateSchema",
|
||||||
permission: "SEND_MESSAGES",
|
permission: "SEND_MESSAGES",
|
||||||
right: "SEND_MESSAGES",
|
right: "SEND_MESSAGES",
|
||||||
responses: {
|
responses: {
|
||||||
|
@ -36,7 +36,7 @@ const router: Router = Router();
|
|||||||
router.put(
|
router.put(
|
||||||
"/:overwrite_id",
|
"/:overwrite_id",
|
||||||
route({
|
route({
|
||||||
body: "ChannelPermissionOverwriteSchema",
|
requestBody: "ChannelPermissionOverwriteSchema",
|
||||||
permission: "MANAGE_ROLES",
|
permission: "MANAGE_ROLES",
|
||||||
responses: {
|
responses: {
|
||||||
204: {},
|
204: {},
|
||||||
|
@ -54,7 +54,7 @@ router.get(
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "WebhookCreateSchema",
|
requestBody: "WebhookCreateSchema",
|
||||||
permission: "MANAGE_WEBHOOKS",
|
permission: "MANAGE_WEBHOOKS",
|
||||||
responses: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
|
@ -29,7 +29,7 @@ const router = Router();
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "ConnectionCallbackSchema" }),
|
route({ requestBody: "ConnectionCallbackSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { connection_name } = req.params;
|
const { connection_name } = req.params;
|
||||||
const connection = ConnectionStore.connections.get(connection_name);
|
const connection = ConnectionStore.connections.get(connection_name);
|
||||||
|
@ -16,20 +16,20 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
import { getIpAdress, route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
|
Ban,
|
||||||
|
BanModeratorSchema,
|
||||||
|
BanRegistrySchema,
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
emitEvent,
|
|
||||||
GuildBanAddEvent,
|
GuildBanAddEvent,
|
||||||
GuildBanRemoveEvent,
|
GuildBanRemoveEvent,
|
||||||
Ban,
|
|
||||||
User,
|
|
||||||
Member,
|
Member,
|
||||||
BanRegistrySchema,
|
User,
|
||||||
BanModeratorSchema,
|
emitEvent,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { getIpAdress, route } from "@spacebar/api";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ router.get(
|
|||||||
|
|
||||||
router.put(
|
router.put(
|
||||||
"/:user_id",
|
"/:user_id",
|
||||||
route({ body: "BanCreateSchema", permission: "BAN_MEMBERS" }),
|
route({ requestBody: "BanCreateSchema", permission: "BAN_MEMBERS" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const banned_user_id = req.params.user_id;
|
const banned_user_id = req.params.user_id;
|
||||||
@ -143,7 +143,7 @@ router.put(
|
|||||||
|
|
||||||
router.put(
|
router.put(
|
||||||
"/@me",
|
"/@me",
|
||||||
route({ body: "BanCreateSchema" }),
|
route({ requestBody: "BanCreateSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Response, Request } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
ChannelUpdateEvent,
|
|
||||||
emitEvent,
|
|
||||||
ChannelModifySchema,
|
ChannelModifySchema,
|
||||||
ChannelReorderSchema,
|
ChannelReorderSchema,
|
||||||
|
ChannelUpdateEvent,
|
||||||
|
emitEvent,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { route } from "@spacebar/api";
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
@ -37,7 +37,10 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNELS" }),
|
route({
|
||||||
|
requestBody: "ChannelModifySchema",
|
||||||
|
permission: "MANAGE_CHANNELS",
|
||||||
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
// creates a new guild channel https://discord.com/developers/docs/resources/guild#create-guild-channel
|
// creates a new guild channel https://discord.com/developers/docs/resources/guild#create-guild-channel
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
@ -54,7 +57,10 @@ router.post(
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "ChannelReorderSchema", permission: "MANAGE_CHANNELS" }),
|
route({
|
||||||
|
requestBody: "ChannelReorderSchema",
|
||||||
|
permission: "MANAGE_CHANNELS",
|
||||||
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
// changes guild channel position
|
// changes guild channel position
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Config,
|
Config,
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
emitEvent,
|
|
||||||
Emoji,
|
Emoji,
|
||||||
|
EmojiCreateSchema,
|
||||||
|
EmojiModifySchema,
|
||||||
GuildEmojisUpdateEvent,
|
GuildEmojisUpdateEvent,
|
||||||
handleFile,
|
|
||||||
Member,
|
Member,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
User,
|
User,
|
||||||
EmojiCreateSchema,
|
emitEvent,
|
||||||
EmojiModifySchema,
|
handleFile,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ router.get("/:emoji_id", route({}), async (req: Request, res: Response) => {
|
|||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "EmojiCreateSchema",
|
requestBody: "EmojiCreateSchema",
|
||||||
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
@ -113,7 +113,7 @@ router.post(
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/:emoji_id",
|
"/:emoji_id",
|
||||||
route({
|
route({
|
||||||
body: "EmojiModifySchema",
|
requestBody: "EmojiModifySchema",
|
||||||
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
|
Guild,
|
||||||
|
GuildUpdateEvent,
|
||||||
|
GuildUpdateSchema,
|
||||||
|
Member,
|
||||||
|
SpacebarApiErrors,
|
||||||
emitEvent,
|
emitEvent,
|
||||||
getPermission,
|
getPermission,
|
||||||
getRights,
|
getRights,
|
||||||
Guild,
|
|
||||||
GuildUpdateEvent,
|
|
||||||
handleFile,
|
handleFile,
|
||||||
Member,
|
|
||||||
GuildUpdateSchema,
|
|
||||||
SpacebarApiErrors,
|
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { route } from "@spacebar/api";
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "GuildUpdateSchema", permission: "MANAGE_GUILD" }),
|
route({ requestBody: "GuildUpdateSchema", permission: "MANAGE_GUILD" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as GuildUpdateSchema;
|
const body = req.body as GuildUpdateSchema;
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Member,
|
emitEvent,
|
||||||
|
Emoji,
|
||||||
getPermission,
|
getPermission,
|
||||||
getRights,
|
getRights,
|
||||||
Role,
|
|
||||||
GuildMemberUpdateEvent,
|
|
||||||
emitEvent,
|
|
||||||
Sticker,
|
|
||||||
Emoji,
|
|
||||||
Guild,
|
Guild,
|
||||||
|
GuildMemberUpdateEvent,
|
||||||
handleFile,
|
handleFile,
|
||||||
|
Member,
|
||||||
MemberChangeSchema,
|
MemberChangeSchema,
|
||||||
|
Role,
|
||||||
|
Sticker,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "MemberChangeSchema" }),
|
route({ requestBody: "MemberChangeSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const member_id =
|
const member_id =
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getPermission, Member, PermissionResolvable } from "@spacebar/util";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
|
import { getPermission, Member, PermissionResolvable } from "@spacebar/util";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "MemberNickChangeSchema" }),
|
route({ requestBody: "MemberNickChangeSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
let permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
|
let permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
|
||||||
|
@ -31,7 +31,7 @@ const router = Router();
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/:member_id",
|
"/:member_id",
|
||||||
route({ body: "MemberChangeProfileSchema" }),
|
route({ requestBody: "MemberChangeProfileSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
// const member_id =
|
// const member_id =
|
||||||
|
@ -16,17 +16,17 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Role,
|
|
||||||
Member,
|
|
||||||
GuildRoleUpdateEvent,
|
|
||||||
GuildRoleDeleteEvent,
|
|
||||||
emitEvent,
|
emitEvent,
|
||||||
|
GuildRoleDeleteEvent,
|
||||||
|
GuildRoleUpdateEvent,
|
||||||
handleFile,
|
handleFile,
|
||||||
|
Member,
|
||||||
|
Role,
|
||||||
RoleModifySchema,
|
RoleModifySchema,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
@ -69,7 +69,7 @@ router.delete(
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }),
|
route({ requestBody: "RoleModifySchema", permission: "MANAGE_ROLES" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { role_id, guild_id } = req.params;
|
const { role_id, guild_id } = req.params;
|
||||||
const body = req.body as RoleModifySchema;
|
const body = req.body as RoleModifySchema;
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Role,
|
|
||||||
getPermission,
|
|
||||||
Member,
|
|
||||||
GuildRoleCreateEvent,
|
|
||||||
GuildRoleUpdateEvent,
|
|
||||||
emitEvent,
|
|
||||||
Config,
|
Config,
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
|
emitEvent,
|
||||||
|
getPermission,
|
||||||
|
GuildRoleCreateEvent,
|
||||||
|
GuildRoleUpdateEvent,
|
||||||
|
Member,
|
||||||
|
Role,
|
||||||
RoleModifySchema,
|
RoleModifySchema,
|
||||||
RolePositionUpdateSchema,
|
RolePositionUpdateSchema,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
import { Not } from "typeorm";
|
import { Not } from "typeorm";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
@ -47,7 +47,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }),
|
route({ requestBody: "RoleModifySchema", permission: "MANAGE_ROLES" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const guild_id = req.params.guild_id;
|
const guild_id = req.params.guild_id;
|
||||||
const body = req.body as RoleModifySchema;
|
const body = req.body as RoleModifySchema;
|
||||||
@ -104,7 +104,7 @@ router.post(
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "RolePositionUpdateSchema" }),
|
route({ requestBody: "RolePositionUpdateSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const body = req.body as RolePositionUpdateSchema;
|
const body = req.body as RolePositionUpdateSchema;
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
emitEvent,
|
|
||||||
GuildStickersUpdateEvent,
|
GuildStickersUpdateEvent,
|
||||||
Member,
|
Member,
|
||||||
|
ModifyGuildStickerSchema,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
Sticker,
|
Sticker,
|
||||||
StickerFormatType,
|
StickerFormatType,
|
||||||
StickerType,
|
StickerType,
|
||||||
|
emitEvent,
|
||||||
uploadFile,
|
uploadFile,
|
||||||
ModifyGuildStickerSchema,
|
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { Router, Request, Response } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { route } from "@spacebar/api";
|
|
||||||
import multer from "multer";
|
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
import multer from "multer";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
router.get("/", route({}), async (req: Request, res: Response) => {
|
||||||
@ -54,7 +54,7 @@ router.post(
|
|||||||
bodyParser,
|
bodyParser,
|
||||||
route({
|
route({
|
||||||
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
||||||
body: "ModifyGuildStickerSchema",
|
requestBody: "ModifyGuildStickerSchema",
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
if (!req.file) throw new HTTPError("missing file");
|
if (!req.file) throw new HTTPError("missing file");
|
||||||
@ -110,7 +110,7 @@ router.get("/:sticker_id", route({}), async (req: Request, res: Response) => {
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/:sticker_id",
|
"/:sticker_id",
|
||||||
route({
|
route({
|
||||||
body: "ModifyGuildStickerSchema",
|
requestBody: "ModifyGuildStickerSchema",
|
||||||
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
permission: "MANAGE_EMOJIS_AND_STICKERS",
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
|
@ -16,11 +16,10 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
import { generateCode, route } from "@spacebar/api";
|
||||||
import { Guild, Template } from "@spacebar/util";
|
import { Guild, Template } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { route } from "@spacebar/api";
|
|
||||||
import { generateCode } from "@spacebar/api";
|
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -53,7 +52,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "TemplateCreateSchema", permission: "MANAGE_GUILD" }),
|
route({ requestBody: "TemplateCreateSchema", permission: "MANAGE_GUILD" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const guild = await Guild.findOneOrFail({
|
const guild = await Guild.findOneOrFail({
|
||||||
@ -115,7 +114,7 @@ router.put(
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/:code",
|
"/:code",
|
||||||
route({ body: "TemplateModifySchema", permission: "MANAGE_GUILD" }),
|
route({ requestBody: "TemplateModifySchema", permission: "MANAGE_GUILD" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { code, guild_id } = req.params;
|
const { code, guild_id } = req.params;
|
||||||
const { name, description } = req.body;
|
const { name, description } = req.body;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
@ -23,8 +24,7 @@ import {
|
|||||||
Invite,
|
Invite,
|
||||||
VanityUrlSchema,
|
VanityUrlSchema,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { Router, Request, Response } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { route } from "@spacebar/api";
|
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
@ -60,7 +60,7 @@ router.get(
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }),
|
route({ requestBody: "VanityUrlSchema", permission: "MANAGE_GUILD" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
const body = req.body as VanityUrlSchema;
|
const body = req.body as VanityUrlSchema;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
@ -26,7 +27,6 @@ import {
|
|||||||
VoiceStateUpdateEvent,
|
VoiceStateUpdateEvent,
|
||||||
VoiceStateUpdateSchema,
|
VoiceStateUpdateSchema,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
@ -34,7 +34,7 @@ const router = Router();
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "VoiceStateUpdateSchema" }),
|
route({ requestBody: "VoiceStateUpdateSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as VoiceStateUpdateSchema;
|
const body = req.body as VoiceStateUpdateSchema;
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
|
||||||
import { Guild, Member, GuildUpdateWelcomeScreenSchema } from "@spacebar/util";
|
|
||||||
import { HTTPError } from "lambert-server";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
|
import { Guild, GuildUpdateWelcomeScreenSchema, Member } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({
|
route({
|
||||||
body: "GuildUpdateWelcomeScreenSchema",
|
requestBody: "GuildUpdateWelcomeScreenSchema",
|
||||||
permission: "MANAGE_GUILD",
|
permission: "MANAGE_GUILD",
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
|
||||||
import { Guild, WidgetModifySchema } from "@spacebar/util";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
|
import { Guild, WidgetModifySchema } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
// https://discord.com/developers/docs/resources/guild#modify-guild-widget
|
// https://discord.com/developers/docs/resources/guild#modify-guild-widget
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "WidgetModifySchema", permission: "MANAGE_GUILD" }),
|
route({ requestBody: "WidgetModifySchema", permission: "MANAGE_GUILD" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as WidgetModifySchema;
|
const body = req.body as WidgetModifySchema;
|
||||||
const { guild_id } = req.params;
|
const { guild_id } = req.params;
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import {
|
|
||||||
Guild,
|
|
||||||
Config,
|
|
||||||
getRights,
|
|
||||||
Member,
|
|
||||||
DiscordApiErrors,
|
|
||||||
GuildCreateSchema,
|
|
||||||
} from "@spacebar/util";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
|
import {
|
||||||
|
Config,
|
||||||
|
DiscordApiErrors,
|
||||||
|
Guild,
|
||||||
|
GuildCreateSchema,
|
||||||
|
Member,
|
||||||
|
getRights,
|
||||||
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ const router: Router = Router();
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "GuildCreateSchema", right: "CREATE_GUILDS" }),
|
route({ requestBody: "GuildCreateSchema", right: "CREATE_GUILDS" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as GuildCreateSchema;
|
const body = req.body as GuildCreateSchema;
|
||||||
|
|
||||||
|
@ -16,18 +16,18 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Template,
|
Config,
|
||||||
|
DiscordApiErrors,
|
||||||
Guild,
|
Guild,
|
||||||
|
GuildTemplateCreateSchema,
|
||||||
|
Member,
|
||||||
Role,
|
Role,
|
||||||
Snowflake,
|
Snowflake,
|
||||||
Config,
|
Template,
|
||||||
Member,
|
|
||||||
GuildTemplateCreateSchema,
|
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
import { DiscordApiErrors } from "@spacebar/util";
|
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ router.get("/:code", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/:code",
|
"/:code",
|
||||||
route({ body: "GuildTemplateCreateSchema" }),
|
route({ requestBody: "GuildTemplateCreateSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const {
|
const {
|
||||||
enabled,
|
enabled,
|
||||||
|
@ -16,18 +16,18 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
ApiError,
|
ApiError,
|
||||||
Application,
|
Application,
|
||||||
ApplicationAuthorizeSchema,
|
ApplicationAuthorizeSchema,
|
||||||
getPermission,
|
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
Member,
|
Member,
|
||||||
Permissions,
|
Permissions,
|
||||||
User,
|
User,
|
||||||
|
getPermission,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
// TODO: scopes, other oauth types
|
// TODO: scopes, other oauth types
|
||||||
@ -135,7 +135,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "ApplicationAuthorizeSchema" }),
|
route({ requestBody: "ApplicationAuthorizeSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as ApplicationAuthorizeSchema;
|
const body = req.body as ApplicationAuthorizeSchema;
|
||||||
// const { client_id, scope, response_type, redirect_url } = req.query;
|
// const { client_id, scope, response_type, redirect_url } = req.query;
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { AckBulkSchema, ReadState } from "@spacebar/util";
|
import { AckBulkSchema, ReadState } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "AckBulkSchema" }),
|
route({ requestBody: "AckBulkSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as AckBulkSchema;
|
const body = req.body as AckBulkSchema;
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ router.get(
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "UserProfileModifySchema" }),
|
route({ requestBody: "UserProfileModifySchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserProfileModifySchema;
|
const body = req.body as UserProfileModifySchema;
|
||||||
|
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Request, Response, Router } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Recipient,
|
|
||||||
DmChannelDTO,
|
|
||||||
Channel,
|
Channel,
|
||||||
DmChannelCreateSchema,
|
DmChannelCreateSchema,
|
||||||
|
DmChannelDTO,
|
||||||
|
Recipient,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "DmChannelCreateSchema" }),
|
route({ requestBody: "DmChannelCreateSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as DmChannelCreateSchema;
|
const body = req.body as DmChannelCreateSchema;
|
||||||
res.json(
|
res.json(
|
||||||
|
@ -29,7 +29,7 @@ const router = Router();
|
|||||||
// TODO: connection update schema
|
// TODO: connection update schema
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "ConnectionUpdateSchema" }),
|
route({ requestBody: "ConnectionUpdateSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { connection_name, connection_id } = req.params;
|
const { connection_name, connection_id } = req.params;
|
||||||
const body = req.body as ConnectionUpdateSchema;
|
const body = req.body as ConnectionUpdateSchema;
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Response, Request } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
Channel,
|
Channel,
|
||||||
Member,
|
Member,
|
||||||
OrmUtils,
|
OrmUtils,
|
||||||
UserGuildSettingsSchema,
|
UserGuildSettingsSchema,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "UserGuildSettingsSchema" }),
|
route({ requestBody: "UserGuildSettingsSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserGuildSettingsSchema;
|
const body = req.body as UserGuildSettingsSchema;
|
||||||
|
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
User,
|
|
||||||
PrivateUserProjection,
|
|
||||||
emitEvent,
|
|
||||||
UserUpdateEvent,
|
|
||||||
handleFile,
|
|
||||||
FieldErrors,
|
|
||||||
adjustEmail,
|
adjustEmail,
|
||||||
Config,
|
Config,
|
||||||
UserModifySchema,
|
emitEvent,
|
||||||
|
FieldErrors,
|
||||||
generateToken,
|
generateToken,
|
||||||
|
handleFile,
|
||||||
|
PrivateUserProjection,
|
||||||
|
User,
|
||||||
|
UserModifySchema,
|
||||||
|
UserUpdateEvent,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { route } from "@spacebar/api";
|
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router: Router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "UserModifySchema" }),
|
route({ requestBody: "UserModifySchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserModifySchema;
|
const body = req.body as UserModifySchema;
|
||||||
|
|
||||||
|
@ -16,21 +16,21 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
BackupCode,
|
BackupCode,
|
||||||
generateMfaBackupCodes,
|
|
||||||
User,
|
|
||||||
CodesVerificationSchema,
|
CodesVerificationSchema,
|
||||||
DiscordApiErrors,
|
DiscordApiErrors,
|
||||||
|
User,
|
||||||
|
generateMfaBackupCodes,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "CodesVerificationSchema" }),
|
route({ requestBody: "CodesVerificationSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
// const { key, nonce, regenerate } = req.body as CodesVerificationSchema;
|
// const { key, nonce, regenerate } = req.body as CodesVerificationSchema;
|
||||||
const { regenerate } = req.body as CodesVerificationSchema;
|
const { regenerate } = req.body as CodesVerificationSchema;
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import {
|
import {
|
||||||
BackupCode,
|
BackupCode,
|
||||||
FieldErrors,
|
FieldErrors,
|
||||||
generateMfaBackupCodes,
|
generateMfaBackupCodes,
|
||||||
User,
|
|
||||||
MfaCodesSchema,
|
MfaCodesSchema,
|
||||||
|
User,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ const router = Router();
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "MfaCodesSchema" }),
|
route({ requestBody: "MfaCodesSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const { password, regenerate } = req.body as MfaCodesSchema;
|
const { password, regenerate } = req.body as MfaCodesSchema;
|
||||||
|
|
||||||
|
@ -16,22 +16,22 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
import { verifyToken } from "node-2fa";
|
|
||||||
import { HTTPError } from "lambert-server";
|
|
||||||
import {
|
import {
|
||||||
User,
|
|
||||||
generateToken,
|
|
||||||
BackupCode,
|
BackupCode,
|
||||||
TotpDisableSchema,
|
TotpDisableSchema,
|
||||||
|
User,
|
||||||
|
generateToken,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { HTTPError } from "lambert-server";
|
||||||
|
import { verifyToken } from "node-2fa";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "TotpDisableSchema" }),
|
route({ requestBody: "TotpDisableSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as TotpDisableSchema;
|
const body = req.body as TotpDisableSchema;
|
||||||
|
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Request, Response } from "express";
|
|
||||||
import {
|
|
||||||
User,
|
|
||||||
generateToken,
|
|
||||||
generateMfaBackupCodes,
|
|
||||||
TotpEnableSchema,
|
|
||||||
} from "@spacebar/util";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
|
import {
|
||||||
|
TotpEnableSchema,
|
||||||
|
User,
|
||||||
|
generateMfaBackupCodes,
|
||||||
|
generateToken,
|
||||||
|
} from "@spacebar/util";
|
||||||
import bcrypt from "bcrypt";
|
import bcrypt from "bcrypt";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { verifyToken } from "node-2fa";
|
import { verifyToken } from "node-2fa";
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ const router = Router();
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "TotpEnableSchema" }),
|
route({ requestBody: "TotpEnableSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as TotpEnableSchema;
|
const body = req.body as TotpEnableSchema;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "WebAuthnPostSchema" }),
|
route({ requestBody: "WebAuthnPostSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
if (!WebAuthn.fido2) {
|
if (!WebAuthn.fido2) {
|
||||||
// TODO: I did this for typescript and I can't use !
|
// TODO: I did this for typescript and I can't use !
|
||||||
|
@ -16,20 +16,20 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
|
||||||
RelationshipAddEvent,
|
|
||||||
User,
|
|
||||||
PublicUserProjection,
|
|
||||||
RelationshipType,
|
|
||||||
RelationshipRemoveEvent,
|
|
||||||
emitEvent,
|
|
||||||
Relationship,
|
|
||||||
Config,
|
|
||||||
} from "@spacebar/util";
|
|
||||||
import { Router, Response, Request } from "express";
|
|
||||||
import { HTTPError } from "lambert-server";
|
|
||||||
import { DiscordApiErrors } from "@spacebar/util";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
|
import {
|
||||||
|
Config,
|
||||||
|
DiscordApiErrors,
|
||||||
|
PublicUserProjection,
|
||||||
|
Relationship,
|
||||||
|
RelationshipAddEvent,
|
||||||
|
RelationshipRemoveEvent,
|
||||||
|
RelationshipType,
|
||||||
|
User,
|
||||||
|
emitEvent,
|
||||||
|
} from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
import { HTTPError } from "lambert-server";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.put(
|
router.put(
|
||||||
"/:id",
|
"/:id",
|
||||||
route({ body: "RelationshipPutSchema" }),
|
route({ requestBody: "RelationshipPutSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
return await updateRelationship(
|
return await updateRelationship(
|
||||||
req,
|
req,
|
||||||
@ -77,7 +77,7 @@ router.put(
|
|||||||
|
|
||||||
router.post(
|
router.post(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "RelationshipPostSchema" }),
|
route({ requestBody: "RelationshipPostSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
return await updateRelationship(
|
return await updateRelationship(
|
||||||
req,
|
req,
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Router, Response, Request } from "express";
|
|
||||||
import { User, UserSettingsSchema } from "@spacebar/util";
|
|
||||||
import { route } from "@spacebar/api";
|
import { route } from "@spacebar/api";
|
||||||
|
import { User, UserSettingsSchema } from "@spacebar/util";
|
||||||
|
import { Request, Response, Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
router.patch(
|
router.patch(
|
||||||
"/",
|
"/",
|
||||||
route({ body: "UserSettingsSchema" }),
|
route({ requestBody: "UserSettingsSchema" }),
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const body = req.body as UserSettingsSchema;
|
const body = req.body as UserSettingsSchema;
|
||||||
if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale
|
if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale
|
||||||
|
@ -52,27 +52,31 @@ export type RouteResponse = {
|
|||||||
export interface RouteOptions {
|
export interface RouteOptions {
|
||||||
permission?: PermissionResolvable;
|
permission?: PermissionResolvable;
|
||||||
right?: RightResolvable;
|
right?: RightResolvable;
|
||||||
body?: `${string}Schema`; // typescript interface name
|
requestBody?: `${string}Schema`; // typescript interface name
|
||||||
responses?: {
|
responses?: {
|
||||||
[status: number]: {
|
[status: number]: {
|
||||||
// body?: `${string}Response`;
|
// body?: `${string}Response`;
|
||||||
body?: string;
|
body?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
test?: {
|
|
||||||
response?: RouteResponse;
|
|
||||||
body?: unknown;
|
|
||||||
path?: string;
|
|
||||||
event?: EVENT | EVENT[];
|
event?: EVENT | EVENT[];
|
||||||
headers?: Record<string, string>;
|
summary?: string;
|
||||||
};
|
description?: string;
|
||||||
|
// test?: {
|
||||||
|
// response?: RouteResponse;
|
||||||
|
// body?: unknown;
|
||||||
|
// path?: string;
|
||||||
|
// event?: EVENT | EVENT[];
|
||||||
|
// headers?: Record<string, string>;
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function route(opts: RouteOptions) {
|
export function route(opts: RouteOptions) {
|
||||||
let validate: AnyValidateFunction | undefined;
|
let validate: AnyValidateFunction | undefined;
|
||||||
if (opts.body) {
|
if (opts.requestBody) {
|
||||||
validate = ajv.getSchema(opts.body);
|
validate = ajv.getSchema(opts.requestBody);
|
||||||
if (!validate) throw new Error(`Body schema ${opts.body} not found`);
|
if (!validate)
|
||||||
|
throw new Error(`Body schema ${opts.requestBody} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return async (req: Request, res: Response, next: NextFunction) => {
|
return async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
export interface LazyRequestSchema {
|
export interface LazyRequestSchema {
|
||||||
guild_id: string;
|
guild_id: string;
|
||||||
channels?: Record<string, [number, number][]>;
|
channels?: {
|
||||||
|
[key: string]: [number, number][];
|
||||||
|
};
|
||||||
activities?: boolean;
|
activities?: boolean;
|
||||||
threads?: boolean;
|
threads?: boolean;
|
||||||
typing?: true;
|
typing?: true;
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { UserGuildSettings, ChannelOverride } from "@spacebar/util";
|
import { ChannelOverride, UserGuildSettings } from "@spacebar/util";
|
||||||
|
|
||||||
// This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema
|
// This sucks. I would use a DeepPartial, my own or typeorms, but they both generate inncorect schema
|
||||||
export interface UserGuildSettingsSchema
|
export interface UserGuildSettingsSchema
|
||||||
extends Partial<Omit<UserGuildSettings, "channel_overrides">> {
|
extends Partial<Omit<UserGuildSettings, "channel_overrides">> {
|
||||||
channel_overrides?: {
|
channel_overrides?: {
|
||||||
[channel_id: string]: Partial<ChannelOverride>;
|
[channel_id: string]: ChannelOverride;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,9 @@ export interface CreateWebAuthnCredentialSchema {
|
|||||||
ticket: string;
|
ticket: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WebAuthnPostSchema = Partial<
|
export type WebAuthnPostSchema =
|
||||||
GenerateWebAuthnCredentialsSchema | CreateWebAuthnCredentialSchema
|
| GenerateWebAuthnCredentialsSchema
|
||||||
>;
|
| CreateWebAuthnCredentialSchema;
|
||||||
|
|
||||||
export interface WebAuthnTotpSchema {
|
export interface WebAuthnTotpSchema {
|
||||||
code: string;
|
code: string;
|
||||||
|
@ -58,7 +58,6 @@ export * from "./PurgeSchema";
|
|||||||
export * from "./RegisterSchema";
|
export * from "./RegisterSchema";
|
||||||
export * from "./RelationshipPostSchema";
|
export * from "./RelationshipPostSchema";
|
||||||
export * from "./RelationshipPutSchema";
|
export * from "./RelationshipPutSchema";
|
||||||
export * from "./responses";
|
|
||||||
export * from "./RoleModifySchema";
|
export * from "./RoleModifySchema";
|
||||||
export * from "./RolePositionUpdateSchema";
|
export * from "./RolePositionUpdateSchema";
|
||||||
export * from "./SelectProtocolSchema";
|
export * from "./SelectProtocolSchema";
|
||||||
@ -80,7 +79,4 @@ export * from "./VoiceVideoSchema";
|
|||||||
export * from "./WebAuthnSchema";
|
export * from "./WebAuthnSchema";
|
||||||
export * from "./WebhookCreateSchema";
|
export * from "./WebhookCreateSchema";
|
||||||
export * from "./WidgetModifySchema";
|
export * from "./WidgetModifySchema";
|
||||||
export * from "./UserRelationsResponse";
|
export * from "./responses";
|
||||||
export * from "./GatewayResponse";
|
|
||||||
export * from "./GatewayBotResponse";
|
|
||||||
export * from "./UserProfileResponse";
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user