1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-25 19:52:36 +01:00

Fix regression of 5f22faa57b

This commit is contained in:
Madeline 2023-07-28 09:45:13 +10:00
parent 5f22faa57b
commit 08f17f88e7
No known key found for this signature in database
GPG Key ID: 80D25DA3BCB24281

View File

@ -119,25 +119,26 @@ router.get(
};
let messages: Message[];
if (after) {
if (BigInt(after) > BigInt(Snowflake.generate()))
return res.status(422);
query.where.id = MoreThan(after);
messages = await Message.find(query);
} else if (before) {
if (BigInt(before) < BigInt(req.params.channel_id))
return res.status(422);
query.where.id = LessThan(before);
messages = await Message.find(query);
} else if (around) {
if (around) {
query.take = Math.floor(limit / 2);
query.where.id = LessThan(around);
const messages_before = await Message.find(query);
query.where.id = MoreThan(around);
const messages_after = await Message.find(query);
messages = messages_before.concat(messages_after);
const [right, left] = await Promise.all([
Message.find({ ...query, where: { id: LessThan(around) } }),
Message.find({ ...query, where: { id: MoreThan(around) } }),
]);
messages = right.concat(left);
} else {
throw new HTTPError("after, around or before must be present", 422);
if (after) {
if (BigInt(after) > BigInt(Snowflake.generate()))
return res.status(422);
query.where.id = MoreThan(after);
} else if (before) {
if (BigInt(before) < BigInt(Snowflake.generate()))
return res.status(422);
query.where.id = LessThan(before);
}
messages = await Message.find(query);
}
const endpoint = Config.get().cdn.endpointPublic;