Assert req.params type as solely string (express update)

This commit is contained in:
Rory&
2026-02-01 03:49:51 +01:00
parent 36c602dff3
commit 98af6066a2
92 changed files with 275 additions and 266 deletions
@@ -39,7 +39,7 @@ router.post(
}),
async (req: Request, res: Response) => {
const app = await Application.findOneOrFail({
where: { id: req.params.application_id },
where: { id: req.params.application_id as string },
relations: { owner: true },
});
@@ -66,7 +66,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const bot = await User.findOneOrFail({ where: { id: req.params.application_id } });
const bot = await User.findOneOrFail({ where: { id: req.params.application_id as string } });
const owner = req.user;
if (owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
@@ -110,7 +110,7 @@ router.patch(
}
const app = await Application.findOneOrFail({
where: { id: req.params.application_id },
where: { id: req.params.application_id as string },
relations: { bot: true, owner: true },
});
@@ -24,14 +24,14 @@ import { Application, ApplicationCommand, FieldErrors, Snowflake } from "@spaceb
const router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const command = await ApplicationCommand.findOne({ where: { application_id: req.params.application_id, id: req.params.command_id } });
const command = await ApplicationCommand.findOne({ where: { application_id: req.params.application_id as string, id: req.params.command_id as string } });
if (!command) {
res.status(404).send({ code: 404, message: "Unknown application command" });
@@ -47,14 +47,14 @@ router.patch(
requestBody: "ApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, id: req.params.command_id } });
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id as string, id: req.params.command_id as string } });
if (!commandExists) {
res.status(404).send({ code: 404, message: "Unknown application command" });
@@ -78,7 +78,7 @@ router.patch(
}
const commandForDb: ApplicationCommandSchema = {
application_id: req.params.application_id,
application_id: req.params.application_id as string,
name: body.name.trim(),
name_localizations: body.name_localizations,
description: body.description?.trim() || "",
@@ -101,21 +101,21 @@ router.patch(
);
router.delete("/", async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, id: req.params.command_id } });
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id as string, id: req.params.command_id as string } });
if (!commandExists) {
res.status(404).send({ code: 404, message: "Unknown application command" });
return;
}
await ApplicationCommand.delete({ application_id: req.params.application_id, id: req.params.command_id });
await ApplicationCommand.delete({ application_id: req.params.application_id as string, id: req.params.command_id as string });
res.sendStatus(204);
});
@@ -25,14 +25,14 @@ import { IsNull } from "typeorm";
const router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const command = await ApplicationCommand.find({ where: { application_id: req.params.application_id } });
const command = await ApplicationCommand.find({ where: { application_id: req.params.application_id as string } });
res.send(command);
});
@@ -42,7 +42,7 @@ router.post(
requestBody: "ApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
@@ -66,7 +66,7 @@ router.post(
}
const commandForDb: ApplicationCommandSchema = {
application_id: req.params.application_id,
application_id: req.params.application_id as string,
name: body.name.trim(),
name_localizations: body.name_localizations,
description: body.description?.trim() || "",
@@ -83,10 +83,10 @@ router.post(
version: Snowflake.generate(),
};
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, name: body.name.trim() } });
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id as string, name: body.name.trim() } });
if (commandExists) {
await ApplicationCommand.update({ application_id: req.params.application_id, name: body.name.trim() }, commandForDb);
await ApplicationCommand.update({ application_id: req.params.application_id as string, name: body.name.trim() }, commandForDb);
} else {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb);
@@ -102,7 +102,7 @@ router.put(
requestBody: "BulkApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
@@ -112,13 +112,13 @@ router.put(
const body = req.body as ApplicationCommandCreateSchema[];
// Remove commands not present in array
const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: IsNull() } });
const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id as string, guild_id: IsNull() } });
const commandNamesInArray = body.map((c) => c.name);
const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name));
for (const command of commandsNotInArray) {
await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: IsNull(), id: command.id });
await ApplicationCommand.delete({ application_id: req.params.application_id as string, guild_id: IsNull(), id: command.id });
}
for (const command of body) {
@@ -137,7 +137,7 @@ router.put(
}
const commandForDb: ApplicationCommandSchema = {
application_id: req.params.application_id,
application_id: req.params.application_id as string,
name: command.name.trim(),
name_localizations: command.name_localizations,
description: command.description?.trim() || "",
@@ -154,10 +154,10 @@ router.put(
version: Snowflake.generate(),
};
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, name: command.name.trim() } });
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id as string, name: command.name.trim() } });
if (commandExists) {
await ApplicationCommand.update({ application_id: req.params.application_id, name: command.name.trim() }, commandForDb);
await ApplicationCommand.update({ application_id: req.params.application_id as string, name: command.name.trim() }, commandForDb);
} else {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb);
@@ -24,26 +24,28 @@ import { Application, ApplicationCommand, FieldErrors, Guild, Member, Snowflake
const router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const guildExists = await Guild.exists({ where: { id: req.params.guild_id } });
const guildExists = await Guild.exists({ where: { id: req.params.guild_id as string } });
if (!guildExists) {
res.status(404).send({ code: 404, message: "Unknown Server" });
return;
}
if (!(await Member.exists({ where: { id: req.params.application_id, guild_id: req.params.guild_id } }))) {
if (!(await Member.exists({ where: { id: req.params.application_id as string, guild_id: req.params.guild_id as string } }))) {
res.status(401).send({ code: 401, message: "Missing Access" });
return;
}
const command = await ApplicationCommand.findOne({ where: { application_id: req.params.application_id, id: req.params.command_id, guild_id: req.params.guild_id } });
const command = await ApplicationCommand.findOne({
where: { application_id: req.params.application_id as string, id: req.params.command_id as string, guild_id: req.params.guild_id as string },
});
if (!command) {
res.status(404).send({ code: 404, message: "Unknown application command" });
@@ -59,21 +61,21 @@ router.patch(
requestBody: "ApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const guildExists = await Guild.exists({ where: { id: req.params.guild_id } });
const guildExists = await Guild.exists({ where: { id: req.params.guild_id as string } });
if (!guildExists) {
res.status(404).send({ code: 404, message: "Unknown Server" });
return;
}
if (!(await Member.exists({ where: { id: req.params.application_id, guild_id: req.params.guild_id } }))) {
if (!(await Member.exists({ where: { id: req.params.application_id as string, guild_id: req.params.guild_id as string } }))) {
res.status(401).send({ code: 401, message: "Missing Access" });
return;
}
@@ -95,7 +97,7 @@ router.patch(
}
const commandForDb: ApplicationCommandSchema = {
application_id: req.params.application_id,
application_id: req.params.application_id as string,
name: body.name.trim(),
name_localizations: body.name_localizations,
description: body.description?.trim() || "",
@@ -113,7 +115,7 @@ router.patch(
};
const commandExists = await ApplicationCommand.exists({
where: { application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id, name: body.name.trim() },
where: { application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, id: req.params.command_id as string, name: body.name.trim() },
});
if (!commandExists) {
@@ -122,7 +124,7 @@ router.patch(
}
await ApplicationCommand.update(
{ application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id, name: body.name.trim() },
{ application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, id: req.params.command_id as string, name: body.name.trim() },
commandForDb,
);
res.send(commandForDb);
@@ -130,33 +132,35 @@ router.patch(
);
router.delete("/", async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const guildExists = await Guild.exists({ where: { id: req.params.guild_id } });
const guildExists = await Guild.exists({ where: { id: req.params.guild_id as string } });
if (!guildExists) {
res.status(404).send({ code: 404, message: "Unknown Server" });
return;
}
if (!(await Member.exists({ where: { id: req.params.application_id, guild_id: req.params.guild_id } }))) {
if (!(await Member.exists({ where: { id: req.params.application_id as string, guild_id: req.params.guild_id as string } }))) {
res.status(401).send({ code: 401, message: "Missing Access" });
return;
}
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id } });
const commandExists = await ApplicationCommand.exists({
where: { application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, id: req.params.command_id as string },
});
if (!commandExists) {
res.status(404).send({ code: 404, message: "Unknown application command" });
return;
}
await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: req.params.guild_id, id: req.params.command_id });
await ApplicationCommand.delete({ application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, id: req.params.command_id as string });
res.sendStatus(204);
});
@@ -24,26 +24,26 @@ import { Application, ApplicationCommand, FieldErrors, Guild, Member, Snowflake
const router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const guildExists = await Guild.exists({ where: { id: req.params.guild_id } });
const guildExists = await Guild.exists({ where: { id: req.params.guild_id as string } });
if (!guildExists) {
res.status(404).send({ code: 404, message: "Unknown Server" });
return;
}
if (!(await Member.exists({ where: { id: req.params.application_id, guild_id: req.params.guild_id } }))) {
if (!(await Member.exists({ where: { id: req.params.application_id as string, guild_id: req.params.guild_id as string } }))) {
res.status(401).send({ code: 401, message: "Missing Access" });
return;
}
const command = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id } });
const command = await ApplicationCommand.find({ where: { application_id: req.params.application_id as string, guild_id: req.params.guild_id as string } });
res.send(command);
});
@@ -53,21 +53,21 @@ router.post(
requestBody: "ApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const guildExists = await Guild.exists({ where: { id: req.params.guild_id } });
const guildExists = await Guild.exists({ where: { id: req.params.guild_id as string } });
if (!guildExists) {
res.status(404).send({ code: 404, message: "Unknown Server" });
return;
}
if (!(await Member.exists({ where: { id: req.params.application_id, guild_id: req.params.guild_id } }))) {
if (!(await Member.exists({ where: { id: req.params.application_id as string, guild_id: req.params.guild_id as string } }))) {
res.status(401).send({ code: 401, message: "Missing Access" });
return;
}
@@ -89,8 +89,8 @@ router.post(
}
const commandForDb: ApplicationCommandSchema = {
application_id: req.params.application_id,
guild_id: req.params.guild_id,
application_id: req.params.application_id as string,
guild_id: req.params.guild_id as string,
name: body.name.trim(),
name_localizations: body.name_localizations,
description: body.description?.trim() || "",
@@ -107,10 +107,12 @@ router.post(
version: Snowflake.generate(),
};
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id, name: body.name.trim() } });
const commandExists = await ApplicationCommand.exists({
where: { application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, name: body.name.trim() },
});
if (commandExists) {
await ApplicationCommand.update({ application_id: req.params.application_id, guild_id: req.params.guild_id, name: body.name.trim() }, commandForDb);
await ApplicationCommand.update({ application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, name: body.name.trim() }, commandForDb);
} else {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb);
@@ -126,21 +128,21 @@ router.put(
requestBody: "BulkApplicationCommandCreateSchema",
}),
async (req: Request, res: Response) => {
const applicationExists = await Application.exists({ where: { id: req.params.application_id } });
const applicationExists = await Application.exists({ where: { id: req.params.application_id as string } });
if (!applicationExists) {
res.status(404).send({ code: 404, message: "Unknown application" });
return;
}
const guildExists = await Guild.exists({ where: { id: req.params.guild_id } });
const guildExists = await Guild.exists({ where: { id: req.params.guild_id as string } });
if (!guildExists) {
res.status(404).send({ code: 404, message: "Unknown Server" });
return;
}
if (!(await Member.exists({ where: { id: req.params.application_id, guild_id: req.params.guild_id } }))) {
if (!(await Member.exists({ where: { id: req.params.application_id as string, guild_id: req.params.guild_id as string } }))) {
res.status(401).send({ code: 401, message: "Missing Access" });
return;
}
@@ -148,13 +150,13 @@ router.put(
const body = req.body as ApplicationCommandCreateSchema[];
// Remove commands not present in array
const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id } });
const applicationCommands = await ApplicationCommand.find({ where: { application_id: req.params.application_id as string, guild_id: req.params.guild_id as string } });
const commandNamesInArray = body.map((c) => c.name);
const commandsNotInArray = applicationCommands.filter((c) => !commandNamesInArray.includes(c.name));
for (const command of commandsNotInArray) {
await ApplicationCommand.delete({ application_id: req.params.application_id, guild_id: req.params.guild_id, id: command.id });
await ApplicationCommand.delete({ application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, id: command.id });
}
for (const command of body) {
@@ -173,8 +175,8 @@ router.put(
}
const commandForDb: ApplicationCommandSchema = {
application_id: req.params.application_id,
guild_id: req.params.guild_id,
application_id: req.params.application_id as string,
guild_id: req.params.guild_id as string,
name: command.name.trim(),
name_localizations: command.name_localizations,
description: command.description?.trim() || "",
@@ -191,10 +193,12 @@ router.put(
version: Snowflake.generate(),
};
const commandExists = await ApplicationCommand.exists({ where: { application_id: req.params.application_id, guild_id: req.params.guild_id, name: command.name } });
const commandExists = await ApplicationCommand.exists({
where: { application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, name: command.name },
});
if (commandExists) {
await ApplicationCommand.update({ application_id: req.params.application_id, guild_id: req.params.guild_id, name: command.name }, commandForDb);
await ApplicationCommand.update({ application_id: req.params.application_id as string, guild_id: req.params.guild_id as string, name: command.name }, commandForDb);
} else {
commandForDb.id = Snowflake.generate(); // Have to be done that way so the id doesn't change
await ApplicationCommand.save(commandForDb);
@@ -39,7 +39,7 @@ router.get(
}),
async (req: Request, res: Response) => {
const app = await Application.findOneOrFail({
where: { id: req.params.application_id },
where: { id: req.params.application_id as string },
relations: { owner: true, bot: true },
});
if (app.owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
@@ -65,7 +65,7 @@ router.patch(
const body = req.body as ApplicationModifySchema;
const app = await Application.findOneOrFail({
where: { id: req.params.application_id },
where: { id: req.params.application_id as string },
relations: { owner: true, bot: true },
});
@@ -122,7 +122,7 @@ router.post(
}),
async (req: Request, res: Response) => {
const app = await Application.findOneOrFail({
where: { id: req.params.application_id },
where: { id: req.params.application_id as string },
relations: { bot: true, owner: true },
});
if (app.owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
@@ -40,7 +40,7 @@ router.post(
}),
async (req: Request, res: Response) => {
const payload = req.body as UploadAttachmentRequestSchema;
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const user = req.user;
const channel = await Channel.findOneOrFail({ where: { id: channel_id } });
@@ -100,7 +100,7 @@ router.post(
);
router.delete("/:cloud_attachment_url", async (req: Request, res: Response) => {
const { channel_id, cloud_attachment_url } = req.params;
const { channel_id, cloud_attachment_url } = req.params as { [key: string]: string };
const user = req.user;
const channel = await Channel.findOneOrFail({ where: { id: channel_id } });
+1 -1
View File
@@ -41,7 +41,7 @@ router.post(
}),
async (req: Request, res: Response) => {
const payload = req.body as GreetRequestSchema;
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
+3 -3
View File
@@ -37,7 +37,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -61,7 +61,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -147,7 +147,7 @@ router.patch(
}),
async (req: Request, res: Response) => {
const payload = req.body as ChannelModifySchema;
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon);
const channel = await Channel.findOneOrFail({
@@ -43,7 +43,7 @@ router.post(
async (req: Request, res: Response) => {
const { user_id } = req;
const body = req.body as InviteCreateSchema;
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
select: { id: true, name: true, type: true, guild_id: true },
@@ -98,7 +98,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
});
@@ -36,7 +36,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { channel_id, message_id } = req.params;
const { channel_id, message_id } = req.params as { [key: string]: string };
const permission = await getPermission(req.user_id, undefined, channel_id);
permission.hasThrow("VIEW_CHANNEL");
@@ -67,7 +67,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const { message_id, channel_id } = req.params as { [key: string]: string };
let body = req.body as MessageEditSchema;
const message = await Message.findOneOrFail({
@@ -165,7 +165,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { channel_id, message_id } = req.params;
const { channel_id, message_id } = req.params as { [key: string]: string };
const body = req.body as MessageCreateSchema;
const attachments: (MessageCreateAttachment | MessageCreateCloudAttachment)[] = body.attachments ?? [];
@@ -261,7 +261,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const { message_id, channel_id } = req.params as { [key: string]: string };
const message = await Message.findOneOrFail({
where: { id: message_id, channel_id },
@@ -288,7 +288,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const { message_id, channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -68,7 +68,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const { message_id, channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -104,8 +104,8 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const emoji = getEmoji(req.params.emoji);
const { message_id, channel_id } = req.params as { [key: string]: string };
const emoji = getEmoji(req.params.emoji as string);
const message = await Message.findOneOrFail({
where: { id: message_id, channel_id },
@@ -149,8 +149,8 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const emoji = getEmoji(req.params.emoji);
const { message_id, channel_id } = req.params as { [key: string]: string };
const emoji = getEmoji(req.params.emoji as string);
const message = await Message.findOneOrFail({
where: { id: message_id, channel_id },
@@ -186,9 +186,9 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { message_id, channel_id, user_id } = req.params;
const { message_id, channel_id, user_id } = req.params as { [key: string]: string };
if (user_id !== "@me") throw new HTTPError("Invalid user");
const emoji = getEmoji(req.params.emoji);
const emoji = getEmoji(req.params.emoji as string);
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -261,10 +261,10 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
let { user_id } = req.params;
const { message_id, channel_id } = req.params;
let { user_id } = req.params as { [key: string]: string };
const { message_id, channel_id } = req.params as { [key: string]: string };
const emoji = getEmoji(req.params.emoji);
const emoji = getEmoji(req.params.emoji as string);
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -318,10 +318,10 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
let { user_id } = req.params;
const { message_id, channel_id } = req.params;
let { user_id } = req.params as { [key: string]: string };
const { message_id, channel_id } = req.params as { [key: string]: string };
const emoji = getEmoji(req.params.emoji);
const emoji = getEmoji(req.params.emoji as string);
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
@@ -39,7 +39,7 @@ router.post(
}),
async (req: Request, res: Response) => {
// TODO: check for differences with https://github.com/spacebarchat/server/pull/876/files#diff-95be9c4cdfd8ba6f67361cd40b9abc8226b35d83e2bb44bf5b4682f1d66155e9
const { message_id, channel_id } = req.params;
const { message_id, channel_id } = req.params as { [key: string]: string };
const body = req.body as MessageThreadCreationSchema;
const message = await Message.findOneOrFail({
where: { id: message_id, channel_id },
@@ -42,7 +42,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
});
@@ -97,7 +97,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const channel_id = req.params.channel_id;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
});
@@ -329,7 +329,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const body = req.body as MessageCreateSchema;
const attachments: (Attachment | MessageCreateAttachment | MessageCreateCloudAttachment)[] = body.attachments ?? [];
@@ -518,7 +518,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params; // not really a channel id if read_state_type != CHANNEL
const { channel_id } = req.params as { [key: string]: string }; // not really a channel id if read_state_type != CHANNEL
const body = req.body as AcknowledgeDeleteSchema;
if (body.version != 2) return res.status(204).send();
// TODO: handle other read state types
@@ -37,7 +37,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { channel_id, message_id } = req.params;
const { channel_id, message_id } = req.params as { [key: string]: string };
const message = await Message.findOneOrFail({
where: { id: message_id },
@@ -122,7 +122,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { channel_id, message_id } = req.params;
const { channel_id, message_id } = req.params as { [key: string]: string };
const message = await Message.findOneOrFail({
where: { id: message_id },
@@ -169,7 +169,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const pins = await Message.find({
where: { channel_id: channel_id, pinned_at: Not(IsNull()) },
@@ -42,9 +42,9 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { guild_id: req.params.guild_id },
where: { guild_id: req.params.guild_id as string },
select: { id: true },
});
const {
@@ -39,7 +39,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { channel_id, overwrite_id } = req.params;
const { channel_id, overwrite_id } = req.params as { [key: string]: string };
const body = req.body as ChannelPermissionOverwriteSchema;
const channel = await Channel.findOneOrFail({
@@ -82,7 +82,7 @@ router.put(
// TODO: check permission hierarchy
router.delete("/:overwrite_id", route({ permission: "MANAGE_ROLES", responses: { 204: {}, 404: {} } }), async (req: Request, res: Response) => {
const { channel_id, overwrite_id } = req.params;
const { channel_id, overwrite_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
+3 -3
View File
@@ -38,7 +38,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { channel_id, message_id } = req.params;
const { channel_id, message_id } = req.params as { [key: string]: string };
const message = await Message.findOneOrFail({
where: { id: message_id },
@@ -123,7 +123,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { channel_id, message_id } = req.params;
const { channel_id, message_id } = req.params as { [key: string]: string };
const message = await Message.findOneOrFail({
where: { id: message_id },
@@ -170,7 +170,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const pins = await Message.find({
where: { channel_id: channel_id, pinned_at: Not(IsNull()) },
+1 -1
View File
@@ -44,7 +44,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
});
@@ -32,7 +32,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { channel_id, user_id } = req.params;
const { channel_id, user_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
relations: { recipients: true },
@@ -82,7 +82,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { channel_id, user_id } = req.params;
const { channel_id, user_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
relations: { recipients: true },
@@ -41,7 +41,7 @@ router.get(
after?: Snowflake;
limit?: string;
};
const { id: channel_id } = req.params;
const { id: channel_id } = req.params as { [key: string]: string };
if (limit && parseInt(limit) > 100) limit = "100";
@@ -69,7 +69,7 @@ router.post(
}),
async (req: Request, res: Response) => {
// eslint-disable-next-line prefer-const
let { channel_id, user_id } = req.params;
let { channel_id, user_id } = req.params as { [key: string]: string };
const thread = await Channel.findOneOrFail({ where: { id: channel_id } });
if (user_id != "@me") (await thread.getUserPermissions({ user: req.user, guild: thread.guild })).hasThrow(Permissions.FLAGS.SEND_MESSAGES);
@@ -126,7 +126,7 @@ router.delete(
}),
async (req: Request, res: Response) => {
// eslint-disable-next-line prefer-const
let { channel_id, user_id } = req.params;
let { channel_id, user_id } = req.params as { [key: string]: string };
const thread = await Channel.findOneOrFail({ where: { id: channel_id } });
// TODO: require thread creator for private threads
@@ -181,9 +181,9 @@ router.patch(
async (req: Request, res: Response) => {
// TODO
// eslint-disable-next-line prefer-const
let { channel_id } = req.params;
let { channel_id } = req.params as { [key: string]: string };
const thread = await Channel.findOneOrFail({ where: { id: channel_id } });
await Member.IsInGuildOrFail(req.params.user_id, thread.guild_id!);
await Member.IsInGuildOrFail(req.params.user_id as string, thread.guild_id!);
// var threadMember = await ThreadMember.findOneOrFail({ where: { member_id: req.user_id, id: channel_id } });
// await emitEvent({
@@ -33,7 +33,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const user_id = req.user_id;
const timestamp = Math.floor(Date.now() / 1000);
const channel = await Channel.findOneOrFail({
@@ -37,7 +37,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const webhooks = await Webhook.find({
where: { channel_id },
relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true },
@@ -69,7 +69,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const channel_id = req.params.channel_id;
const { channel_id } = req.params as { [key: string]: string };
const channel = await Channel.findOneOrFail({
where: { id: channel_id },
});
@@ -23,7 +23,7 @@ import { ConnectionStore, FieldErrors } from "../../../../util";
const router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const { connection_name } = req.params;
const { connection_name } = req.params as { [key: string]: string };
const connection = ConnectionStore.connections.get(connection_name);
if (!connection)
throw FieldErrors({
@@ -24,7 +24,7 @@ import { ConnectionCallbackSchema } from "@spacebar/schemas";
const router = Router({ mergeParams: true });
router.post("/", route({ requestBody: "ConnectionCallbackSchema" }), async (req: Request, res: Response) => {
const { connection_name } = req.params;
const { connection_name } = req.params as { [key: string]: string };
const connection = ConnectionStore.connections.get(connection_name);
if (!connection)
throw FieldErrors({
+1 -1
View File
@@ -36,7 +36,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { emoji_id } = req.params;
const { emoji_id } = req.params as { [key: string]: string };
const emoji = await Emoji.findOne({ where: { id: emoji_id } });
if (!emoji) {
@@ -25,7 +25,7 @@ import { ApplicationCommandSchema, ApplicationCommandType } from "@spacebar/sche
const router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const members = await Member.find({ where: { guild_id: req.params.guild_id, user: { bot: true } } });
const members = await Member.find({ where: { guild_id: req.params.guild_id as string, user: { bot: true } } });
const applications: Application[] = [];
for (const member of members) {
@@ -50,7 +50,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
for (const application of applications) {
applicationCommands.push(await ApplicationCommand.find({ where: { application_id: application.id, guild_id: IsNull() } }));
applicationCommands.push(await ApplicationCommand.find({ where: { application_id: application.id, guild_id: req.params.guild_id } }));
applicationCommands.push(await ApplicationCommand.find({ where: { application_id: application.id, guild_id: req.params.guild_id as string } }));
}
const applicationCommandsSendable: ApplicationCommandSchema[] = [];
@@ -38,7 +38,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const rules = await AutomodRule.find({ where: { guild_id } });
return res.json(rules);
},
@@ -62,7 +62,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
if (req.user_id !== req.body.creator_id) throw new HTTPError("You can't create a rule for someone else", 403);
if (guild_id !== req.body.guild_id) throw new HTTPError("You can't create a rule for another guild", 403);
@@ -103,7 +103,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { rule_id } = req.params;
const { rule_id } = req.params as { [key: string]: string };
const rule = await AutomodRule.findOneOrFail({
where: { id: rule_id },
});
@@ -131,7 +131,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { rule_id } = req.params;
const { rule_id } = req.params as { [key: string]: string };
await AutomodRule.delete({ id: rule_id });
return res.status(204).send();
},
+6 -6
View File
@@ -40,7 +40,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
let bans = await Ban.find({ where: { guild_id: guild_id } });
const promisesToAwait: Promise<PublicUser>[] = [];
@@ -98,7 +98,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const limit = Number(req.query.limit) || 10;
if (limit > 10 || limit < 1) throw new HTTPError("Limit must be between 1 and 10");
@@ -154,7 +154,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id, user_id } = req.params;
const { guild_id, user_id } = req.params as { [key: string]: string };
const ban = (await Ban.findOneOrFail({
where: { guild_id: guild_id, user_id: user_id },
@@ -196,8 +196,8 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const banned_user_id = req.params.user_id;
const { guild_id } = req.params as { [key: string]: string };
const banned_user_id = req.params.user_id as string;
const opts = req.body as BanCreateSchema;
let deleteMessagesMs = opts.delete_message_days
@@ -262,7 +262,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { guild_id, user_id } = req.params;
const { guild_id, user_id } = req.params as { [key: string]: string };
await Ban.findOneOrFail({
where: { guild_id: guild_id, user_id: user_id },
+1 -1
View File
@@ -42,7 +42,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const userIds: Array<string> = req.body.user_ids;
if (!userIds) throw new HTTPError("The user_ids array is missing", 400);
+3 -3
View File
@@ -32,7 +32,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const channels = await Channel.find({ where: { guild_id } });
for await (const channel of channels) {
@@ -63,7 +63,7 @@ router.post(
}),
async (req: Request, res: Response) => {
// 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 as { [key: string]: string };
const body = req.body as ChannelModifySchema;
const channel = await Channel.createChannel({ ...body, guild_id }, req.user_id);
@@ -90,7 +90,7 @@ router.patch(
}),
async (req: Request, res: Response) => {
// changes guild channel position
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
let body = req.body as ChannelReorderSchema;
const guild = await Guild.findOneOrFail({
+1 -1
View File
@@ -39,7 +39,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({
where: { id: guild_id },
@@ -31,7 +31,7 @@ router.get(
},
}),
(req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
// TODO:
// Load from database
// Admin control, but for now it allows anyone to be discoverable
+5 -5
View File
@@ -36,7 +36,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
await Member.IsInGuildOrFail(req.user_id, guild_id);
@@ -65,7 +65,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id, emoji_id } = req.params;
const { guild_id, emoji_id } = req.params as { [key: string]: string };
await Member.IsInGuildOrFail(req.user_id, guild_id);
@@ -96,7 +96,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const body = req.body as EmojiCreateSchema;
const id = Snowflake.generate();
@@ -153,7 +153,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { emoji_id, guild_id } = req.params;
const { emoji_id, guild_id } = req.params as { [key: string]: string };
const body = req.body as EmojiModifySchema;
if (body.name?.includes("-")) body.name = body.name?.replaceAll("-", ""); // Dashes are invalid apparently
@@ -189,7 +189,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { emoji_id, guild_id } = req.params;
const { emoji_id, guild_id } = req.params as { [key: string]: string };
await Emoji.delete({
id: emoji_id,
+2 -2
View File
@@ -40,7 +40,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const [guild, member] = await Promise.all([Guild.findOneOrFail({ where: { id: guild_id } }), Member.findOne({ where: { guild_id: guild_id, id: req.user_id } })]);
if (!member) throw new HTTPError("You are not a member of the guild you are trying to access", 401);
@@ -74,7 +74,7 @@ router.patch(
}),
async (req: Request, res: Response) => {
const body = req.body as GuildUpdateSchema;
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const rights = await getRights(req.user_id);
const permission = await getPermission(req.user_id, guild_id);
+1 -1
View File
@@ -33,7 +33,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const invites = await Invite.find({
where: { guild_id },
@@ -39,7 +39,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id, member_id } = req.params;
const { guild_id, member_id } = req.params as { [key: string]: string };
await Member.IsInGuildOrFail(req.user_id, guild_id);
const member = await Member.findOneOrFail({
@@ -85,8 +85,8 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const member_id = req.params.member_id === "@me" ? req.user_id : req.params.member_id;
const { guild_id } = req.params as { [key: string]: string };
const member_id = req.params.member_id === "@me" ? req.user_id : (req.params.member_id as string);
const body = req.body as MemberChangeSchema;
const member = await Member.findOneOrFail({
@@ -168,8 +168,8 @@ router.put(
const rights = await getRights(req.user_id);
const { guild_id } = req.params;
let { member_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
let { member_id } = req.params as { [key: string]: string };
if (member_id === "@me") {
member_id = req.user_id;
rights.hasThrow("JOIN_GUILDS");
@@ -216,7 +216,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { guild_id, member_id } = req.params;
const { guild_id, member_id } = req.params as { [key: string]: string };
const permission = await getPermission(req.user_id, guild_id);
const rights = await getRights(req.user_id);
if (member_id === "@me" || member_id === req.user_id) {
@@ -39,9 +39,9 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
let permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
const member_id = req.params.member_id === "@me" ? ((permissionString = "CHANGE_NICKNAME"), req.user_id) : req.params.member_id;
const member_id = req.params.member_id === "@me" ? ((permissionString = "CHANGE_NICKNAME"), req.user_id) : (req.params.member_id as string);
const perms = await getPermission(req.user_id, guild_id);
perms.hasThrow(permissionString);
@@ -34,7 +34,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { guild_id, role_id, member_id } = req.params;
const { guild_id, role_id, member_id } = req.params as { [key: string]: string };
await Member.removeRole(member_id, guild_id, role_id);
res.sendStatus(204);
@@ -51,7 +51,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { guild_id, role_id, member_id } = req.params;
const { guild_id, role_id, member_id } = req.params as { [key: string]: string };
await Member.addRole(member_id, guild_id, role_id);
res.sendStatus(204);
@@ -50,7 +50,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const limit = Number(req.query.limit) || 1;
if (limit > 1000 || limit < 1) throw new HTTPError("Limit must be between 1 and 1000");
const after = `${req.query.after}`;
@@ -66,7 +66,7 @@ router.get(
}); // todo this is wrong
}
const permissions = await getPermission(req.user_id, req.params.guild_id, channel_id as string | undefined);
const permissions = await getPermission(req.user_id, req.params.guild_id as string, channel_id as string | undefined);
permissions.hasThrow("VIEW_CHANNEL");
if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json({ messages: [], total_results: 0 });
@@ -77,7 +77,7 @@ router.get(
take: parsedLimit || 0,
where: {
guild: {
id: req.params.guild_id,
id: req.params.guild_id as string,
},
},
relations: { author: true, webhook: true, application: true, mentions: true, mention_roles: true, mention_channels: true, sticker_items: true, attachments: true },
@@ -88,13 +88,13 @@ router.get(
else {
// get all channel IDs that this user can access
const channels = await Channel.find({
where: { guild_id: req.params.guild_id },
where: { guild_id: req.params.guild_id as string },
select: { id: true },
});
const ids = [];
for (const channel of channels) {
const perm = await getPermission(req.user_id, req.params.guild_id, channel.id);
const perm = await getPermission(req.user_id, req.params.guild_id as string, channel.id);
if (!perm.has("VIEW_CHANNEL") || !perm.has("READ_MESSAGE_HISTORY")) continue;
ids.push(channel.id);
}
+1 -1
View File
@@ -33,7 +33,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
const profileResponse: GuildProfileResponse = {
id: guild_id,
@@ -40,7 +40,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
// const member_id =
// req.params.member_id === "@me" ? req.user_id : req.params.member_id;
const body = req.body as MemberChangeProfileSchema;
+2 -2
View File
@@ -87,7 +87,7 @@ router.get(
let roles = req.query.include_roles;
if (typeof roles === "string") roles = [roles]; //express will return array otherwise
const members = await inactiveMembers(req.params.guild_id, req.user_id, days, roles as string[]);
const members = await inactiveMembers(req.params.guild_id as string, req.user_id, days, roles as string[]);
res.send({ pruned: members.length });
},
@@ -113,7 +113,7 @@ router.post(
let roles = req.query.include_roles;
if (typeof roles === "string") roles = [roles];
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const members = await inactiveMembers(guild_id, req.user_id, days, roles as string[]);
await Promise.all(members.map((x) => Member.removeFromGuild(x.id, guild_id)));
+1 -1
View File
@@ -35,7 +35,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
//TODO we should use an enum for guild's features and not hardcoded strings
return res.json(await getVoiceRegions(req.ip!, guild.features.includes("VIP_REGIONS")));
@@ -40,7 +40,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id, role_id } = req.params;
const { guild_id, role_id } = req.params as { [key: string]: string };
await Member.IsInGuildOrFail(req.user_id, guild_id);
const role = await Role.findOneOrFail({
where: { guild_id, id: role_id },
@@ -67,7 +67,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { guild_id, role_id } = req.params;
const { guild_id, role_id } = req.params as { [key: string]: string };
if (role_id === guild_id) throw new HTTPError("You can't delete the @everyone role");
await Promise.all([
@@ -112,7 +112,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { role_id, guild_id } = req.params;
const { role_id, guild_id } = req.params as { [key: string]: string };
const body = req.body as RoleModifySchema;
if (body.icon && body.icon.length) body.icon = await handleFile(`/role-icons/${role_id}`, body.icon as string);
@@ -23,7 +23,7 @@ import { route } from "@spacebar/api";
const router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const { guild_id, role_id } = req.params;
const { guild_id, role_id } = req.params as { [key: string]: string };
// TODO: Is this route really not paginated?
const members = await Member.find({
@@ -24,7 +24,7 @@ const router = Router({ mergeParams: true });
router.patch("/", route({ permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => {
// Payload is JSON containing a list of member_ids, the new list of members to have the role
const { guild_id, role_id } = req.params;
const { guild_id, role_id } = req.params as { [key: string]: string };
const { member_ids } = req.body;
// don't mess with @everyone
@@ -25,7 +25,7 @@ import { RoleModifySchema, RolePositionUpdateSchema } from "@spacebar/schemas";
const router: Router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const guild_id = req.params.guild_id;
const guild_id = req.params.guild_id as string;
await Member.IsInGuildOrFail(req.user_id, guild_id);
@@ -52,7 +52,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const guild_id = req.params.guild_id;
const guild_id = req.params.guild_id as string;
const body = req.body as RoleModifySchema;
const role_count = await Role.count({ where: { guild_id } });
@@ -124,7 +124,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const body = req.body as RolePositionUpdateSchema;
await Promise.all(body.map(async (x) => Role.update({ guild_id, id: x.id }, { position: x.position })));
@@ -23,7 +23,7 @@ import { route } from "@spacebar/api";
const router: Router = Router({ mergeParams: true });
router.get("/", route({}), async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
await Member.IsInGuildOrFail(req.user_id, guild_id);
const role_ids = await Role.find({ where: { guild_id }, select: { id: true } });
@@ -51,7 +51,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
let cacheEntry = jsonDataCache.get(guild_id);
if (!cacheEntry || cacheEntry.expiry.getTime() < Date.now()) {
+5 -5
View File
@@ -37,7 +37,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
await Member.IsInGuildOrFail(req.user_id, guild_id);
res.json(await Sticker.find({ where: { guild_id } }));
@@ -74,7 +74,7 @@ router.post(
async (req: Request, res: Response) => {
if (!req.file) throw new HTTPError("missing file");
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const body = req.body as ModifyGuildStickerSchema;
const id = Snowflake.generate();
@@ -132,7 +132,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id, sticker_id } = req.params;
const { guild_id, sticker_id } = req.params as { [key: string]: string };
await Member.IsInGuildOrFail(req.user_id, guild_id);
res.json(
@@ -161,7 +161,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { guild_id, sticker_id } = req.params;
const { guild_id, sticker_id } = req.params as { [key: string]: string };
const body = req.body as ModifyGuildStickerSchema;
const sticker = await Sticker.create({
@@ -198,7 +198,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { guild_id, sticker_id } = req.params;
const { guild_id, sticker_id } = req.params as { [key: string]: string };
await Sticker.delete({ guild_id, id: sticker_id });
await sendStickerUpdateEvent(guild_id);
+5 -5
View File
@@ -51,7 +51,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const templates = await Template.find({
where: { source_guild_id: guild_id },
@@ -82,7 +82,7 @@ router.post(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({
where: { id: guild_id },
select: TemplateGuildProjection,
@@ -117,7 +117,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { code, guild_id } = req.params;
const { code, guild_id } = req.params as { [key: string]: string };
const template = await Template.delete({
code,
@@ -138,7 +138,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { code, guild_id } = req.params;
const { code, guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({
where: { id: guild_id },
select: TemplateGuildProjection,
@@ -164,7 +164,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { code, guild_id } = req.params;
const { code, guild_id } = req.params as { [key: string]: string };
const { name, description } = req.body;
const template = await Template.findOneOrFail({
@@ -43,7 +43,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
if (!guild.features.includes("ALIASABLE_NAMES")) {
@@ -82,7 +82,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const body = req.body as VanityUrlSchema;
const code = body.code?.replace(InviteRegex, "");
@@ -43,8 +43,8 @@ router.patch(
}),
async (req: Request, res: Response) => {
const body = req.body as VoiceStateUpdateSchema;
const { guild_id } = req.params;
const user_id = req.params.user_id === "@me" ? req.user_id : req.params.user_id;
const { guild_id } = req.params as { [key: string]: string };
const user_id = req.params.user_id === "@me" ? req.user_id : (req.params.user_id as string);
const perms = await getPermission(req.user_id, guild_id, body.channel_id);
+1 -1
View File
@@ -33,7 +33,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const webhooks = await Webhook.find({
where: { guild_id },
relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true },
@@ -36,7 +36,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const guild_id = req.params.guild_id;
const guild_id = req.params.guild_id as string;
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
await Member.IsInGuildOrFail(req.user_id, guild_id);
@@ -61,7 +61,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const guild_id = req.params.guild_id;
const guild_id = req.params.guild_id as string;
const body = req.body as GuildUpdateWelcomeScreenSchema;
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
@@ -47,7 +47,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
let cacheEntry = jsonDataCache.get(guild_id);
if (!cacheEntry || cacheEntry.expiry.getTime() < Date.now()) {
@@ -46,7 +46,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
if (!guild.widget_enabled) throw DiscordApiErrors.EMBED_DISABLED;
+2 -2
View File
@@ -37,7 +37,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({ where: { id: guild_id } });
@@ -68,7 +68,7 @@ router.patch(
}),
async (req: Request, res: Response) => {
const body = req.body as WidgetModifySchema;
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
await Guild.update(
{ id: guild_id },
+2 -2
View File
@@ -40,7 +40,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { template_code } = req.params;
const { template_code } = req.params as { [key: string]: string };
const template = await getTemplate(template_code);
@@ -49,7 +49,7 @@ router.get(
);
router.post("/:template_code", route({ requestBody: "GuildTemplateCreateSchema" }), async (req: Request, res: Response) => {
const { template_code } = req.params;
const { template_code } = req.params as { [key: string]: string };
const body = req.body as GuildTemplateCreateSchema;
const { maxGuilds } = Config.get().limits.user;
@@ -68,7 +68,7 @@ router.post("/", route({}), async (req: Request, res: Response) => {
throw FieldErrors(errors);
}
const interactionId = req.params.interaction_id;
const interactionId = req.params.interaction_id as string;
const interaction = pendingInteractions.get(req.params.interaction_id);
if (!interaction) {
+3 -3
View File
@@ -37,7 +37,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { invite_code } = req.params;
const { invite_code } = req.params as { [key: string]: string };
const invite = await Invite.findOneOrFail({
where: { code: invite_code },
@@ -70,7 +70,7 @@ router.post(
async (req: Request, res: Response) => {
if (req.user_bot && !Config.get().user.botsCanUseInvites) throw DiscordApiErrors.BOT_PROHIBITED_ENDPOINT;
const { invite_code } = req.params;
const { invite_code } = req.params as { [key: string]: string };
const { public_flags } = req.user;
const { guild_id } = await Invite.findOneOrFail({
where: { code: invite_code },
@@ -128,7 +128,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { invite_code } = req.params;
const { invite_code } = req.params as { [key: string]: string };
const invite = await Invite.findOneOrFail({ where: { code: invite_code } });
const { guild_id, channel_id } = invite;
+1 -1
View File
@@ -34,7 +34,7 @@ router.get(
}),
async (req: Request, res: Response) => {
const app = await Application.findOneOrFail({
where: { id: req.params.id }, // ...huh? there's no ID in the path...
where: { id: req.params.id as string }, // ...huh? there's no ID in the path...
relations: { bot: true, owner: true },
select: {
owner: Object.fromEntries(PublicUserProjection.map((x) => [x, true])),
@@ -22,7 +22,7 @@ import { route } from "@spacebar/api";
const router = Router({ mergeParams: true });
router.get("/", route({}), (req: Request, res: Response) => {
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
// TODO:
// Load from database
// Admin control, but for now it allows anyone to be discoverable
+1 -1
View File
@@ -31,7 +31,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { sticker_id } = req.params;
const { sticker_id } = req.params as { [key: string]: string };
res.json(await Sticker.find({ where: { id: sticker_id } }));
},
@@ -318,7 +318,7 @@ const skus = new Map([
router.get("/", route({}), (req: Request, res: Response) => {
// TODO: add the ability to add custom
const { sku_id } = req.params;
const { sku_id } = req.params as { [key: string]: string };
if (!skus.has(sku_id)) {
console.log(`Request for invalid SKU ${sku_id}! Please report this!`);
+9 -9
View File
@@ -58,7 +58,7 @@ router.post(
const sw = Stopwatch.startNew();
const body = req.body as InstanceUserDeleteSchema | undefined;
const user = await User.findOneOrFail({
where: { id: req.params.user_id },
where: { id: req.params.user_id as string },
select: [...PrivateUserProjection, "data"],
});
@@ -130,11 +130,11 @@ router.post(
);
// change ownership on guilds
const guilds = await Guild.find({ where: { owner_id: req.params.user_id } });
const guilds = await Guild.find({ where: { owner_id: req.params.user_id as string } });
await Promise.all(
guilds.map(async (guild) => {
const members = await Member.find({
where: { guild_id: guild.id, id: Not(req.params.user_id) },
where: { guild_id: guild.id, id: Not(req.params.user_id as string) },
relations: { roles: true },
select: { id: true, roles: { id: true, position: true } },
});
@@ -156,7 +156,7 @@ router.post(
console.log(`[Instance ban] Transferred ownership of guild ${guild.id} to user ${guild.owner_id}`);
// safety - reassign emojis/stickers owned by the old owner
const stickers = await Sticker.find({ where: { guild_id: guild.id, user_id: req.params.user_id } });
const stickers = await Sticker.find({ where: { guild_id: guild.id, user_id: req.params.user_id as string } });
await Promise.all(
stickers.map(async (sticker) => {
sticker.user_id = guild.owner_id;
@@ -165,7 +165,7 @@ router.post(
}),
);
const emojis = await Emoji.find({ where: { guild_id: guild.id, user_id: req.params.user_id } });
const emojis = await Emoji.find({ where: { guild_id: guild.id, user_id: req.params.user_id as string } });
await Promise.all(
emojis.map(async (emoji) => {
emoji.user_id = guild.owner_id!;
@@ -177,16 +177,16 @@ router.post(
}),
);
const members = await Member.find({ where: { id: req.params.user_id } });
const members = await Member.find({ where: { id: req.params.user_id as string } });
await Promise.all([...members.map((member) => Member.removeFromGuild(member.id, member.guild_id))]);
await UserSettingsProtos.delete({ user_id: req.params.user_id });
await User.delete({ id: req.params.user_id });
await UserSettingsProtos.delete({ user_id: req.params.user_id as string });
await User.delete({ id: req.params.user_id as string });
// TODO: respect intents as USER_DELETE has potential to cause privacy issues
await emitEvent({
event: "USER_DELETE",
user_id: req.user_id,
data: { user_id: req.params.user_id },
data: { user_id: req.params.user_id as string },
} as UserDeleteEvent);
console.log(`[Instance ban] Deleted user ${user.id} from instance in ${sw.elapsed().toString()}`);
+1 -1
View File
@@ -32,7 +32,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { user_id } = req.params;
const { user_id } = req.params as { [key: string]: string };
res.json(await User.getPublicUser(user_id));
},
+1 -1
View File
@@ -35,7 +35,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const user = await User.findOneOrFail({ where: { id: req.params.user_id } });
const user = await User.findOneOrFail({ where: { id: req.params.user_id as string } });
const channel = await user.getDmChannelWith(req.user_id);
const messages = (
+1 -1
View File
@@ -28,7 +28,7 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
if (req.params.user_id === "@me") req.params.user_id = req.user_id;
const { guild_id, with_mutual_guilds, with_mutual_friends, with_mutual_friends_count } = req.query;
const { user_id } = req.params;
const { user_id } = req.params as { [key: string]: string };
const user = await User.findOneOrFail({
where: {
@@ -37,7 +37,7 @@ router.get(
const mutual_relations: UserRelationsResponse = [];
const requested_relations = await User.findOneOrFail({
where: { id: req.params.user_id },
where: { id: req.params.user_id as string },
relations: { relationships: true },
});
const self_relations = await User.findOneOrFail({
@@ -28,7 +28,7 @@ const ALLOWED_CONNECTIONS = ["twitch", "youtube"];
// NOTE: this route has not been extensively tested, as the required connections are not implemented as of writing
router.get("/", route({}), async (req: Request, res: Response) => {
const { connection_name, connection_id } = req.params;
const { connection_name, connection_id } = req.params as { [key: string]: string };
const connection = ConnectionStore.connections.get(connection_name);
@@ -24,7 +24,7 @@ const router = Router({ mergeParams: true });
// TODO: connection update schema
router.patch("/", route({ requestBody: "ConnectionUpdateSchema" }), async (req: Request, res: Response) => {
const { connection_name, connection_id } = req.params;
const { connection_name, connection_id } = req.params as { [key: string]: string };
const body = req.body as ConnectionUpdateSchema;
const connection = await ConnectedAccount.findOne({
@@ -63,7 +63,7 @@ router.patch("/", route({ requestBody: "ConnectionUpdateSchema" }), async (req:
});
router.delete("/", route({}), async (req: Request, res: Response) => {
const { connection_name, connection_id } = req.params;
const { connection_name, connection_id } = req.params as { [key: string]: string };
const account = await ConnectedAccount.findOneOrFail({
where: {
+1 -1
View File
@@ -64,7 +64,7 @@ router.delete(
}),
async (req: Request, res: Response) => {
const { autoJoin } = Config.get().guild;
const { guild_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
const guild = await Guild.findOneOrFail({
where: { id: guild_id },
select: { owner_id: true },
@@ -34,7 +34,7 @@ router.get(
}),
async (req: Request, res: Response) => {
const user = await Member.findOneOrFail({
where: { id: req.user_id, guild_id: req.params.guild_id },
where: { id: req.user_id, guild_id: req.params.guild_id as string },
select: { settings: true },
});
return res.json(user.settings);
@@ -65,11 +65,11 @@ router.patch(
}
const user = await Member.findOneOrFail({
where: { id: req.user_id, guild_id: req.params.guild_id },
where: { id: req.user_id, guild_id: req.params.guild_id as string },
select: { settings: true },
});
OrmUtils.mergeDeep(user.settings || {}, body);
Member.update({ id: req.user_id, guild_id: req.params.guild_id }, user);
Member.update({ id: req.user_id, guild_id: req.params.guild_id as string }, user);
res.json(user.settings);
},
@@ -29,7 +29,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { key_id } = req.params;
const { key_id } = req.params as { [key: string]: string };
await SecurityKey.delete({
id: key_id,
+2 -2
View File
@@ -35,7 +35,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { user_id } = req.params;
const { user_id } = req.params as { [key: string]: string };
const note = await Note.findOneOrFail({
where: {
@@ -64,7 +64,7 @@ router.put(
},
}),
async (req: Request, res: Response) => {
const { user_id } = req.params;
const { user_id } = req.params as { [key: string]: string };
const owner = req.user;
const target = await User.findOneOrFail({ where: { id: user_id } }); //if noted user does not exist throw
const { note } = req.body;
+3 -3
View File
@@ -69,7 +69,7 @@ router.put(
req,
res,
await User.findOneOrFail({
where: { id: req.params.user_id },
where: { id: req.params.user_id as string },
relations: { relationships: { to: true } },
select: userProjection,
}),
@@ -97,7 +97,7 @@ router.patch(
const rel = await Relationship.findOneOrFail({
where: {
from_id: req.user_id,
to_id: req.params.user_id,
to_id: req.params.user_id as string,
},
});
rel.nickname = body.nickname;
@@ -161,7 +161,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { user_id } = req.params;
const { user_id } = req.params as { [key: string]: string };
if (user_id === req.user_id) throw new HTTPError("You can't remove yourself as a friend");
const user = await User.findOneOrFail({
@@ -19,7 +19,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { webhook_id, token } = req.params;
const { webhook_id, token } = req.params as { [key: string]: string };
const webhook = await Webhook.findOne({
where: {
id: webhook_id,
@@ -101,7 +101,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { webhook_id, token } = req.params;
const { webhook_id, token } = req.params as { [key: string]: string };
const webhook = await Webhook.findOne({
where: {
@@ -149,7 +149,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { webhook_id, token } = req.params;
const { webhook_id, token } = req.params as { [key: string]: string };
const body = req.body as WebhookUpdateSchema;
const webhook = await Webhook.findOneOrFail({
+3 -3
View File
@@ -17,7 +17,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
const { webhook_id } = req.params;
const { webhook_id } = req.params as { [key: string]: string };
const webhook = await Webhook.findOneOrFail({
where: { id: webhook_id },
relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true },
@@ -48,7 +48,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
const { webhook_id } = req.params;
const { webhook_id } = req.params as { [key: string]: string };
const webhook = await Webhook.findOneOrFail({
where: { id: webhook_id },
@@ -93,7 +93,7 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
const { webhook_id } = req.params;
const { webhook_id } = req.params as { [key: string]: string };
const body = req.body as WebhookUpdateSchema;
const webhook = await Webhook.findOneOrFail({
+1 -1
View File
@@ -8,7 +8,7 @@ import { WebhookExecuteSchema } from "@spacebar/schemas";
export const executeWebhook = async (req: Request, res: Response) => {
const body = req.body as WebhookExecuteSchema;
const { webhook_id, token } = req.params;
const { webhook_id, token } = req.params as { [key: string]: string };
const webhook = await Webhook.findOne({
where: {
+2 -1
View File
@@ -89,7 +89,8 @@ export function route(opts: RouteOptions) {
return async (req: Request, res: Response, next: NextFunction) => {
if (opts.permission) {
req.permission = await getPermission(req.user_id, req.params.guild_id, req.params.channel_id);
const { guild_id, channel_id } = req.params as { [key: string]: string };
req.permission = await getPermission(req.user_id, guild_id, channel_id);
const requiredPerms = Array.isArray(opts.permission) ? opts.permission : [opts.permission];
requiredPerms.forEach((perm) => {
+6 -6
View File
@@ -36,7 +36,7 @@ router.post("/:channel_id", multer.single("file"), async (req: Request, res: Res
if (!req.file) throw new HTTPError("file missing");
const { buffer, mimetype, size, originalname } = req.file;
const { channel_id } = req.params;
const { channel_id } = req.params as { [key: string]: string };
const filename = originalname.replaceAll(" ", "_").replace(/[^a-zA-Z0-9._]+/g, "");
const id = Snowflake.generate();
const path = `attachments/${channel_id}/${id}/${filename}`;
@@ -71,7 +71,7 @@ router.post("/:channel_id", multer.single("file"), async (req: Request, res: Res
});
router.get("/:channel_id/:id/:filename", cache, async (req: Request, res: Response) => {
const { channel_id, id, filename } = req.params;
const { channel_id, id, filename } = req.params as { [key: string]: string };
// const { format } = req.query;
const path = `attachments/${channel_id}/${id}/${filename}`;
@@ -108,7 +108,7 @@ router.get("/:channel_id/:id/:filename", cache, async (req: Request, res: Respon
router.delete("/:channel_id/:id/:filename", async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
const { channel_id, id, filename } = req.params;
const { channel_id, id, filename } = req.params as { [key: string]: string };
const path = `attachments/${channel_id}/${id}/${filename}`;
await storage.delete(path);
@@ -118,7 +118,7 @@ router.delete("/:channel_id/:id/:filename", async (req: Request, res: Response)
// "cloud attachments"
router.put("/:channel_id/:batch_id/:attachment_id/:filename", multer.single("file"), async (req: Request, res: Response) => {
const { channel_id, batch_id, attachment_id, filename } = req.params;
const { channel_id, batch_id, attachment_id, filename } = req.params as { [key: string]: string };
const att = await CloudAttachment.findOneOrFail({
where: {
uploadFilename: `${channel_id}/${batch_id}/${attachment_id}/${filename}`,
@@ -177,7 +177,7 @@ router.delete("/:channel_id/:batch_id/:attachment_id/:filename", async (req: Req
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
console.log("[Cloud Delete] Deleting attachment", req.params);
const { channel_id, batch_id, attachment_id, filename } = req.params;
const { channel_id, batch_id, attachment_id, filename } = req.params as { [key: string]: string };
const path = `attachments/${channel_id}/${batch_id}/${attachment_id}/${filename}`;
const att = await CloudAttachment.findOne({
@@ -201,7 +201,7 @@ router.post("/:channel_id/:batch_id/:attachment_id/:filename/clone_to_message/:m
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
console.log("[Cloud Clone] Cloning attachment to message", req.params);
const { channel_id, batch_id, attachment_id, filename, message_id } = req.params;
const { channel_id, batch_id, attachment_id, filename, message_id } = req.params as { [key: string]: string };
const path = `attachments/${channel_id}/${batch_id}/${attachment_id}/${filename}`;
const newPath = `attachments/${channel_id}/${message_id}/${filename}`;
+5 -5
View File
@@ -40,7 +40,7 @@ router.post("/:user_id", multer.single("file"), async (req: Request, res: Respon
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file");
const { buffer, size } = req.file;
const { user_id } = req.params;
const { user_id } = req.params as { [key: string]: string };
let hash = crypto.createHash("md5").update(Snowflake.generate()).digest("hex");
@@ -62,7 +62,7 @@ router.post("/:user_id", multer.single("file"), async (req: Request, res: Respon
});
router.get("/:user_id", cache, async (req: Request, res: Response) => {
let { user_id } = req.params;
let { user_id } = req.params as { [key: string]: string };
user_id = user_id.split(".")[0]; // remove .file extension
const path = `avatars/${user_id}`;
@@ -76,8 +76,8 @@ router.get("/:user_id", cache, async (req: Request, res: Response) => {
});
export const getAvatar = async (req: Request, res: Response) => {
const { user_id } = req.params;
let { hash } = req.params;
const { user_id } = req.params as { [key: string]: string };
let { hash } = req.params as { [key: string]: string };
hash = hash.split(".")[0]; // remove .file extension
const path = `avatars/${user_id}/${hash}`;
@@ -94,7 +94,7 @@ router.get("/:user_id/:hash", cache, getAvatar);
router.delete("/:user_id/:id", async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
const { user_id, id } = req.params;
const { user_id, id } = req.params as { [key: string]: string };
const path = `avatars/${user_id}/${id}`;
await storage.delete(path);
+1 -1
View File
@@ -25,7 +25,7 @@ import { cache } from "../util/cache";
const router = Router({ mergeParams: true });
router.get("/:badge_id", cache, async (req: Request, res: Response) => {
const { badge_id } = req.params;
const { badge_id } = req.params as { [key: string]: string };
const path = `badge-icons/${badge_id}`;
const file = await storage.get(path);
+2 -2
View File
@@ -60,7 +60,7 @@ async function getFile(path: string) {
}
router.get("/avatars/:id", cache, async (req: Request, res: Response) => {
let { id } = req.params;
let { id } = req.params as { [key: string]: string };
id = id.split(".")[0]; // remove .file extension
const hash = defaultAvatarHashMap.get(id);
if (!hash) throw new HTTPError("not found", 404);
@@ -76,7 +76,7 @@ router.get("/avatars/:id", cache, async (req: Request, res: Response) => {
});
router.get("/group-avatars/:id", cache, async (req: Request, res: Response) => {
let { id } = req.params;
let { id } = req.params as { [key: string]: string };
id = id.split(".")[0]; // remove .file extension
const hash = defaultGroupDMAvatarHashMap.get(id);
if (!hash) throw new HTTPError("not found", 404);
+6 -6
View File
@@ -40,7 +40,7 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file");
const { buffer, size } = req.file;
const { guild_id, user_id } = req.params;
const { guild_id, user_id } = req.params as { [key: string]: string };
let hash = crypto.createHash("md5").update(Snowflake.generate()).digest("hex");
@@ -62,8 +62,8 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => {
});
router.get("/", cache, async (req: Request, res: Response) => {
const { guild_id } = req.params;
let { user_id } = req.params;
const { guild_id } = req.params as { [key: string]: string };
let { user_id } = req.params as { [key: string]: string };
user_id = user_id.split(".")[0]; // remove .file extension
const path = `guilds/${guild_id}/users/${user_id}/avatars`;
@@ -77,8 +77,8 @@ router.get("/", cache, async (req: Request, res: Response) => {
});
router.get("/:hash", cache, async (req: Request, res: Response) => {
const { guild_id, user_id } = req.params;
let { hash } = req.params;
const { guild_id, user_id } = req.params as { [key: string]: string };
let { hash } = req.params as { [key: string]: string };
hash = hash.split(".")[0]; // remove .file extension
const path = `guilds/${guild_id}/users/${user_id}/avatars/${hash}`;
@@ -93,7 +93,7 @@ router.get("/:hash", cache, async (req: Request, res: Response) => {
router.delete("/:id", async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
const { guild_id, user_id, id } = req.params;
const { guild_id, user_id, id } = req.params as { [key: string]: string };
const path = `guilds/${guild_id}/users/${user_id}/avatars/${id}`;
await storage.delete(path);
+4 -4
View File
@@ -40,7 +40,7 @@ router.post("/:role_id", multer.single("file"), async (req: Request, res: Respon
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file");
const { buffer, size } = req.file;
const { role_id } = req.params;
const { role_id } = req.params as { [key: string]: string };
const hash = crypto.createHash("md5").update(Snowflake.generate()).digest("hex");
@@ -61,7 +61,7 @@ router.post("/:role_id", multer.single("file"), async (req: Request, res: Respon
});
router.get("/:role_id", cache, async (req: Request, res: Response) => {
const { role_id } = req.params;
const { role_id } = req.params as { [key: string]: string };
//role_id = role_id.split(".")[0]; // remove .file extension
const path = `role-icons/${role_id}`;
@@ -75,7 +75,7 @@ router.get("/:role_id", cache, async (req: Request, res: Response) => {
});
router.get("/:role_id/:hash", cache, async (req: Request, res: Response) => {
const { role_id, hash } = req.params;
const { role_id, hash } = req.params as { [key: string]: string };
//hash = hash.split(".")[0]; // remove .file extension
const requested_extension = hash.split(".")[1];
const role_icon_hash = hash.split(".")[0];
@@ -98,7 +98,7 @@ router.get("/:role_id/:hash", cache, async (req: Request, res: Response) => {
router.delete("/:role_id/:id", async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
const { role_id, id } = req.params;
const { role_id, id } = req.params as { [key: string]: string };
const path = `role-icons/${role_id}/${id}`;
await storage.delete(path);
+5 -5
View File
@@ -49,7 +49,7 @@ export function createBasicCrdFileRouter(opts: BasicCrdFileRouterOptions) {
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
if (!req.file) throw new HTTPError("Missing file");
const { buffer, size } = req.file;
const { user_id } = req.params;
const { user_id } = req.params as { [key: string]: string };
let hash = crypto.createHash("md5").update(Snowflake.generate()).digest("hex");
@@ -71,7 +71,7 @@ export function createBasicCrdFileRouter(opts: BasicCrdFileRouterOptions) {
});
router.get("/:user_id", async (req: Request, res: Response) => {
let { user_id } = req.params;
let { user_id } = req.params as { [key: string]: string };
user_id = user_id.split(".")[0]; // remove .file extension
const path = `${opts.pathPrefix}/${user_id}`;
@@ -86,8 +86,8 @@ export function createBasicCrdFileRouter(opts: BasicCrdFileRouterOptions) {
});
const getAvatar = async (req: Request, res: Response) => {
const { user_id } = req.params;
let { hash } = req.params;
const { user_id } = req.params as { [key: string]: string };
let { hash } = req.params as { [key: string]: string };
hash = hash.split(".")[0]; // remove .file extension
const path = `${opts.pathPrefix}/${user_id}/${hash}`;
@@ -105,7 +105,7 @@ export function createBasicCrdFileRouter(opts: BasicCrdFileRouterOptions) {
router.delete("/:user_id/:hash", async (req: Request, res: Response) => {
if (req.headers.signature !== Config.get().security.requestSignature) throw new HTTPError("Invalid request signature");
const { user_id, hash } = req.params;
const { user_id, hash } = req.params as { [key: string]: string };
const path = `${opts.pathPrefix}/${user_id}/${hash}`;
await storage.delete(path);