From b0d46de170c27fdb16311be9c3fee9947dda1c9a Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Sat, 17 Aug 2024 07:10:40 +0200 Subject: [PATCH 1/4] Order by status & invisible/no session users --- src/gateway/opcodes/LazyRequest.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts index 27e9b00a..45eaccfa 100644 --- a/src/gateway/opcodes/LazyRequest.ts +++ b/src/gateway/opcodes/LazyRequest.ts @@ -68,7 +68,6 @@ async function getMembers(guild_id: string, range: [number, number]) { if (!Array.isArray(range) || range.length !== 2) { throw new Error("range is not a valid array"); } - // TODO: wait for typeorm to implement ordering for .find queries https://github.com/typeorm/typeorm/issues/2620 let members: Member[] = []; try { @@ -82,11 +81,11 @@ async function getMembers(guild_id: string, range: [number, number]) { .leftJoinAndSelect("user.sessions", "session") .addSelect("user.settings") .addSelect( - "CASE WHEN session.status = 'offline' THEN 0 ELSE 1 END", + "CASE WHEN session.status IS NULL OR session.status = 'offline' OR session.status = 'invisible' THEN 0 ELSE 1 END", "_status", ) - .orderBy("role.position", "DESC") - .addOrderBy("_status", "DESC") + .orderBy("_status", "DESC") + .addOrderBy("role.position", "DESC") .addOrderBy("user.username", "ASC") .offset(Number(range[0]) || 0) .limit(Number(range[1]) || 100) From 1bf2424033185eaf9ff1f97b5403142f5b098df0 Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Sun, 25 Aug 2024 06:50:34 +0200 Subject: [PATCH 2/4] Remove auth requirement & fix image path --- src/api/middlewares/Authentication.ts | 2 ++ src/api/middlewares/ImageProxy.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/middlewares/Authentication.ts b/src/api/middlewares/Authentication.ts index ffefee8f..18785908 100644 --- a/src/api/middlewares/Authentication.ts +++ b/src/api/middlewares/Authentication.ts @@ -54,6 +54,8 @@ export const NO_AUTHORIZATION_ROUTES = [ /GET \/guilds\/\d+\/widget\.(json|png)/, // Connections /POST \/connections\/\w+\/callback/, + // Image proxy + /GET \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/ ]; export const API_PREFIX = /^\/api(\/v\d+)?/; diff --git a/src/api/middlewares/ImageProxy.ts b/src/api/middlewares/ImageProxy.ts index 537c5da1..d1d0faa7 100644 --- a/src/api/middlewares/ImageProxy.ts +++ b/src/api/middlewares/ImageProxy.ts @@ -67,7 +67,7 @@ export async function ImageProxy(req: Request, res: Response) { if (!crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(path[0]))) throw new Error("Invalid signature"); } catch { - console.log("Invalid signature, expected " + hash + " got " + path[0]); + console.log("[ImageProxy] Invalid signature, expected " + hash + " but got " + path[0]); res.status(403).send("Invalid signature"); return; } @@ -75,7 +75,7 @@ export async function ImageProxy(req: Request, res: Response) { const abort = new AbortController(); setTimeout(() => abort.abort(), 5000); - const request = await fetch(path.slice(2).join("/"), { + const request = await fetch("https://" + path.slice(2).join("/"), { headers: { "User-Agent": "SpacebarImageProxy/1.0.0 (https://spacebar.chat)", }, From b73b4e95028d6bfda21ed206db30084b5f1085d3 Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Sun, 25 Aug 2024 06:51:30 +0200 Subject: [PATCH 3/4] Run prettier --- src/api/middlewares/Authentication.ts | 2 +- src/api/middlewares/ImageProxy.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/api/middlewares/Authentication.ts b/src/api/middlewares/Authentication.ts index 18785908..ec77cbbb 100644 --- a/src/api/middlewares/Authentication.ts +++ b/src/api/middlewares/Authentication.ts @@ -55,7 +55,7 @@ export const NO_AUTHORIZATION_ROUTES = [ // Connections /POST \/connections\/\w+\/callback/, // Image proxy - /GET \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/ + /GET \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/, ]; export const API_PREFIX = /^\/api(\/v\d+)?/; diff --git a/src/api/middlewares/ImageProxy.ts b/src/api/middlewares/ImageProxy.ts index d1d0faa7..4f9eef10 100644 --- a/src/api/middlewares/ImageProxy.ts +++ b/src/api/middlewares/ImageProxy.ts @@ -67,7 +67,12 @@ export async function ImageProxy(req: Request, res: Response) { if (!crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(path[0]))) throw new Error("Invalid signature"); } catch { - console.log("[ImageProxy] Invalid signature, expected " + hash + " but got " + path[0]); + console.log( + "[ImageProxy] Invalid signature, expected " + + hash + + " but got " + + path[0], + ); res.status(403).send("Invalid signature"); return; } From c62748cbf01e87e213dbce9774063f3a10d49563 Mon Sep 17 00:00:00 2001 From: Cyber Date: Wed, 28 Aug 2024 08:17:54 +0200 Subject: [PATCH 4/4] fix: display pinned message author --- src/api/routes/channels/#channel_id/pins.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/routes/channels/#channel_id/pins.ts b/src/api/routes/channels/#channel_id/pins.ts index d43db6ec..f9586469 100644 --- a/src/api/routes/channels/#channel_id/pins.ts +++ b/src/api/routes/channels/#channel_id/pins.ts @@ -179,6 +179,7 @@ router.get( const pins = await Message.find({ where: { channel_id: channel_id, pinned: true }, + relations: ["author"], }); res.send(pins);