mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-15 07:25:18 +00:00
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.
This commit is contained in:
@@ -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(),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user