From 3a9821626fc7ba3186bb8439e2f8283ea11f1b82 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Sun, 30 Nov 2025 23:41:00 -0600 Subject: [PATCH] fix other bug --- .../channels/#channel_id/messages/search.ts | 4 +- .../guilds/#guild_id/messages/search.ts | 48 +++++-------------- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/api/routes/channels/#channel_id/messages/search.ts b/src/api/routes/channels/#channel_id/messages/search.ts index 9a4acd644..7331945d6 100644 --- a/src/api/routes/channels/#channel_id/messages/search.ts +++ b/src/api/routes/channels/#channel_id/messages/search.ts @@ -99,6 +99,8 @@ router.get( if (content) query.where.content = Like(`%${content}%`); const messages: Message[] = await Message.find(query); + delete query.take; + const total_results = await Message.count(query); const messagesDto = messages.map((x) => [ { @@ -132,7 +134,7 @@ router.get( return res.json({ messages: messagesDto, - total_results: messages.length, + total_results, }); }, ); diff --git a/src/api/routes/guilds/#guild_id/messages/search.ts b/src/api/routes/guilds/#guild_id/messages/search.ts index aaf1113f0..6532b53b2 100644 --- a/src/api/routes/guilds/#guild_id/messages/search.ts +++ b/src/api/routes/guilds/#guild_id/messages/search.ts @@ -54,14 +54,10 @@ router.get( } = req.query; const parsedLimit = Number(limit) || 50; - if (parsedLimit < 1 || parsedLimit > 100) - throw new HTTPError("limit must be between 1 and 100", 422); + if (parsedLimit < 1 || parsedLimit > 100) throw new HTTPError("limit must be between 1 and 100", 422); if (sort_order) { - if ( - typeof sort_order != "string" || - ["desc", "asc"].indexOf(sort_order) == -1 - ) + if (typeof sort_order != "string" || ["desc", "asc"].indexOf(sort_order) == -1) throw FieldErrors({ sort_order: { message: "Value must be one of ('desc', 'asc').", @@ -70,20 +66,13 @@ 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, channel_id as string | undefined); permissions.hasThrow("VIEW_CHANNEL"); - if (!permissions.has("READ_MESSAGE_HISTORY")) - return res.json({ messages: [], total_results: 0 }); + if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json({ messages: [], total_results: 0 }); const query: FindManyOptions = { order: { - timestamp: sort_order - ? (sort_order.toUpperCase() as "ASC" | "DESC") - : "DESC", + timestamp: sort_order ? (sort_order.toUpperCase() as "ASC" | "DESC") : "DESC", }, take: parsedLimit || 0, where: { @@ -91,16 +80,7 @@ router.get( id: req.params.guild_id, }, }, - relations: [ - "author", - "webhook", - "application", - "mentions", - "mention_roles", - "mention_channels", - "sticker_items", - "attachments", - ], + relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"], skip: offset ? Number(offset) : 0, }; //@ts-ignore @@ -114,16 +94,8 @@ router.get( const ids = []; for (const channel of channels) { - const perm = await getPermission( - req.user_id, - req.params.guild_id, - channel.id, - ); - if ( - !perm.has("VIEW_CHANNEL") || - !perm.has("READ_MESSAGE_HISTORY") - ) - continue; + const perm = await getPermission(req.user_id, req.params.guild_id, channel.id); + if (!perm.has("VIEW_CHANNEL") || !perm.has("READ_MESSAGE_HISTORY")) continue; ids.push(channel.id); } @@ -136,6 +108,8 @@ router.get( if (content) query.where.content = Like(`%${content}%`); const messages: Message[] = await Message.find(query); + delete query.take; + const total_results = await Message.count(query); const messagesDto = messages.map((x) => [ { @@ -169,7 +143,7 @@ router.get( return res.json({ messages: messagesDto, - total_results: messages.length, + total_results, }); }, );