From 09f6a15b41476443a546f48b9158ff3b041189cf Mon Sep 17 00:00:00 2001 From: shay <43248357+shayypy@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:35:38 -0600 Subject: [PATCH 1/3] fix: `measurements` sometimes missing for vanity metadata --- src/controllers/shield.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controllers/shield.ts b/src/controllers/shield.ts index 9b0081d..4e190df 100644 --- a/src/controllers/shield.ts +++ b/src/controllers/shield.ts @@ -31,8 +31,10 @@ export const getMemberCountFromGuilded = async ( let returnData; if (type === "vanity") - returnData = (data.metadata as VanityInviteInfo)?.team?.measurements - ?.numMembers; + returnData = ( + (data.metadata as VanityInviteInfo)?.team?.measurements?.numMembers ?? + (data.metadata as VanityInviteInfo)?.team?.memberCount + ); else if (type === "i") returnData = (data.metadata as IInviteInfo)?.inviteInfo?.team ?.memberCount; From 1bea384c9ae7897c581dc20a89d5ede0a351af08 Mon Sep 17 00:00:00 2001 From: shay <43248357+shayypy@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:39:47 -0600 Subject: [PATCH 2/3] fix: type `memberCount` in vanity info interface --- src/types.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 77d9d7b..6aabdc9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -25,7 +25,8 @@ export interface VanityInviteInfo { team: { id: string; name: string; - measurements: { numMembers: number }; + measurements?: { numMembers: number }; + memberCount: number; }; } From 1f8758b39cf06adfd8c421c58a0891810a8a2432 Mon Sep 17 00:00:00 2001 From: shay <43248357+shayypy@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:45:37 -0600 Subject: [PATCH 3/3] chore: lint, format --- .eslintrc.js | 8 +++++++- .prettierrc.json | 8 ++++---- _config.yml | 2 +- docker-compose.dev.yml | 2 +- src/controllers/shield.ts | 16 +++++++++------- src/routes/shields.ts | 14 +++++++++----- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 603192e..a12c27a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,7 +3,13 @@ module.exports = { project: "./tsconfig.json", }, extends: "@sapphire", - ignorePatterns: ["**/node_modules/**", "**/dist/**", "**/types/**", "**/scripts/**", "*.d.ts"], + ignorePatterns: [ + "**/node_modules/**", + "**/dist/**", + "**/types/**", + "**/scripts/**", + "*.d.ts", + ], rules: { "@typescript-eslint/member-ordering": "off", "@typescript-eslint/no-floating-promises": "off", diff --git a/.prettierrc.json b/.prettierrc.json index bf8d484..7111df5 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,6 +1,6 @@ { - "singleQuote": false, - "semi": true, - "trailingComma": "all", - "tabWidth": 4 + "singleQuote": false, + "semi": true, + "trailingComma": "all", + "tabWidth": 4 } diff --git a/_config.yml b/_config.yml index c741881..f980e76 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-slate \ No newline at end of file +theme: jekyll-theme-slate diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 88ab0d8..4f6ced9 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -3,4 +3,4 @@ services: api: command: ["npm", "run", "start:dev"] volumes: - - "./src:/usr/app/src" \ No newline at end of file + - "./src:/usr/app/src" diff --git a/src/controllers/shield.ts b/src/controllers/shield.ts index 4e190df..6215206 100644 --- a/src/controllers/shield.ts +++ b/src/controllers/shield.ts @@ -31,10 +31,10 @@ export const getMemberCountFromGuilded = async ( let returnData; if (type === "vanity") - returnData = ( - (data.metadata as VanityInviteInfo)?.team?.measurements?.numMembers ?? - (data.metadata as VanityInviteInfo)?.team?.memberCount - ); + returnData = + (data.metadata as VanityInviteInfo)?.team?.measurements + ?.numMembers ?? + (data.metadata as VanityInviteInfo)?.team?.memberCount; else if (type === "i") returnData = (data.metadata as IInviteInfo)?.inviteInfo?.team ?.memberCount; @@ -69,9 +69,11 @@ export const generateSvg = async ( label: "Guilded", message: `${msg} members`, }); - await redis.set(`badge:${type}:${inviteId}:${color}:${style}`, svg, { - EX: 900, - }).catch(() => void 0); + await redis + .set(`badge:${type}:${inviteId}:${color}:${style}`, svg, { + EX: 900, + }) + .catch(() => void 0); return svg; } catch (e) { return internalError(res, (e as Error).message); diff --git a/src/routes/shields.ts b/src/routes/shields.ts index c508011..4567538 100644 --- a/src/routes/shields.ts +++ b/src/routes/shields.ts @@ -31,16 +31,18 @@ export const getServerShield = async ( return badRequest(res, "Invalid style."); } - const cachedBadge = await redis.get( - `badge:${type}:${inviteId}:${color}:${receivedStyle}`, - ).catch(() => null); + const cachedBadge = await redis + .get(`badge:${type}:${inviteId}:${color}:${receivedStyle}`) + .catch(() => null); if (cachedBadge) { res.header("Content-Type", "image/svg+xml"); return res.status(200).send(cachedBadge); } let memberCount: string | null; - const cachedGuildedReq = await redis.get(`req:${type}:${inviteId}`).catch(() => null); + const cachedGuildedReq = await redis + .get(`req:${type}:${inviteId}`) + .catch(() => null); if (cachedGuildedReq) memberCount = cachedGuildedReq; else { const memberCountReq = await getMemberCountFromGuilded(inviteId, type); @@ -51,7 +53,9 @@ export const getServerShield = async ( ); memberCount = memberCountReq.toString(); - await redis.set(`req:${type}:${inviteId}`, memberCount, { EX: 900 }).catch(() => void 0); + await redis + .set(`req:${type}:${inviteId}`, memberCount, { EX: 900 }) + .catch(() => void 0); } const svg = await generateSvg(redis, res, {