From 590331518ce6f742773de4d90edaf5cd8dca8dc9 Mon Sep 17 00:00:00 2001 From: Zane Helton Date: Sun, 29 Jun 2025 11:34:57 -0400 Subject: [PATCH] Make tsc happy when using strings as Date in embed Validation on embeds has interesting behavior. Embeds have a `timestamp` property that is of type `Date`. However when providing a Date, `WebhookExecuteSchema` silently ends the operation. The resolution was to use strings and to annotate them with `// @ts-expect-error`. This was not my first choice, but it was the best option I saw. The other option is to allow `Embeds` to pass strings as a timestamp but I'd want a second opinion before making that change. --- .../webhooks/#webhook_id/#token/github.ts | 22 ++++++++++++++++++- .../webhooks/#webhook_id/#token/index.ts | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/api/routes/webhooks/#webhook_id/#token/github.ts b/src/api/routes/webhooks/#webhook_id/#token/github.ts index 3bcda194..9b2a5fe8 100644 --- a/src/api/routes/webhooks/#webhook_id/#token/github.ts +++ b/src/api/routes/webhooks/#webhook_id/#token/github.ts @@ -29,6 +29,7 @@ const parseGitHubWebhook = ( req.body = discordPayload; // Set default wait=true for GitHub webhooks so they get a response req.query.wait = req.query.wait || "true"; + next(); }; @@ -51,6 +52,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -67,6 +69,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -83,6 +86,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -99,6 +103,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -115,6 +120,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -131,6 +137,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -150,6 +157,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -166,6 +174,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -182,6 +191,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -201,6 +211,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -222,6 +233,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -238,6 +250,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -258,7 +271,8 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, - // TODO: Improve this by adding fields for recent commits + // TODO: Improve this by adding `fields` to show recent commits + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -276,6 +290,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -292,6 +307,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -314,6 +330,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -336,6 +353,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -352,6 +370,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], @@ -368,6 +387,7 @@ function transformGitHubToDiscord( thumbnail: { url: payload.sender?.avatar_url, }, + // @ts-expect-error Validate using string in schema timestamp: new Date().toISOString(), }, ], diff --git a/src/api/routes/webhooks/#webhook_id/#token/index.ts b/src/api/routes/webhooks/#webhook_id/#token/index.ts index d38b68de..2467a7db 100644 --- a/src/api/routes/webhooks/#webhook_id/#token/index.ts +++ b/src/api/routes/webhooks/#webhook_id/#token/index.ts @@ -74,7 +74,7 @@ const messageUpload = multer({ router.post( "/", messageUpload.any(), - (req, res, next) => { + (req, _res, next) => { if (req.body.payload_json) { req.body = JSON.parse(req.body.payload_json); }