summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorZane Helton <zane99@me.com>2025-06-29 11:34:57 -0400
committerZane Helton <zane99@me.com>2025-06-29 11:34:57 -0400
commit590331518ce6f742773de4d90edaf5cd8dca8dc9 (patch)
tree6664d50192ba194b33c94217ca2cefafe39ba904 /src/api
parentRefactor `/github` endpoint into it's own file (diff)
downloadserver-ts-590331518ce6f742773de4d90edaf5cd8dca8dc9.tar.xz
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.
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/webhooks/#webhook_id/#token/github.ts22
-rw-r--r--src/api/routes/webhooks/#webhook_id/#token/index.ts2
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 3bcda1941..9b2a5fe87 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 d38b68de1..2467a7dba 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); }