summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 18:24:21 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-25 23:35:18 +1000
commitf44f5d7ac2d24ff836c2e1d4b2fa58da04b13052 (patch)
treea6655c41bb3db79c30fd876b06ee60fe9cf70c9b /api/src
parentAllow edited_timestamp to passthrough in handleMessage (diff)
downloadserver-f44f5d7ac2d24ff836c2e1d4b2fa58da04b13052.tar.xz
Refactor to mono-repo + upgrade packages
Diffstat (limited to '')
-rw-r--r--api/src/global.d.ts8
-rw-r--r--src/api/Server.ts (renamed from api/src/Server.ts)0
-rw-r--r--src/api/index.ts (renamed from api/src/index.ts)0
-rw-r--r--src/api/middlewares/Authentication.ts (renamed from api/src/middlewares/Authentication.ts)0
-rw-r--r--src/api/middlewares/BodyParser.ts (renamed from api/src/middlewares/BodyParser.ts)0
-rw-r--r--src/api/middlewares/CORS.ts (renamed from api/src/middlewares/CORS.ts)0
-rw-r--r--src/api/middlewares/ErrorHandler.ts (renamed from api/src/middlewares/ErrorHandler.ts)0
-rw-r--r--src/api/middlewares/RateLimit.ts (renamed from api/src/middlewares/RateLimit.ts)0
-rw-r--r--src/api/middlewares/Translation.ts (renamed from api/src/middlewares/Translation.ts)4
-rw-r--r--src/api/middlewares/index.ts (renamed from api/src/middlewares/index.ts)0
-rw-r--r--src/api/routes/-/healthz.ts (renamed from api/src/routes/-/healthz.ts)12
-rw-r--r--src/api/routes/-/monitorz.ts (renamed from api/src/routes/-/monitorz.ts)0
-rw-r--r--src/api/routes/-/readyz.ts (renamed from api/src/routes/-/readyz.ts)12
-rw-r--r--src/api/routes/applications/#id/entitlements.ts (renamed from api/src/routes/applications/#id/entitlements.ts)0
-rw-r--r--src/api/routes/applications/detectable.ts (renamed from api/src/routes/applications/detectable.ts)0
-rw-r--r--src/api/routes/applications/index.ts (renamed from api/src/routes/applications/index.ts)0
-rw-r--r--src/api/routes/auth/location-metadata.ts (renamed from api/src/routes/auth/location-metadata.ts)0
-rw-r--r--src/api/routes/auth/login.ts (renamed from api/src/routes/auth/login.ts)0
-rw-r--r--src/api/routes/auth/mfa/totp.ts (renamed from api/src/routes/auth/mfa/totp.ts)9
-rw-r--r--src/api/routes/auth/register.ts (renamed from api/src/routes/auth/register.ts)2
-rw-r--r--src/api/routes/auth/verify/view-backup-codes-challenge.ts (renamed from api/src/routes/auth/verify/view-backup-codes-challenge.ts)4
-rw-r--r--src/api/routes/channels/#channel_id/followers.ts (renamed from api/src/routes/channels/#channel_id/followers.ts)0
-rw-r--r--src/api/routes/channels/#channel_id/index.ts (renamed from api/src/routes/channels/#channel_id/index.ts)4
-rw-r--r--src/api/routes/channels/#channel_id/invites.ts (renamed from api/src/routes/channels/#channel_id/invites.ts)60
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/ack.ts (renamed from api/src/routes/channels/#channel_id/messages/#message_id/ack.ts)4
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts (renamed from api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts)0
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/index.ts (renamed from api/src/routes/channels/#channel_id/messages/#message_id/index.ts)30
-rw-r--r--src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts (renamed from api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts)18
-rw-r--r--src/api/routes/channels/#channel_id/messages/bulk-delete.ts (renamed from api/src/routes/channels/#channel_id/messages/bulk-delete.ts)4
-rw-r--r--src/api/routes/channels/#channel_id/messages/index.ts (renamed from api/src/routes/channels/#channel_id/messages/index.ts)4
-rw-r--r--src/api/routes/channels/#channel_id/permissions.ts (renamed from api/src/routes/channels/#channel_id/permissions.ts)10
-rw-r--r--src/api/routes/channels/#channel_id/pins.ts (renamed from api/src/routes/channels/#channel_id/pins.ts)10
-rw-r--r--src/api/routes/channels/#channel_id/purge.ts (renamed from api/src/routes/channels/#channel_id/purge.ts)32
-rw-r--r--src/api/routes/channels/#channel_id/recipients.ts (renamed from api/src/routes/channels/#channel_id/recipients.ts)2
-rw-r--r--src/api/routes/channels/#channel_id/typing.ts (renamed from api/src/routes/channels/#channel_id/typing.ts)2
-rw-r--r--src/api/routes/channels/#channel_id/webhooks.ts (renamed from api/src/routes/channels/#channel_id/webhooks.ts)4
-rw-r--r--src/api/routes/discoverable-guilds.ts (renamed from api/src/routes/discoverable-guilds.ts)13
-rw-r--r--src/api/routes/discovery.ts (renamed from api/src/routes/discovery.ts)2
-rw-r--r--src/api/routes/downloads.ts (renamed from api/src/routes/downloads.ts)4
-rw-r--r--src/api/routes/experiments.ts (renamed from api/src/routes/experiments.ts)0
-rw-r--r--src/api/routes/gateway/bot.ts (renamed from api/src/routes/gateway/bot.ts)0
-rw-r--r--src/api/routes/gateway/index.ts (renamed from api/src/routes/gateway/index.ts)0
-rw-r--r--src/api/routes/gifs/search.ts (renamed from api/src/routes/gifs/search.ts)2
-rw-r--r--src/api/routes/gifs/trending-gifs.ts (renamed from api/src/routes/gifs/trending-gifs.ts)2
-rw-r--r--src/api/routes/gifs/trending.ts (renamed from api/src/routes/gifs/trending.ts)4
-rw-r--r--src/api/routes/guild-recommendations.ts (renamed from api/src/routes/guild-recommendations.ts)5
-rw-r--r--src/api/routes/guilds/#guild_id/audit-logs.ts (renamed from api/src/routes/guilds/#guild_id/audit-logs.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/bans.ts (renamed from api/src/routes/guilds/#guild_id/bans.ts)38
-rw-r--r--src/api/routes/guilds/#guild_id/channels.ts (renamed from api/src/routes/guilds/#guild_id/channels.ts)6
-rw-r--r--src/api/routes/guilds/#guild_id/delete.ts (renamed from api/src/routes/guilds/#guild_id/delete.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/discovery-requirements.ts (renamed from api/src/routes/guilds/#guild_id/discovery-requirements.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/emojis.ts (renamed from api/src/routes/guilds/#guild_id/emojis.ts)15
-rw-r--r--src/api/routes/guilds/#guild_id/index.ts (renamed from api/src/routes/guilds/#guild_id/index.ts)16
-rw-r--r--src/api/routes/guilds/#guild_id/integrations.ts (renamed from api/src/routes/guilds/#guild_id/integrations.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/invites.ts (renamed from api/src/routes/guilds/#guild_id/invites.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/member-verification.ts (renamed from api/src/routes/guilds/#guild_id/member-verification.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/members/#member_id/index.ts (renamed from api/src/routes/guilds/#guild_id/members/#member_id/index.ts)6
-rw-r--r--src/api/routes/guilds/#guild_id/members/#member_id/nick.ts (renamed from api/src/routes/guilds/#guild_id/members/#member_id/nick.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts (renamed from api/src/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/members/index.ts (renamed from api/src/routes/guilds/#guild_id/members/index.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/messages/search.ts (renamed from api/src/routes/guilds/#guild_id/messages/search.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/premium.ts (renamed from api/src/routes/guilds/#guild_id/premium.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/prune.ts (renamed from api/src/routes/guilds/#guild_id/prune.ts)2
-rw-r--r--src/api/routes/guilds/#guild_id/regions.ts (renamed from api/src/routes/guilds/#guild_id/regions.ts)2
-rw-r--r--src/api/routes/guilds/#guild_id/roles/#role_id/index.ts (renamed from api/src/routes/guilds/#guild_id/roles/#role_id/index.ts)4
-rw-r--r--src/api/routes/guilds/#guild_id/roles/index.ts (renamed from api/src/routes/guilds/#guild_id/roles/index.ts)10
-rw-r--r--src/api/routes/guilds/#guild_id/stickers.ts (renamed from api/src/routes/guilds/#guild_id/stickers.ts)10
-rw-r--r--src/api/routes/guilds/#guild_id/templates.ts (renamed from api/src/routes/guilds/#guild_id/templates.ts)10
-rw-r--r--src/api/routes/guilds/#guild_id/vanity-url.ts (renamed from api/src/routes/guilds/#guild_id/vanity-url.ts)10
-rw-r--r--src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts (renamed from api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts)10
-rw-r--r--src/api/routes/guilds/#guild_id/webhooks.ts (renamed from api/src/routes/guilds/#guild_id/webhooks.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/welcome-screen.ts (renamed from api/src/routes/guilds/#guild_id/welcome-screen.ts)4
-rw-r--r--src/api/routes/guilds/#guild_id/widget.json.ts (renamed from api/src/routes/guilds/#guild_id/widget.json.ts)14
-rw-r--r--src/api/routes/guilds/#guild_id/widget.png.ts (renamed from api/src/routes/guilds/#guild_id/widget.png.ts)2
-rw-r--r--src/api/routes/guilds/#guild_id/widget.ts (renamed from api/src/routes/guilds/#guild_id/widget.ts)2
-rw-r--r--src/api/routes/guilds/index.ts (renamed from api/src/routes/guilds/index.ts)4
-rw-r--r--src/api/routes/guilds/templates/index.ts (renamed from api/src/routes/guilds/templates/index.ts)19
-rw-r--r--src/api/routes/invites/index.ts (renamed from api/src/routes/invites/index.ts)18
-rw-r--r--src/api/routes/oauth2/tokens.ts (renamed from api/src/routes/oauth2/tokens.ts)0
-rw-r--r--src/api/routes/outbound-promotions.ts (renamed from api/src/routes/outbound-promotions.ts)0
-rw-r--r--src/api/routes/partners/#guild_id/requirements.ts (renamed from api/src/routes/partners/#guild_id/requirements.ts)0
-rw-r--r--src/api/routes/ping.ts (renamed from api/src/routes/ping.ts)0
-rw-r--r--src/api/routes/policies/instance/domains.ts (renamed from api/src/routes/policies/instance/domains.ts)0
-rw-r--r--src/api/routes/policies/instance/index.ts (renamed from api/src/routes/policies/instance/index.ts)0
-rw-r--r--src/api/routes/policies/instance/limits.ts (renamed from api/src/routes/policies/instance/limits.ts)0
-rw-r--r--src/api/routes/scheduled-maintenances/upcoming_json.ts (renamed from api/src/routes/scheduled-maintenances/upcoming_json.ts)0
-rw-r--r--src/api/routes/science.ts (renamed from api/src/routes/science.ts)0
-rw-r--r--src/api/routes/stage-instances.ts (renamed from api/src/routes/stage-instances.ts)0
-rw-r--r--src/api/routes/sticker-packs/index.ts (renamed from api/src/routes/sticker-packs/index.ts)0
-rw-r--r--src/api/routes/stickers/#sticker_id/index.ts (renamed from api/src/routes/stickers/#sticker_id/index.ts)2
-rw-r--r--src/api/routes/stop.ts (renamed from api/src/routes/stop.ts)0
-rw-r--r--src/api/routes/store/published-listings/applications.ts (renamed from api/src/routes/store/published-listings/applications.ts)0
-rw-r--r--src/api/routes/store/published-listings/applications/#id/subscription-plans.ts (renamed from api/src/routes/store/published-listings/applications/#id/subscription-plans.ts)0
-rw-r--r--src/api/routes/store/published-listings/skus.ts (renamed from api/src/routes/store/published-listings/skus.ts)0
-rw-r--r--src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts (renamed from api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts)0
-rw-r--r--src/api/routes/teams.ts (renamed from api/src/routes/teams.ts)0
-rw-r--r--src/api/routes/template.ts.disabled (renamed from api/src/routes/template.ts.disabled)0
-rw-r--r--src/api/routes/track.ts (renamed from api/src/routes/track.ts)0
-rw-r--r--src/api/routes/updates.ts (renamed from api/src/routes/updates.ts)12
-rw-r--r--src/api/routes/users/#id/index.ts (renamed from api/src/routes/users/#id/index.ts)0
-rw-r--r--src/api/routes/users/#id/profile.ts (renamed from api/src/routes/users/#id/profile.ts)6
-rw-r--r--src/api/routes/users/#id/relationships.ts (renamed from api/src/routes/users/#id/relationships.ts)0
-rw-r--r--src/api/routes/users/@me/activities/statistics/applications.ts (renamed from api/src/routes/users/@me/activities/statistics/applications.ts)0
-rw-r--r--src/api/routes/users/@me/affinities/guilds.ts (renamed from api/src/routes/users/@me/affinities/guilds.ts)0
-rw-r--r--src/api/routes/users/@me/affinities/users.ts (renamed from api/src/routes/users/@me/affinities/users.ts)0
-rw-r--r--src/api/routes/users/@me/applications/#app_id/entitlements.ts (renamed from api/src/routes/users/@me/applications/#app_id/entitlements.ts)0
-rw-r--r--src/api/routes/users/@me/billing/country-code.ts (renamed from api/src/routes/users/@me/billing/country-code.ts)0
-rw-r--r--src/api/routes/users/@me/billing/payment-sources.ts (renamed from api/src/routes/users/@me/billing/payment-sources.ts)0
-rw-r--r--src/api/routes/users/@me/billing/subscriptions.ts (renamed from api/src/routes/users/@me/billing/subscriptions.ts)0
-rw-r--r--src/api/routes/users/@me/channels.ts (renamed from api/src/routes/users/@me/channels.ts)0
-rw-r--r--src/api/routes/users/@me/connections.ts (renamed from api/src/routes/users/@me/connections.ts)0
-rw-r--r--src/api/routes/users/@me/delete.ts (renamed from api/src/routes/users/@me/delete.ts)0
-rw-r--r--src/api/routes/users/@me/devices.ts (renamed from api/src/routes/users/@me/devices.ts)0
-rw-r--r--src/api/routes/users/@me/disable.ts (renamed from api/src/routes/users/@me/disable.ts)0
-rw-r--r--src/api/routes/users/@me/email-settings.ts (renamed from api/src/routes/users/@me/email-settings.ts)0
-rw-r--r--src/api/routes/users/@me/entitlements.ts (renamed from api/src/routes/users/@me/entitlements.ts)0
-rw-r--r--src/api/routes/users/@me/guilds.ts (renamed from api/src/routes/users/@me/guilds.ts)0
-rw-r--r--src/api/routes/users/@me/guilds/#guild_id/settings.ts (renamed from api/src/routes/users/@me/guilds/#guild_id/settings.ts)0
-rw-r--r--src/api/routes/users/@me/guilds/premium/subscription-slots.ts (renamed from api/src/routes/users/@me/guilds/premium/subscription-slots.ts)0
-rw-r--r--src/api/routes/users/@me/index.ts (renamed from api/src/routes/users/@me/index.ts)0
-rw-r--r--src/api/routes/users/@me/library.ts (renamed from api/src/routes/users/@me/library.ts)0
-rw-r--r--src/api/routes/users/@me/mfa/codes-verification.ts (renamed from api/src/routes/users/@me/mfa/codes-verification.ts)14
-rw-r--r--src/api/routes/users/@me/mfa/codes.ts (renamed from api/src/routes/users/@me/mfa/codes.ts)14
-rw-r--r--src/api/routes/users/@me/mfa/totp/disable.ts (renamed from api/src/routes/users/@me/mfa/totp/disable.ts)4
-rw-r--r--src/api/routes/users/@me/mfa/totp/enable.ts (renamed from api/src/routes/users/@me/mfa/totp/enable.ts)0
-rw-r--r--src/api/routes/users/@me/notes.ts (renamed from api/src/routes/users/@me/notes.ts)2
-rw-r--r--src/api/routes/users/@me/relationships.ts (renamed from api/src/routes/users/@me/relationships.ts)20
-rw-r--r--src/api/routes/users/@me/settings.ts (renamed from api/src/routes/users/@me/settings.ts)10
-rw-r--r--src/api/routes/voice/regions.ts (renamed from api/src/routes/voice/regions.ts)0
-rw-r--r--src/api/start.ts (renamed from api/src/start.ts)0
-rw-r--r--src/api/util/entities/blockedEmailDomains.txt (renamed from api/src/util/entities/blockedEmailDomains.txt)0
-rw-r--r--src/api/util/entities/trustedEmailDomains.txt (renamed from api/src/util/entities/trustedEmailDomains.txt)0
-rw-r--r--src/api/util/handlers/Instance.ts (renamed from api/src/util/handlers/Instance.ts)2
-rw-r--r--src/api/util/handlers/Message.ts (renamed from api/src/util/handlers/Message.ts)24
-rw-r--r--src/api/util/handlers/Voice.ts (renamed from api/src/util/handlers/Voice.ts)0
-rw-r--r--src/api/util/handlers/route.ts (renamed from api/src/util/handlers/route.ts)52
-rw-r--r--src/api/util/index.ts (renamed from api/src/util/index.ts)0
-rw-r--r--src/api/util/utility/Base64.ts (renamed from api/src/util/utility/Base64.ts)0
-rw-r--r--src/api/util/utility/RandomInviteID.ts (renamed from api/src/util/utility/RandomInviteID.ts)0
-rw-r--r--src/api/util/utility/String.ts (renamed from api/src/util/utility/String.ts)0
-rw-r--r--src/api/util/utility/captcha.ts (renamed from api/src/util/utility/captcha.ts)0
-rw-r--r--src/api/util/utility/ipAddress.ts (renamed from api/src/util/utility/ipAddress.ts)2
-rw-r--r--src/api/util/utility/passwordStrength.ts (renamed from api/src/util/utility/passwordStrength.ts)0
143 files changed, 293 insertions, 340 deletions
diff --git a/api/src/global.d.ts b/api/src/global.d.ts
deleted file mode 100644

index 7751af8f..00000000 --- a/api/src/global.d.ts +++ /dev/null
@@ -1,8 +0,0 @@ -declare global { - namespace Express { - interface Request { - user_id: any; - token: any; - } - } -} diff --git a/api/src/Server.ts b/src/api/Server.ts
index 4cf0917d..4cf0917d 100644 --- a/api/src/Server.ts +++ b/src/api/Server.ts
diff --git a/api/src/index.ts b/src/api/index.ts
index 09663452..09663452 100644 --- a/api/src/index.ts +++ b/src/api/index.ts
diff --git a/api/src/middlewares/Authentication.ts b/src/api/middlewares/Authentication.ts
index 1df7911b..1df7911b 100644 --- a/api/src/middlewares/Authentication.ts +++ b/src/api/middlewares/Authentication.ts
diff --git a/api/src/middlewares/BodyParser.ts b/src/api/middlewares/BodyParser.ts
index 4cb376bc..4cb376bc 100644 --- a/api/src/middlewares/BodyParser.ts +++ b/src/api/middlewares/BodyParser.ts
diff --git a/api/src/middlewares/CORS.ts b/src/api/middlewares/CORS.ts
index 20260cf9..20260cf9 100644 --- a/api/src/middlewares/CORS.ts +++ b/src/api/middlewares/CORS.ts
diff --git a/api/src/middlewares/ErrorHandler.ts b/src/api/middlewares/ErrorHandler.ts
index 2012b91c..2012b91c 100644 --- a/api/src/middlewares/ErrorHandler.ts +++ b/src/api/middlewares/ErrorHandler.ts
diff --git a/api/src/middlewares/RateLimit.ts b/src/api/middlewares/RateLimit.ts
index 57645c0b..57645c0b 100644 --- a/api/src/middlewares/RateLimit.ts +++ b/src/api/middlewares/RateLimit.ts
diff --git a/api/src/middlewares/Translation.ts b/src/api/middlewares/Translation.ts
index baabf221..741d6baf 100644 --- a/api/src/middlewares/Translation.ts +++ b/src/api/middlewares/Translation.ts
@@ -6,8 +6,8 @@ import i18nextBackend from "i18next-node-fs-backend"; import { Router } from "express"; export async function initTranslation(router: Router) { - const languages = fs.readdirSync(path.join(__dirname, "..", "..", "locales")); - const namespaces = fs.readdirSync(path.join(__dirname, "..", "..", "locales", "en")); + const languages = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "locales")); + const namespaces = fs.readdirSync(path.join(__dirname, "..", "..", "..", "assets", "locales", "en")); const ns = namespaces.filter((x) => x.endsWith(".json")).map((x) => x.slice(0, x.length - 5)); await i18next diff --git a/api/src/middlewares/index.ts b/src/api/middlewares/index.ts
index f0c50dbe..f0c50dbe 100644 --- a/api/src/middlewares/index.ts +++ b/src/api/middlewares/index.ts
diff --git a/api/src/routes/-/healthz.ts b/src/api/routes/-/healthz.ts
index f7bcfebf..d9d1c026 100644 --- a/api/src/routes/-/healthz.ts +++ b/src/api/routes/-/healthz.ts
@@ -1,17 +1,13 @@ import { Router, Response, Request } from "express"; import { route } from "@fosscord/api"; -import { getConnection } from "typeorm"; +import { getDatabase } from "@fosscord/util"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - try { - // test that the database is alive & responding - getConnection(); - return res.sendStatus(200); - } catch (e) { - res.sendStatus(503); - } + if (!getDatabase()) return res.sendStatus(503); + + return res.sendStatus(200); }); export default router; diff --git a/api/src/routes/-/monitorz.ts b/src/api/routes/-/monitorz.ts
index f85cd099..f85cd099 100644 --- a/api/src/routes/-/monitorz.ts +++ b/src/api/routes/-/monitorz.ts
diff --git a/api/src/routes/-/readyz.ts b/src/api/routes/-/readyz.ts
index f7bcfebf..d9d1c026 100644 --- a/api/src/routes/-/readyz.ts +++ b/src/api/routes/-/readyz.ts
@@ -1,17 +1,13 @@ import { Router, Response, Request } from "express"; import { route } from "@fosscord/api"; -import { getConnection } from "typeorm"; +import { getDatabase } from "@fosscord/util"; const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { - try { - // test that the database is alive & responding - getConnection(); - return res.sendStatus(200); - } catch (e) { - res.sendStatus(503); - } + if (!getDatabase()) return res.sendStatus(503); + + return res.sendStatus(200); }); export default router; diff --git a/api/src/routes/applications/#id/entitlements.ts b/src/api/routes/applications/#id/entitlements.ts
index cfcfe40f..cfcfe40f 100644 --- a/api/src/routes/applications/#id/entitlements.ts +++ b/src/api/routes/applications/#id/entitlements.ts
diff --git a/api/src/routes/applications/detectable.ts b/src/api/routes/applications/detectable.ts
index 28ce42da..28ce42da 100644 --- a/api/src/routes/applications/detectable.ts +++ b/src/api/routes/applications/detectable.ts
diff --git a/api/src/routes/applications/index.ts b/src/api/routes/applications/index.ts
index 28ce42da..28ce42da 100644 --- a/api/src/routes/applications/index.ts +++ b/src/api/routes/applications/index.ts
diff --git a/api/src/routes/auth/location-metadata.ts b/src/api/routes/auth/location-metadata.ts
index f4c2bd16..f4c2bd16 100644 --- a/api/src/routes/auth/location-metadata.ts +++ b/src/api/routes/auth/location-metadata.ts
diff --git a/api/src/routes/auth/login.ts b/src/api/routes/auth/login.ts
index bcaccb30..bcaccb30 100644 --- a/api/src/routes/auth/login.ts +++ b/src/api/routes/auth/login.ts
diff --git a/api/src/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts
index cec6e5ee..50b9e9c8 100644 --- a/api/src/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts
@@ -26,7 +26,14 @@ router.post("/", route({ body: "TotpSchema" }), async (req: Request, res: Respon ], }); - const backup = await BackupCode.findOne({ code: code, expired: false, consumed: false, user: { id: user.id }}); + const backup = await BackupCode.findOne({ + where: { + code: code, + expired: false, + consumed: false, + user: { id: user.id } + } + }); if (!backup) { const ret = verifyToken(user.totp_secret!, code); diff --git a/api/src/routes/auth/register.ts b/src/api/routes/auth/register.ts
index f74d0d63..b7122dad 100644 --- a/api/src/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts
@@ -117,7 +117,7 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re } // check if there is already an account with this email - const exists = await User.findOne({ email: email }); + const exists = await User.findOne({ where: { email: email } }); if (exists) { throw FieldErrors({ diff --git a/api/src/routes/auth/verify/view-backup-codes-challenge.ts b/src/api/routes/auth/verify/view-backup-codes-challenge.ts
index be651686..36bfeb0c 100644 --- a/api/src/routes/auth/verify/view-backup-codes-challenge.ts +++ b/src/api/routes/auth/verify/view-backup-codes-challenge.ts
@@ -11,7 +11,7 @@ export interface BackupCodesChallengeSchema { router.post("/", route({ body: "BackupCodesChallengeSchema" }), async (req: Request, res: Response) => { const { password } = req.body as BackupCodesChallengeSchema; - const user = await User.findOneOrFail({ id: req.user_id }, { select: ["data"] }); + const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] }); if (!await bcrypt.compare(password, user.data.hash || "")) { throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } }); @@ -20,7 +20,7 @@ router.post("/", route({ body: "BackupCodesChallengeSchema" }), async (req: Requ return res.json({ nonce: "NoncePlaceholder", regenerate_nonce: "RegenNoncePlaceholder", - }) + }); }); export default router; diff --git a/api/src/routes/channels/#channel_id/followers.ts b/src/api/routes/channels/#channel_id/followers.ts
index 641af4f8..641af4f8 100644 --- a/api/src/routes/channels/#channel_id/followers.ts +++ b/src/api/routes/channels/#channel_id/followers.ts
diff --git a/api/src/routes/channels/#channel_id/index.ts b/src/api/routes/channels/#channel_id/index.ts
index 932a933a..0340a616 100644 --- a/api/src/routes/channels/#channel_id/index.ts +++ b/src/api/routes/channels/#channel_id/index.ts
@@ -18,7 +18,7 @@ const router: Router = Router(); router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => { const { channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); return res.send(channel); }); @@ -81,7 +81,7 @@ router.patch("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANN const { channel_id } = req.params; if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon); - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); channel.assign(payload); await Promise.all([ diff --git a/api/src/routes/channels/#channel_id/invites.ts b/src/api/routes/channels/#channel_id/invites.ts
index 9c361164..fd8339ad 100644 --- a/api/src/routes/channels/#channel_id/invites.ts +++ b/src/api/routes/channels/#channel_id/invites.ts
@@ -20,44 +20,44 @@ export interface InviteCreateSchema { } router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE", right: "CREATE_INVITES" }), - async (req: Request, res: Response) => { - const { user_id } = req; - const { channel_id } = req.params; - const channel = await Channel.findOneOrFail({ where: { id: channel_id }, select: ["id", "name", "type", "guild_id"] }); - isTextChannel(channel.type); + async (req: Request, res: Response) => { + const { user_id } = req; + const { channel_id } = req.params; + const channel = await Channel.findOneOrFail({ where: { id: channel_id }, select: ["id", "name", "type", "guild_id"] }); + isTextChannel(channel.type); - if (!channel.guild_id) { - throw new HTTPError("This channel doesn't exist", 404); - } - const { guild_id } = channel; + if (!channel.guild_id) { + throw new HTTPError("This channel doesn't exist", 404); + } + const { guild_id } = channel; - const expires_at = new Date(req.body.max_age * 1000 + Date.now()); + const expires_at = new Date(req.body.max_age * 1000 + Date.now()); - const invite = await new Invite({ - code: random(), - temporary: req.body.temporary, - uses: 0, - max_uses: req.body.max_uses, - max_age: req.body.max_age, - expires_at, - created_at: new Date(), - guild_id, - channel_id: channel_id, - inviter_id: user_id - }).save(); - const data = invite.toJSON(); - data.inviter = await User.getPublicUser(req.user_id); - data.guild = await Guild.findOne({ id: guild_id }); - data.channel = channel; + const invite = await Invite.create({ + code: random(), + temporary: req.body.temporary, + uses: 0, + max_uses: req.body.max_uses, + max_age: req.body.max_age, + expires_at, + created_at: new Date(), + guild_id, + channel_id: channel_id, + inviter_id: user_id + }).save(); + const data = invite.toJSON(); + data.inviter = await User.getPublicUser(req.user_id); + data.guild = await Guild.findOne({ where: { id: guild_id } }); + data.channel = channel; - await emitEvent({ event: "INVITE_CREATE", data, guild_id } as InviteCreateEvent); - res.status(201).send(data); -}); + await emitEvent({ event: "INVITE_CREATE", data, guild_id } as InviteCreateEvent); + res.status(201).send(data); + }); router.get("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => { const { user_id } = req; const { channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (!channel.guild_id) { throw new HTTPError("This channel doesn't exist", 404); diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts b/src/api/routes/channels/#channel_id/messages/#message_id/ack.ts
index 1e3564d8..3abae7ce 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts +++ b/src/api/routes/channels/#channel_id/messages/#message_id/ack.ts
@@ -19,8 +19,8 @@ router.post("/", route({ body: "MessageAcknowledgeSchema" }), async (req: Reques const permission = await getPermission(req.user_id, undefined, channel_id); permission.hasThrow("VIEW_CHANNEL"); - let read_state = await ReadState.findOne({ user_id: req.user_id, channel_id }); - if (!read_state) read_state = new ReadState({ user_id: req.user_id, channel_id }); + let read_state = await ReadState.findOne({ where: { user_id: req.user_id, channel_id } }); + if (!read_state) read_state = ReadState.create({ user_id: req.user_id, channel_id }); read_state.last_message_id = message_id; await read_state.save(); diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts b/src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts
index b2cb6763..b2cb6763 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/crosspost.ts +++ b/src/api/routes/channels/#channel_id/messages/#message_id/crosspost.ts
diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
index 37734397..a02a9abe 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts +++ b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
@@ -7,12 +7,12 @@ import { FosscordApiErrors, getPermission, getRights, - Message, + Message, MessageCreateEvent, MessageDeleteEvent, MessageUpdateEvent, Snowflake, - uploadFile + uploadFile } from "@fosscord/util"; import { Router, Response, Request } from "express"; import multer from "multer"; @@ -40,14 +40,14 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, relations: ["attachments"] }); const permissions = await getPermission(req.user_id, undefined, channel_id); - + const rights = await getRights(req.user_id); if ((req.user_id !== message.author_id)) { if (!rights.has("MANAGE_MESSAGES")) { permissions.hasThrow("MANAGE_MESSAGES"); body = { flags: body.flags }; -// guild admins can only suppress embeds of other messages, no such restriction imposed to instance-wide admins + // guild admins can only suppress embeds of other messages, no such restriction imposed to instance-wide admins } } else rights.hasThrow("SELF_EDIT_MESSAGES"); @@ -94,7 +94,7 @@ router.put( const { channel_id, message_id } = req.params; var body = req.body as MessageCreateSchema; const attachments: Attachment[] = []; - + const rights = await getRights(req.user_id); rights.hasThrow("SEND_MESSAGES"); @@ -103,13 +103,13 @@ router.put( throw new HTTPError("Message IDs must be positive integers", 400); } - const snowflake = Snowflake.deconstruct(message_id) + const snowflake = Snowflake.deconstruct(message_id); if (Date.now() < snowflake.timestamp) { // message is in the future throw FosscordApiErrors.CANNOT_BACKFILL_TO_THE_FUTURE; } - const exists = await Message.findOne({ where: { id: message_id, channel_id: channel_id }}); + const exists = await Message.findOne({ where: { id: message_id, channel_id: channel_id } }); if (exists) { throw FosscordApiErrors.CANNOT_REPLACE_BY_BACKFILL; } @@ -117,7 +117,7 @@ router.put( if (req.file) { try { const file = await uploadFile(`/attachments/${req.params.channel_id}`, req.file); - attachments.push({ ...file, proxy_url: file.url }); + attachments.push(Attachment.create({ ...file, proxy_url: file.url })); } catch (error) { return res.status(400).json(error); } @@ -135,13 +135,13 @@ router.put( embeds, channel_id, attachments, - edited_timestamp: null, + edited_timestamp: undefined, timestamp: new Date(snowflake.timestamp), }); //Fix for the client bug - delete message.member - + delete message.member; + await Promise.all([ message.save(), emitEvent({ event: "MESSAGE_CREATE", channel_id: channel_id, data: message } as MessageCreateEvent), @@ -160,7 +160,7 @@ router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, relations: ["attachments"] }); const permissions = await getPermission(req.user_id, undefined, channel_id); - + if (message.author_id !== req.user_id) permissions.hasThrow("READ_MESSAGE_HISTORY"); return res.json(message); @@ -169,9 +169,9 @@ router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: router.delete("/", route({}), async (req: Request, res: Response) => { const { message_id, channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); - const message = await Message.findOneOrFail({ id: message_id }); - + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); + const message = await Message.findOneOrFail({ where: { id: message_id } }); + const rights = await getRights(req.user_id); if ((message.author_id !== req.user_id)) { diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
index d93cf70f..c3cca05d 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/reactions.ts +++ b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
@@ -39,7 +39,7 @@ function getEmoji(emoji: string): PartialEmoji { router.delete("/", route({ permission: "MANAGE_MESSAGES" }), async (req: Request, res: Response) => { const { message_id, channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); await Message.update({ id: message_id, channel_id }, { reactions: [] }); @@ -60,7 +60,7 @@ router.delete("/:emoji", route({ permission: "MANAGE_MESSAGES" }), async (req: R const { message_id, channel_id } = req.params; const emoji = getEmoji(req.params.emoji); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name); if (!already_added) throw new HTTPError("Reaction not found", 404); @@ -87,7 +87,7 @@ router.get("/:emoji", route({ permission: "VIEW_CHANNEL" }), async (req: Request const { message_id, channel_id } = req.params; const emoji = getEmoji(req.params.emoji); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); const reaction = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name); if (!reaction) throw new HTTPError("Reaction not found", 404); @@ -106,14 +106,14 @@ router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY", right if (user_id !== "@me") throw new HTTPError("Invalid user"); const emoji = getEmoji(req.params.emoji); - const channel = await Channel.findOneOrFail({ id: channel_id }); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name); if (!already_added) req.permission!.hasThrow("ADD_REACTIONS"); if (emoji.id) { - const external_emoji = await Emoji.findOneOrFail({ id: emoji.id }); + const external_emoji = await Emoji.findOneOrFail({ where: { id: emoji.id } }); if (!already_added) req.permission!.hasThrow("USE_EXTERNAL_EMOJIS"); emoji.animated = external_emoji.animated; emoji.name = external_emoji.name; @@ -126,7 +126,7 @@ router.put("/:emoji/:user_id", route({ permission: "READ_MESSAGE_HISTORY", right await message.save(); - const member = channel.guild_id && (await Member.findOneOrFail({ id: req.user_id })); + const member = channel.guild_id && (await Member.findOneOrFail({ where: { id: req.user_id } })); await emitEvent({ event: "MESSAGE_REACTION_ADD", @@ -149,8 +149,8 @@ router.delete("/:emoji/:user_id", route({}), async (req: Request, res: Response) const emoji = getEmoji(req.params.emoji); - const channel = await Channel.findOneOrFail({ id: channel_id }); - const message = await Message.findOneOrFail({ id: message_id, channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); + const message = await Message.findOneOrFail({ where: { id: message_id, channel_id } }); if (user_id === "@me") user_id = req.user_id; else { diff --git a/api/src/routes/channels/#channel_id/messages/bulk-delete.ts b/src/api/routes/channels/#channel_id/messages/bulk-delete.ts
index 6eacf249..b6fd37f4 100644 --- a/api/src/routes/channels/#channel_id/messages/bulk-delete.ts +++ b/src/api/routes/channels/#channel_id/messages/bulk-delete.ts
@@ -17,7 +17,7 @@ export interface BulkDeleteSchema { // https://discord.com/developers/docs/resources/channel#bulk-delete-messages router.post("/", route({ body: "BulkDeleteSchema" }), async (req: Request, res: Response) => { const { channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (!channel.guild_id) throw new HTTPError("Can't bulk delete dm channel messages", 400); const rights = await getRights(req.user_id); @@ -35,7 +35,7 @@ router.post("/", route({ body: "BulkDeleteSchema" }), async (req: Request, res: if (messages.length > maxBulkDelete) throw new HTTPError(`You cannot delete more than ${maxBulkDelete} messages`); } - await Message.delete(messages.map((x) => ({ id: x }))); + await Message.delete(messages); await emitEvent({ event: "MESSAGE_DELETE_BULK", diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index 3c014f5c..154dc8ed 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -203,7 +203,7 @@ router.post( for (var currFile of files) { try { const file = await uploadFile(`/attachments/${channel.id}`, currFile); - attachments.push({ ...file, proxy_url: file.url }); + attachments.push(Attachment.create({ ...file, proxy_url: file.url })); } catch (error) { return res.status(400).json(error); @@ -220,7 +220,7 @@ router.post( embeds, channel_id, attachments, - edited_timestamp: null, + edited_timestamp: undefined, timestamp: new Date() }); diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/src/api/routes/channels/#channel_id/permissions.ts
index 2eded853..e74a0255 100644 --- a/api/src/routes/channels/#channel_id/permissions.ts +++ b/src/api/routes/channels/#channel_id/permissions.ts
@@ -16,7 +16,7 @@ const router: Router = Router(); // TODO: Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel) -export interface ChannelPermissionOverwriteSchema extends ChannelPermissionOverwrite {} +export interface ChannelPermissionOverwriteSchema extends ChannelPermissionOverwrite { } router.put( "/:overwrite_id", @@ -25,13 +25,13 @@ router.put( const { channel_id, overwrite_id } = req.params; const body = req.body as ChannelPermissionOverwriteSchema; - var channel = await Channel.findOneOrFail({ id: channel_id }); + var channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (!channel.guild_id) throw new HTTPError("Channel not found", 404); if (body.type === 0) { - if (!(await Role.count({ id: overwrite_id }))) throw new HTTPError("role not found", 404); + if (!(await Role.count({ where: { id: overwrite_id } }))) throw new HTTPError("role not found", 404); } else if (body.type === 1) { - if (!(await Member.count({ id: overwrite_id }))) throw new HTTPError("user not found", 404); + if (!(await Member.count({ where: { id: overwrite_id } }))) throw new HTTPError("user not found", 404); } else throw new HTTPError("type not supported", 501); // @ts-ignore @@ -64,7 +64,7 @@ router.put( router.delete("/:overwrite_id", route({ permission: "MANAGE_ROLES" }), async (req: Request, res: Response) => { const { channel_id, overwrite_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (!channel.guild_id) throw new HTTPError("Channel not found", 404); channel.permission_overwrites = channel.permission_overwrites!.filter((x) => x.id === overwrite_id); diff --git a/api/src/routes/channels/#channel_id/pins.ts b/src/api/routes/channels/#channel_id/pins.ts
index e71e659f..30507c71 100644 --- a/api/src/routes/channels/#channel_id/pins.ts +++ b/src/api/routes/channels/#channel_id/pins.ts
@@ -17,12 +17,12 @@ const router: Router = Router(); router.put("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => { const { channel_id, message_id } = req.params; - const message = await Message.findOneOrFail({ id: message_id }); + const message = await Message.findOneOrFail({ where: { id: message_id } }); // * in dm channels anyone can pin messages -> only check for guilds if (message.guild_id) req.permission!.hasThrow("MANAGE_MESSAGES"); - const pinned_count = await Message.count({ channel: { id: channel_id }, pinned: true }); + const pinned_count = await Message.count({ where: { channel: { id: channel_id }, pinned: true } }); const { maxPins } = Config.get().limits.channel; if (pinned_count >= maxPins) throw DiscordApiErrors.MAXIMUM_PINS.withParams(maxPins); @@ -50,10 +50,10 @@ router.put("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Re router.delete("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => { const { channel_id, message_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); if (channel.guild_id) req.permission!.hasThrow("MANAGE_MESSAGES"); - const message = await Message.findOneOrFail({ id: message_id }); + const message = await Message.findOneOrFail({ where: { id: message_id } }); message.pinned = false; await Promise.all([ @@ -82,7 +82,7 @@ router.delete("/:message_id", route({ permission: "VIEW_CHANNEL" }), async (req: router.get("/", route({ permission: ["READ_MESSAGE_HISTORY"] }), async (req: Request, res: Response) => { const { channel_id } = req.params; - let pins = await Message.find({ channel_id: channel_id, pinned: true }); + let pins = await Message.find({ where: { channel_id: channel_id, pinned: true } }); res.send(pins); }); diff --git a/api/src/routes/channels/#channel_id/purge.ts b/src/api/routes/channels/#channel_id/purge.ts
index 28b52b50..bfac27ee 100644 --- a/api/src/routes/channels/#channel_id/purge.ts +++ b/src/api/routes/channels/#channel_id/purge.ts
@@ -12,10 +12,10 @@ import { FosscordApiErrors, getPermission, getRights, - Message, + Message, MessageDeleteBulkEvent, Snowflake, - uploadFile + uploadFile } from "@fosscord/util"; import { Router, Response, Request } from "express"; import multer from "multer"; @@ -27,7 +27,7 @@ export default router; export interface PurgeSchema { before: string; - after: string + after: string; } /** @@ -35,8 +35,8 @@ TODO: apply the delete bit by bit to prevent client and database stress **/ router.post("/", route({ /*body: "PurgeSchema",*/ }), async (req: Request, res: Response) => { const { channel_id } = req.params; - const channel = await Channel.findOneOrFail({ id: channel_id }); - + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); + if (!channel.guild_id) throw new HTTPError("Can't purge dm channels", 400); isTextChannel(channel.type); @@ -46,7 +46,7 @@ router.post("/", route({ /*body: "PurgeSchema",*/ }), async (req: Request, res: permissions.hasThrow("MANAGE_MESSAGES"); permissions.hasThrow("MANAGE_CHANNELS"); } - + const { before, after } = req.body as PurgeSchema; // TODO: send the deletion event bite-by-bite to prevent client stress @@ -55,25 +55,25 @@ router.post("/", route({ /*body: "PurgeSchema",*/ }), async (req: Request, res: order: { id: "ASC" }, // take: limit, where: { - channel_id, - id: Between(after, before), // the right way around - author_id: rights.has("SELF_DELETE_MESSAGES") ? undefined : Not(req.user_id) - // if you lack the right of self-deletion, you can't delete your own messages, even in purges - }, + channel_id, + id: Between(after, before), // the right way around + author_id: rights.has("SELF_DELETE_MESSAGES") ? undefined : Not(req.user_id) + // if you lack the right of self-deletion, you can't delete your own messages, even in purges + }, relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"] }; - + const messages = await Message.find(query); const endpoint = Config.get().cdn.endpointPublic; - - if (messages.length == 0) { + + if (messages.length == 0) { res.sendStatus(304); return; } - await Message.delete(messages.map((x) => ({ id: x }))); - + await Message.delete(messages.map((x) => x.id)); + await emitEvent({ event: "MESSAGE_DELETE_BULK", channel_id, diff --git a/api/src/routes/channels/#channel_id/recipients.ts b/src/api/routes/channels/#channel_id/recipients.ts
index e6466211..25854415 100644 --- a/api/src/routes/channels/#channel_id/recipients.ts +++ b/src/api/routes/channels/#channel_id/recipients.ts
@@ -28,7 +28,7 @@ router.put("/:user_id", route({}), async (req: Request, res: Response) => { throw DiscordApiErrors.INVALID_RECIPIENT; //TODO is this the right error? } - channel.recipients!.push(new Recipient({ channel_id: channel_id, user_id: user_id })); + channel.recipients!.push(Recipient.create({ channel_id: channel_id, user_id: user_id })); await channel.save(); await emitEvent({ diff --git a/api/src/routes/channels/#channel_id/typing.ts b/src/api/routes/channels/#channel_id/typing.ts
index 56652368..99460f6e 100644 --- a/api/src/routes/channels/#channel_id/typing.ts +++ b/src/api/routes/channels/#channel_id/typing.ts
@@ -8,7 +8,7 @@ router.post("/", route({ permission: "SEND_MESSAGES" }), async (req: Request, re const { channel_id } = req.params; const user_id = req.user_id; const timestamp = Date.now(); - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); const member = await Member.findOne({ where: { id: user_id, guild_id: channel.guild_id }, relations: ["roles", "user"] }); await emitEvent({ diff --git a/api/src/routes/channels/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts
index 92895da6..93f70a41 100644 --- a/api/src/routes/channels/#channel_id/webhooks.ts +++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -22,12 +22,12 @@ router.get("/", route({}), async (req: Request, res: Response) => { // TODO: use Image Data Type for avatar instead of String router.post("/", route({ body: "WebhookCreateSchema", permission: "MANAGE_WEBHOOKS" }), async (req: Request, res: Response) => { const channel_id = req.params.channel_id; - const channel = await Channel.findOneOrFail({ id: channel_id }); + const channel = await Channel.findOneOrFail({ where: { id: channel_id } }); isTextChannel(channel.type); if (!channel.guild_id) throw new HTTPError("Not a guild channel", 400); - const webhook_count = await Webhook.count({ channel_id }); + const webhook_count = await Webhook.count({ where: { channel_id } }); const { maxWebhooks } = Config.get().limits.channel; if (webhook_count > maxWebhooks) throw DiscordApiErrors.MAXIMUM_WEBHOOKS.withParams(maxWebhooks); diff --git a/api/src/routes/discoverable-guilds.ts b/src/api/routes/discoverable-guilds.ts
index 0aa2baa9..383e2b24 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/src/api/routes/discoverable-guilds.ts
@@ -2,6 +2,7 @@ import { Guild, Config } from "@fosscord/util"; import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; +import { Like } from "typeorm"; const router = Router(); @@ -16,14 +17,14 @@ router.get("/", route({}), async (req: Request, res: Response) => { if (categories == undefined) { guilds = showAllGuilds ? await Guild.find({ take: Math.abs(Number(limit || configLimit)) }) - : await Guild.find({ where: `"features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || configLimit)) }); + : await Guild.find({ where: { features: Like(`%DISCOVERABLE%`) }, take: Math.abs(Number(limit || configLimit)) }); } else { guilds = showAllGuilds - ? await Guild.find({ where: `"primary_category_id" = ${categories}`, take: Math.abs(Number(limit || configLimit)) }) - : await Guild.find({ - where: `"primary_category_id" = ${categories} AND "features" LIKE '%DISCOVERABLE%'`, - take: Math.abs(Number(limit || configLimit)) - }); + ? await Guild.find({ where: { primary_category_id: categories.toString() }, take: Math.abs(Number(limit || configLimit)) }) + : await Guild.find({ + where: { primary_category_id: categories.toString(), features: Like("%DISCOVERABLE%") }, + take: Math.abs(Number(limit || configLimit)) + }); } const total = guilds ? guilds.length : undefined; diff --git a/api/src/routes/discovery.ts b/src/api/routes/discovery.ts
index 1991400e..6ab2cc13 100644 --- a/api/src/routes/discovery.ts +++ b/src/api/routes/discovery.ts
@@ -10,7 +10,7 @@ router.get("/categories", route({}), async (req: Request, res: Response) => { const { locale, primary_only } = req.query; - const out = primary_only ? await Categories.find() : await Categories.find({ where: `"is_primary" = "true"` }); + const out = primary_only ? await Categories.find() : await Categories.find({ where: { is_primary: true } }); res.send(out); }); diff --git a/api/src/routes/downloads.ts b/src/api/routes/downloads.ts
index ddfc080c..df3df911 100644 --- a/api/src/routes/downloads.ts +++ b/src/api/routes/downloads.ts
@@ -10,9 +10,9 @@ router.get("/:branch", route({}), async (req: Request, res: Response) => { const { platform } = req.query; //TODO - if(!platform || !["linux", "osx", "win"].includes(platform.toString())) return res.status(404) + if (!platform || !["linux", "osx", "win"].includes(platform.toString())) return res.status(404); - const release = await Release.findOneOrFail({ name: client.releases.upstreamVersion }); + const release = await Release.findOneOrFail({ where: { name: client.releases.upstreamVersion } }); res.redirect(release[`win_url`]); }); diff --git a/api/src/routes/experiments.ts b/src/api/routes/experiments.ts
index 7be86fb8..7be86fb8 100644 --- a/api/src/routes/experiments.ts +++ b/src/api/routes/experiments.ts
diff --git a/api/src/routes/gateway/bot.ts b/src/api/routes/gateway/bot.ts
index f1dbb9df..f1dbb9df 100644 --- a/api/src/routes/gateway/bot.ts +++ b/src/api/routes/gateway/bot.ts
diff --git a/api/src/routes/gateway/index.ts b/src/api/routes/gateway/index.ts
index 9bad7478..9bad7478 100644 --- a/api/src/routes/gateway/index.ts +++ b/src/api/routes/gateway/index.ts
diff --git a/api/src/routes/gifs/search.ts b/src/api/routes/gifs/search.ts
index 9ad7a592..c7468641 100644 --- a/api/src/routes/gifs/search.ts +++ b/src/api/routes/gifs/search.ts
@@ -20,7 +20,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { headers: { "Content-Type": "application/json" } }); - const { results } = await response.json(); + const { results } = await response.json() as any; // TODO: types res.json(results.map(parseGifResult)).status(200); }); diff --git a/api/src/routes/gifs/trending-gifs.ts b/src/api/routes/gifs/trending-gifs.ts
index 6d97bf7c..52a8969d 100644 --- a/api/src/routes/gifs/trending-gifs.ts +++ b/src/api/routes/gifs/trending-gifs.ts
@@ -20,7 +20,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { headers: { "Content-Type": "application/json" } }); - const { results } = await response.json(); + const { results } = await response.json() as any; // TODO: types res.json(results.map(parseGifResult)).status(200); }); diff --git a/api/src/routes/gifs/trending.ts b/src/api/routes/gifs/trending.ts
index c81b4c08..aa976c3f 100644 --- a/api/src/routes/gifs/trending.ts +++ b/src/api/routes/gifs/trending.ts
@@ -50,8 +50,8 @@ router.get("/", route({}), async (req: Request, res: Response) => { }) ]); - const { tags } = await responseSource.json(); - const { results } = await trendGifSource.json(); + const { tags } = await responseSource.json() as any; // TODO: types + const { results } = await trendGifSource.json() as any; //TODO: types; res.json({ categories: tags.map((x: any) => ({ name: x.searchterm, src: x.image })), diff --git a/api/src/routes/guild-recommendations.ts b/src/api/routes/guild-recommendations.ts
index 1432f39c..b851d710 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/src/api/routes/guild-recommendations.ts
@@ -2,6 +2,7 @@ import { Guild, Config } from "@fosscord/util"; import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; +import { Like } from "typeorm"; const router = Router(); @@ -16,8 +17,8 @@ router.get("/", route({}), async (req: Request, res: Response) => { const guilds = showAllGuilds ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) - : await Guild.find({ where: `"features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || 24)) }); - res.send({ recommended_guilds: guilds, load_id: `server_recs/${genLoadId(32)}`}).status(200); + : await Guild.find({ where: { features: Like("%DISCOVERABLE%") }, take: Math.abs(Number(limit || 24)) }); + res.send({ recommended_guilds: guilds, load_id: `server_recs/${genLoadId(32)}` }).status(200); }); export default router; diff --git a/api/src/routes/guilds/#guild_id/audit-logs.ts b/src/api/routes/guilds/#guild_id/audit-logs.ts
index a4f2f800..a4f2f800 100644 --- a/api/src/routes/guilds/#guild_id/audit-logs.ts +++ b/src/api/routes/guilds/#guild_id/audit-logs.ts
diff --git a/api/src/routes/guilds/#guild_id/bans.ts b/src/api/routes/guilds/#guild_id/bans.ts
index 1ce41936..51d3ca67 100644 --- a/api/src/routes/guilds/#guild_id/bans.ts +++ b/src/api/routes/guilds/#guild_id/bans.ts
@@ -1,5 +1,5 @@ import { Request, Response, Router } from "express"; -import { DiscordApiErrors, emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member } from "@fosscord/util"; +import { DiscordApiErrors, emitEvent, GuildBanAddEvent, GuildBanRemoveEvent, Ban, User, Member } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import { getIpAdress, route } from "@fosscord/api"; @@ -32,7 +32,7 @@ const router: Router = Router(); router.get("/", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => { const { guild_id } = req.params; - let bans = await Ban.find({ guild_id: guild_id }); + let bans = await Ban.find({ where: { guild_id: guild_id } }); let promisesToAwait: object[] = []; const bansObj: object[] = []; @@ -65,16 +65,16 @@ router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request, const { guild_id } = req.params; const user_id = req.params.ban; - let ban = await Ban.findOneOrFail({ guild_id: guild_id, user_id: user_id }) as BanRegistrySchema; - + let ban = await Ban.findOneOrFail({ where: { guild_id: guild_id, user_id: user_id } }) as BanRegistrySchema; + if (ban.user_id === ban.executor_id) throw DiscordApiErrors.UNKNOWN_BAN; // pretend self-bans don't exist to prevent victim chasing - + /* Filter secret from registry. */ - + ban = ban as BanModeratorSchema; - delete ban.ip + delete ban.ip; return res.json(ban); }); @@ -83,14 +83,14 @@ router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBER const { guild_id } = req.params; const banned_user_id = req.params.user_id; - if ( (req.user_id === banned_user_id) && (banned_user_id === req.permission!.cache.guild?.owner_id)) + if ((req.user_id === banned_user_id) && (banned_user_id === req.permission!.cache.guild?.owner_id)) throw new HTTPError("You are the guild owner, hence can't ban yourself", 403); - + if (req.permission!.cache.guild?.owner_id === banned_user_id) throw new HTTPError("You can't ban the owner", 400); - + const banned_user = await User.getPublicUser(banned_user_id); - const ban = new Ban({ + const ban = Ban.create({ user_id: banned_user_id, guild_id: guild_id, ip: getIpAdress(req), @@ -114,15 +114,15 @@ router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBER return res.json(ban); }); -router.put("/@me", route({ body: "BanCreateSchema"}), async (req: Request, res: Response) => { +router.put("/@me", route({ body: "BanCreateSchema" }), async (req: Request, res: Response) => { const { guild_id } = req.params; const banned_user = await User.getPublicUser(req.params.user_id); - if (req.permission!.cache.guild?.owner_id === req.params.user_id) + if (req.permission!.cache.guild?.owner_id === req.params.user_id) throw new HTTPError("You are the guild owner, hence can't ban yourself", 403); - - const ban = new Ban({ + + const ban = Ban.create({ user_id: req.params.user_id, guild_id: guild_id, ip: getIpAdress(req), @@ -149,13 +149,13 @@ router.put("/@me", route({ body: "BanCreateSchema"}), async (req: Request, res: router.delete("/:user_id", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => { const { guild_id, user_id } = req.params; - let ban = await Ban.findOneOrFail({ guild_id: guild_id, user_id: user_id }); - + let ban = await Ban.findOneOrFail({ where: { guild_id: guild_id, user_id: user_id } }); + if (ban.user_id === ban.executor_id) throw DiscordApiErrors.UNKNOWN_BAN; // make self-bans irreversible and hide them from view to avoid victim chasing - + const banned_user = await User.getPublicUser(user_id); - + await Promise.all([ Ban.delete({ user_id: user_id, diff --git a/api/src/routes/guilds/#guild_id/channels.ts b/src/api/routes/guilds/#guild_id/channels.ts
index a921fa21..11f727fc 100644 --- a/api/src/routes/guilds/#guild_id/channels.ts +++ b/src/api/routes/guilds/#guild_id/channels.ts
@@ -7,7 +7,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const channels = await Channel.find({ guild_id }); + const channels = await Channel.find({ where: { guild_id } }); res.json(channels); }); @@ -22,7 +22,7 @@ router.post("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNE res.status(201).json(channel); }); -export type ChannelReorderSchema = { id: string; position?: number; lock_permissions?: boolean; parent_id?: string }[]; +export type ChannelReorderSchema = { id: string; position?: number; lock_permissions?: boolean; parent_id?: string; }[]; router.patch("/", route({ body: "ChannelReorderSchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => { // changes guild channel position @@ -48,7 +48,7 @@ router.patch("/", route({ body: "ChannelReorderSchema", permission: "MANAGE_CHAN } await Channel.update({ guild_id, id: x.id }, opts); - const channel = await Channel.findOneOrFail({ guild_id, id: x.id }); + const channel = await Channel.findOneOrFail({ where: { guild_id, id: x.id } }); await emitEvent({ event: "CHANNEL_UPDATE", data: channel, channel_id: x.id, guild_id } as ChannelUpdateEvent); }) diff --git a/api/src/routes/guilds/#guild_id/delete.ts b/src/api/routes/guilds/#guild_id/delete.ts
index bd158c56..bd158c56 100644 --- a/api/src/routes/guilds/#guild_id/delete.ts +++ b/src/api/routes/guilds/#guild_id/delete.ts
diff --git a/api/src/routes/guilds/#guild_id/discovery-requirements.ts b/src/api/routes/guilds/#guild_id/discovery-requirements.ts
index ad20633f..ad20633f 100644 --- a/api/src/routes/guilds/#guild_id/discovery-requirements.ts +++ b/src/api/routes/guilds/#guild_id/discovery-requirements.ts
diff --git a/api/src/routes/guilds/#guild_id/emojis.ts b/src/api/routes/guilds/#guild_id/emojis.ts
index 85d7ac05..75998e04 100644 --- a/api/src/routes/guilds/#guild_id/emojis.ts +++ b/src/api/routes/guilds/#guild_id/emojis.ts
@@ -41,19 +41,20 @@ router.post("/", route({ body: "EmojiCreateSchema", permission: "MANAGE_EMOJIS_A const body = req.body as EmojiCreateSchema; const id = Snowflake.generate(); - const emoji_count = await Emoji.count({ guild_id: guild_id }); + const emoji_count = await Emoji.count({ where: { guild_id: guild_id } }); const { maxEmojis } = Config.get().limits.guild; if (emoji_count >= maxEmojis) throw DiscordApiErrors.MAXIMUM_NUMBER_OF_EMOJIS_REACHED.withParams(maxEmojis); if (body.require_colons == null) body.require_colons = true; - const user = await User.findOneOrFail({ id: req.user_id }); + const user = await User.findOneOrFail({ where: { id: req.user_id } }); body.image = (await handleFile(`/emojis/${id}`, body.image)) as string; - const emoji = await new Emoji({ + const emoji = await Emoji.create({ id: id, guild_id: guild_id, ...body, + require_colons: body.require_colons ?? undefined, // schema allows nulls, db does not user: user, managed: false, animated: false, // TODO: Add support animated emojis @@ -66,7 +67,7 @@ router.post("/", route({ body: "EmojiCreateSchema", permission: "MANAGE_EMOJIS_A guild_id: guild_id, data: { guild_id: guild_id, - emojis: await Emoji.find({ guild_id: guild_id }) + emojis: await Emoji.find({ where: { guild_id: guild_id } }) } } as GuildEmojisUpdateEvent); @@ -80,14 +81,14 @@ router.patch( const { emoji_id, guild_id } = req.params; const body = req.body as EmojiModifySchema; - const emoji = await new Emoji({ ...body, id: emoji_id, guild_id: guild_id }).save(); + const emoji = await Emoji.create({ ...body, id: emoji_id, guild_id: guild_id }).save(); await emitEvent({ event: "GUILD_EMOJIS_UPDATE", guild_id: guild_id, data: { guild_id: guild_id, - emojis: await Emoji.find({ guild_id: guild_id }) + emojis: await Emoji.find({ where: { guild_id: guild_id } }) } } as GuildEmojisUpdateEvent); @@ -108,7 +109,7 @@ router.delete("/:emoji_id", route({ permission: "MANAGE_EMOJIS_AND_STICKERS" }), guild_id: guild_id, data: { guild_id: guild_id, - emojis: await Emoji.find({ guild_id: guild_id }) + emojis: await Emoji.find({ where: { guild_id: guild_id } }) } } as GuildEmojisUpdateEvent); diff --git a/api/src/routes/guilds/#guild_id/index.ts b/src/api/routes/guilds/#guild_id/index.ts
index 45e30a74..45bbe348 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/src/api/routes/guilds/#guild_id/index.ts
@@ -27,8 +27,8 @@ router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; const [guild, member] = await Promise.all([ - Guild.findOneOrFail({ id: guild_id }), - Member.findOne({ guild_id: guild_id, id: req.user_id }) + Guild.findOneOrFail({ where: { id: guild_id } }), + Member.findOne({ where: { guild_id: guild_id, id: req.user_id } }) ]); if (!member) throw new HTTPError("You are not a member of the guild you are trying to access", 401); @@ -38,17 +38,17 @@ router.get("/", route({}), async (req: Request, res: Response) => { return res.send(guild); }); -router.patch("/", route({ body: "GuildUpdateSchema"}), async (req: Request, res: Response) => { +router.patch("/", route({ body: "GuildUpdateSchema" }), async (req: Request, res: Response) => { const body = req.body as GuildUpdateSchema; const { guild_id } = req.params; - - + + const rights = await getRights(req.user_id); const permission = await getPermission(req.user_id, guild_id); - - if (!rights.has("MANAGE_GUILDS")||!permission.has("MANAGE_GUILD")) + + if (!rights.has("MANAGE_GUILDS") || !permission.has("MANAGE_GUILD")) throw DiscordApiErrors.MISSING_PERMISSIONS.withParams("MANAGE_GUILD"); - + // TODO: guild update check image if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon); diff --git a/api/src/routes/guilds/#guild_id/integrations.ts b/src/api/routes/guilds/#guild_id/integrations.ts
index abf997c9..abf997c9 100644 --- a/api/src/routes/guilds/#guild_id/integrations.ts +++ b/src/api/routes/guilds/#guild_id/integrations.ts
diff --git a/api/src/routes/guilds/#guild_id/invites.ts b/src/api/routes/guilds/#guild_id/invites.ts
index b7534e31..b7534e31 100644 --- a/api/src/routes/guilds/#guild_id/invites.ts +++ b/src/api/routes/guilds/#guild_id/invites.ts
diff --git a/api/src/routes/guilds/#guild_id/member-verification.ts b/src/api/routes/guilds/#guild_id/member-verification.ts
index 265a1b35..265a1b35 100644 --- a/api/src/routes/guilds/#guild_id/member-verification.ts +++ b/src/api/routes/guilds/#guild_id/member-verification.ts
diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
index d923c10f..d785eb00 100644 --- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts +++ b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
@@ -14,7 +14,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id, member_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - const member = await Member.findOneOrFail({ id: member_id, guild_id }); + const member = await Member.findOneOrFail({ where: { id: member_id, guild_id } }); return res.json(member); }); @@ -26,13 +26,13 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] }); const permission = await getPermission(req.user_id, guild_id); - const everyone = await Role.findOneOrFail({ guild_id: guild_id, name: "@everyone", position: 0 }); + const everyone = await Role.findOneOrFail({ where: { guild_id: guild_id, name: "@everyone", position: 0 } }); if (body.roles) { permission.hasThrow("MANAGE_ROLES"); if (body.roles.indexOf(everyone.id) === -1) body.roles.push(everyone.id); - member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist + member.roles = body.roles.map((x) => Role.create({ id: x })); // foreign key constraint will fail if role doesn't exist } if ('nick' in body) { diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/nick.ts b/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
index 27f7f65d..27f7f65d 100644 --- a/api/src/routes/guilds/#guild_id/members/#member_id/nick.ts +++ b/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts
index 8f5ca7ba..8f5ca7ba 100644 --- a/api/src/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts +++ b/src/api/routes/guilds/#guild_id/members/#member_id/roles/#role_id/index.ts
diff --git a/api/src/routes/guilds/#guild_id/members/index.ts b/src/api/routes/guilds/#guild_id/members/index.ts
index b730a4e7..b730a4e7 100644 --- a/api/src/routes/guilds/#guild_id/members/index.ts +++ b/src/api/routes/guilds/#guild_id/members/index.ts
diff --git a/api/src/routes/guilds/#guild_id/messages/search.ts b/src/api/routes/guilds/#guild_id/messages/search.ts
index a7516ebd..a7516ebd 100644 --- a/api/src/routes/guilds/#guild_id/messages/search.ts +++ b/src/api/routes/guilds/#guild_id/messages/search.ts
diff --git a/api/src/routes/guilds/#guild_id/premium.ts b/src/api/routes/guilds/#guild_id/premium.ts
index 75361ac6..75361ac6 100644 --- a/api/src/routes/guilds/#guild_id/premium.ts +++ b/src/api/routes/guilds/#guild_id/premium.ts
diff --git a/api/src/routes/guilds/#guild_id/prune.ts b/src/api/routes/guilds/#guild_id/prune.ts
index 0e587d22..cf3466f1 100644 --- a/api/src/routes/guilds/#guild_id/prune.ts +++ b/src/api/routes/guilds/#guild_id/prune.ts
@@ -33,7 +33,7 @@ export const inactiveMembers = async (guild_id: string, user_id: string, days: n //I'm sure I can do this in the above db query ( and it would probably be better to do so ), but oh well. if (roles.length && members.length) members = members.filter((user) => user.roles?.some((role) => roles.includes(role.id))); - const me = await Member.findOneOrFail({ id: user_id, guild_id }, { relations: ["roles"] }); + const me = await Member.findOneOrFail({ where: { id: user_id, guild_id }, relations: ["roles"] }); const myHighestRole = Math.max(...(me.roles?.map((x) => x.position) || [])); const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); diff --git a/api/src/routes/guilds/#guild_id/regions.ts b/src/api/routes/guilds/#guild_id/regions.ts
index 75d24fd1..308d5ee5 100644 --- a/api/src/routes/guilds/#guild_id/regions.ts +++ b/src/api/routes/guilds/#guild_id/regions.ts
@@ -7,7 +7,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); //TODO we should use an enum for guild's features and not hardcoded strings return res.json(await getVoiceRegions(getIpAdress(req), guild.features.includes("VIP_REGIONS"))); }); diff --git a/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts
index 16b5a59f..a01068c0 100644 --- a/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/#role_id/index.ts
@@ -9,7 +9,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id, role_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - const role = await Role.findOneOrFail({ guild_id, id: role_id }); + const role = await Role.findOneOrFail({ where: { guild_id, id: role_id } }); return res.json(role); }); @@ -44,7 +44,7 @@ router.patch("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" } if (body.icon && body.icon.length) body.icon = await handleFile(`/role-icons/${role_id}`, body.icon as string); else body.icon = undefined; - const role = new Role({ + const role = Role.create({ ...body, id: role_id, guild_id, diff --git a/api/src/routes/guilds/#guild_id/roles/index.ts b/src/api/routes/guilds/#guild_id/roles/index.ts
index 53465105..7e839f08 100644 --- a/api/src/routes/guilds/#guild_id/roles/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/index.ts
@@ -37,7 +37,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { await Member.IsInGuildOrFail(req.user_id, guild_id); - const roles = await Role.find({ guild_id: guild_id }); + const roles = await Role.find({ where: { guild_id: guild_id } }); return res.json(roles); }); @@ -46,12 +46,12 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }) const guild_id = req.params.guild_id; const body = req.body as RoleModifySchema; - const role_count = await Role.count({ guild_id }); + const role_count = await Role.count({ where: { guild_id } }); const { maxRoles } = Config.get().limits.guild; if (role_count > maxRoles) throw DiscordApiErrors.MAXIMUM_ROLES.withParams(maxRoles); - const role = new Role({ + const role = Role.create({ // values before ...body are default and can be overriden position: 0, hoist: false, @@ -62,8 +62,8 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }) managed: false, permissions: String(req.permission!.bitfield & BigInt(body.permissions || "0")), tags: undefined, - icon: null, - unicode_emoji: null + icon: undefined, + unicode_emoji: undefined }); await Promise.all([ diff --git a/api/src/routes/guilds/#guild_id/stickers.ts b/src/api/routes/guilds/#guild_id/stickers.ts
index 4ea1dce1..7a4e71ee 100644 --- a/api/src/routes/guilds/#guild_id/stickers.ts +++ b/src/api/routes/guilds/#guild_id/stickers.ts
@@ -19,7 +19,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - res.json(await Sticker.find({ guild_id })); + res.json(await Sticker.find({ where: { guild_id } })); }); const bodyParser = multer({ @@ -43,7 +43,7 @@ router.post( const id = Snowflake.generate(); const [sticker] = await Promise.all([ - new Sticker({ + Sticker.create({ ...body, guild_id, id, @@ -79,7 +79,7 @@ router.get("/:sticker_id", route({}), async (req: Request, res: Response) => { const { guild_id, sticker_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); - res.json(await Sticker.findOneOrFail({ guild_id, id: sticker_id })); + res.json(await Sticker.findOneOrFail({ where: { guild_id, id: sticker_id } })); }); export interface ModifyGuildStickerSchema { @@ -105,7 +105,7 @@ router.patch( const { guild_id, sticker_id } = req.params; const body = req.body as ModifyGuildStickerSchema; - const sticker = await new Sticker({ ...body, guild_id, id: sticker_id }).save(); + const sticker = await Sticker.create({ ...body, guild_id, id: sticker_id }).save(); await sendStickerUpdateEvent(guild_id); return res.json(sticker); @@ -118,7 +118,7 @@ async function sendStickerUpdateEvent(guild_id: string) { guild_id: guild_id, data: { guild_id: guild_id, - stickers: await Sticker.find({ guild_id: guild_id }) + stickers: await Sticker.find({ where: { guild_id: guild_id } }) } } as GuildStickersUpdateEvent); } diff --git a/api/src/routes/guilds/#guild_id/templates.ts b/src/api/routes/guilds/#guild_id/templates.ts
index 5179e761..0444c402 100644 --- a/api/src/routes/guilds/#guild_id/templates.ts +++ b/src/api/routes/guilds/#guild_id/templates.ts
@@ -36,7 +36,7 @@ export interface TemplateModifySchema { router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - var templates = await Template.find({ source_guild_id: guild_id }); + var templates = await Template.find({ where: { source_guild_id: guild_id } }); return res.json(templates); }); @@ -44,10 +44,10 @@ router.get("/", route({}), async (req: Request, res: Response) => { router.post("/", route({ body: "TemplateCreateSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => { const { guild_id } = req.params; const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection }); - const exists = await Template.findOneOrFail({ id: guild_id }).catch((e) => {}); + const exists = await Template.findOneOrFail({ where: { id: guild_id } }).catch((e) => { }); if (exists) throw new HTTPError("Template already exists", 400); - const template = await new Template({ + const template = await Template.create({ ...req.body, code: generateCode(), creator_id: req.user_id, @@ -75,7 +75,7 @@ router.put("/:code", route({ permission: "MANAGE_GUILD" }), async (req: Request, const { code, guild_id } = req.params; const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection }); - const template = await new Template({ code, serialized_source_guild: guild }).save(); + const template = await Template.create({ code, serialized_source_guild: guild }).save(); res.json(template); }); @@ -84,7 +84,7 @@ router.patch("/:code", route({ body: "TemplateModifySchema", permission: "MANAGE const { code, guild_id } = req.params; const { name, description } = req.body; - const template = await new Template({ code, name: name, description: description, source_guild_id: guild_id }).save(); + const template = await Template.create({ code, name: name, description: description, source_guild_id: guild_id }).save(); res.json(template); }); diff --git a/api/src/routes/guilds/#guild_id/vanity-url.ts b/src/api/routes/guilds/#guild_id/vanity-url.ts
index 29cd25e2..040bc1fd 100644 --- a/api/src/routes/guilds/#guild_id/vanity-url.ts +++ b/src/api/routes/guilds/#guild_id/vanity-url.ts
@@ -9,7 +9,7 @@ const InviteRegex = /\W/g; router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.features.includes("ALIASABLE_NAMES")) { const invite = await Invite.findOne({ where: { guild_id: guild_id, vanity_url: true } }); @@ -37,17 +37,17 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }) const body = req.body as VanityUrlSchema; const code = body.code?.replace(InviteRegex, ""); - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.features.includes("VANITY_URL")) throw new HTTPError("Your guild doesn't support vanity urls"); if (!code || code.length === 0) throw new HTTPError("Code cannot be null or empty"); - const invite = await Invite.findOne({ code }); + const invite = await Invite.findOne({ where: { code } }); if (invite) throw new HTTPError("Invite already exists"); - const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT }); + const { id } = await Channel.findOneOrFail({ where: { guild_id, type: ChannelType.GUILD_TEXT } }); - await new Invite({ + await Invite.create({ vanity_url: true, code: code, temporary: false, diff --git a/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts b/src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts
index f9fbea54..b7fdfecd 100644 --- a/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts +++ b/src/api/routes/guilds/#guild_id/voice-states/#user_id/index.ts
@@ -34,14 +34,16 @@ router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request if (body.request_to_speak_timestamp) perms.hasThrow("REQUEST_TO_SPEAK"); const voice_state = await VoiceState.findOne({ - guild_id, - channel_id: body.channel_id, - user_id + where: { + guild_id, + channel_id: body.channel_id, + user_id + } }); if (!voice_state) throw DiscordApiErrors.UNKNOWN_VOICE_STATE; voice_state.assign(body); - const channel = await Channel.findOneOrFail({ guild_id, id: body.channel_id }); + const channel = await Channel.findOneOrFail({ where: { guild_id, id: body.channel_id } }); if (channel.type !== ChannelType.GUILD_STAGE_VOICE) { throw DiscordApiErrors.CANNOT_EXECUTE_ON_THIS_CHANNEL_TYPE; } diff --git a/api/src/routes/guilds/#guild_id/webhooks.ts b/src/api/routes/guilds/#guild_id/webhooks.ts
index 8b2febea..8b2febea 100644 --- a/api/src/routes/guilds/#guild_id/webhooks.ts +++ b/src/api/routes/guilds/#guild_id/webhooks.ts
diff --git a/api/src/routes/guilds/#guild_id/welcome-screen.ts b/src/api/routes/guilds/#guild_id/welcome-screen.ts
index 5c7a9daa..a57255f0 100644 --- a/api/src/routes/guilds/#guild_id/welcome-screen.ts +++ b/src/api/routes/guilds/#guild_id/welcome-screen.ts
@@ -19,7 +19,7 @@ export interface GuildUpdateWelcomeScreenSchema { router.get("/", route({}), async (req: Request, res: Response) => { const guild_id = req.params.guild_id; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); await Member.IsInGuildOrFail(req.user_id, guild_id); res.json(guild.welcome_screen); @@ -29,7 +29,7 @@ router.patch("/", route({ body: "GuildUpdateWelcomeScreenSchema", permission: "M const guild_id = req.params.guild_id; const body = req.body as GuildUpdateWelcomeScreenSchema; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.welcome_screen.enabled) throw new HTTPError("Welcome screen disabled", 400); if (body.welcome_channels) guild.welcome_screen.welcome_channels = body.welcome_channels; // TODO: check if they exist and are valid diff --git a/api/src/routes/guilds/#guild_id/widget.json.ts b/src/api/routes/guilds/#guild_id/widget.json.ts
index c31519fa..be5bf23f 100644 --- a/api/src/routes/guilds/#guild_id/widget.json.ts +++ b/src/api/routes/guilds/#guild_id/widget.json.ts
@@ -17,18 +17,19 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.widget_enabled) throw new HTTPError("Widget Disabled", 404); // Fetch existing widget invite for widget channel - var invite = await Invite.findOne({ channel_id: guild.widget_channel_id }); + var invite = await Invite.findOne({ where: { channel_id: guild.widget_channel_id } }); if (guild.widget_channel_id && !invite) { // Create invite for channel if none exists // TODO: Refactor invite create code to a shared function const max_age = 86400; // 24 hours const expires_at = new Date(max_age * 1000 + Date.now()); - const body = { + + invite = await Invite.create({ code: random(), temporary: false, uses: 0, @@ -38,10 +39,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { created_at: new Date(), guild_id, channel_id: guild.widget_channel_id, - inviter_id: null - }; - - invite = await new Invite(body).save(); + }).save(); } // Fetch voice channels, and the @everyone permissions object @@ -63,7 +61,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { // Fetch members // TODO: Understand how Discord's max 100 random member sample works, and apply to here (see top of this file) - let members = await Member.find({ guild_id: guild_id }); + let members = await Member.find({ where: { guild_id: guild_id } }); // Construct object to respond with const data = { diff --git a/api/src/routes/guilds/#guild_id/widget.png.ts b/src/api/routes/guilds/#guild_id/widget.png.ts
index 4c82b740..721b59fb 100644 --- a/api/src/routes/guilds/#guild_id/widget.png.ts +++ b/src/api/routes/guilds/#guild_id/widget.png.ts
@@ -14,7 +14,7 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); if (!guild.widget_enabled) throw new HTTPError("Unknown Guild", 404); // Fetch guild information diff --git a/api/src/routes/guilds/#guild_id/widget.ts b/src/api/routes/guilds/#guild_id/widget.ts
index 2640618d..103f84a3 100644 --- a/api/src/routes/guilds/#guild_id/widget.ts +++ b/src/api/routes/guilds/#guild_id/widget.ts
@@ -13,7 +13,7 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; - const guild = await Guild.findOneOrFail({ id: guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: guild_id } }); return res.json({ enabled: guild.widget_enabled || false, channel_id: guild.widget_channel_id || null }); }); diff --git a/api/src/routes/guilds/index.ts b/src/api/routes/guilds/index.ts
index 489dea49..d44cd735 100644 --- a/api/src/routes/guilds/index.ts +++ b/src/api/routes/guilds/index.ts
@@ -24,9 +24,9 @@ router.post("/", route({ body: "GuildCreateSchema", right: "CREATE_GUILDS" }), a const body = req.body as GuildCreateSchema; const { maxGuilds } = Config.get().limits.user; - const guild_count = await Member.count({ id: req.user_id }); + const guild_count = await Member.count({ where: { id: req.user_id } }); const rights = await getRights(req.user_id); - if ((guild_count >= maxGuilds)&&!rights.has("MANAGE_GUILDS")) { + if ((guild_count >= maxGuilds) && !rights.has("MANAGE_GUILDS")) { throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds); } diff --git a/api/src/routes/guilds/templates/index.ts b/src/api/routes/guilds/templates/index.ts
index 3d922e85..e281214f 100644 --- a/api/src/routes/guilds/templates/index.ts +++ b/src/api/routes/guilds/templates/index.ts
@@ -15,9 +15,9 @@ router.get("/:code", route({}), async (req: Request, res: Response) => { if (!enabled) res.json({ code: 403, message: "Template creation & usage is disabled on this instance." }).sendStatus(403); const { code } = req.params; - + if (code.startsWith("discord:")) { - if (!allowDiscordTemplates) return res.json({ code: 403, message: "Discord templates cannot be used on this instance." }).sendStatus(403); + if (!allowDiscordTemplates) return res.json({ code: 403, message: "Discord templates cannot be used on this instance." }).sendStatus(403); const discordTemplateID = code.split("discord:", 2)[1]; const discordTemplateData = await fetch(`https://discord.com/api/v9/guilds/templates/${discordTemplateID}`, { @@ -28,12 +28,12 @@ router.get("/:code", route({}), async (req: Request, res: Response) => { } if (code.startsWith("external:")) { - if (!allowRaws) return res.json({ code: 403, message: "Importing raws is disabled on this instance." }).sendStatus(403); + if (!allowRaws) return res.json({ code: 403, message: "Importing raws is disabled on this instance." }).sendStatus(403); return res.json(code.split("external:", 2)[1]); } - const template = await Template.findOneOrFail({ code: code }); + const template = await Template.findOneOrFail({ where: { code: code } }); res.json(template); }); @@ -47,23 +47,23 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: const { maxGuilds } = Config.get().limits.user; - const guild_count = await Member.count({ id: req.user_id }); + const guild_count = await Member.count({ where: { id: req.user_id } }); if (guild_count >= maxGuilds) { throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds); } - const template = await Template.findOneOrFail({ code: code }); + const template = await Template.findOneOrFail({ where: { code: code } }); const guild_id = Snowflake.generate(); const [guild, role] = await Promise.all([ - new Guild({ + Guild.create({ ...body, ...template.serialized_source_guild, id: guild_id, owner_id: req.user_id }).save(), - new Role({ + Role.create({ id: guild_id, guild_id: guild_id, color: 0, @@ -71,9 +71,8 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req: managed: true, mentionable: true, name: "@everyone", - permissions: BigInt("2251804225"), + permissions: BigInt("2251804225").toString(), // TODO: where did this come from? position: 0, - tags: null }).save() ]); diff --git a/api/src/routes/invites/index.ts b/src/api/routes/invites/index.ts
index eeafb22a..c268085f 100644 --- a/api/src/routes/invites/index.ts +++ b/src/api/routes/invites/index.ts
@@ -13,15 +13,15 @@ router.get("/:code", route({}), async (req: Request, res: Response) => { res.status(200).send(invite); }); -router.post("/:code", route({right: "USE_MASS_INVITES"}), async (req: Request, res: Response) => { +router.post("/:code", route({ right: "USE_MASS_INVITES" }), async (req: Request, res: Response) => { const { code } = req.params; - const { guild_id } = await Invite.findOneOrFail({ code }) - const { features } = await Guild.findOneOrFail({ id: guild_id}); - const { public_flags } = await User.findOneOrFail({ id: req.user_id }); - - if(features.includes("INTERNAL_EMPLOYEE_ONLY") && (public_flags & 1) !== 1) throw new HTTPError("Only intended for the staff of this server.", 401); - if(features.includes("INVITES_CLOSED")) throw new HTTPError("Sorry, this guild has joins closed.", 403); - + const { guild_id } = await Invite.findOneOrFail({ where: { code: code } }); + const { features } = await Guild.findOneOrFail({ where: { id: guild_id } }); + const { public_flags } = await User.findOneOrFail({ where: { id: req.user_id } }); + + if (features.includes("INTERNAL_EMPLOYEE_ONLY") && (public_flags & 1) !== 1) throw new HTTPError("Only intended for the staff of this server.", 401); + if (features.includes("INVITES_CLOSED")) throw new HTTPError("Sorry, this guild has joins closed.", 403); + const invite = await Invite.joinGuild(req.user_id, code); res.json(invite); @@ -30,7 +30,7 @@ router.post("/:code", route({right: "USE_MASS_INVITES"}), async (req: Request, r // * cant use permission of route() function because path doesn't have guild_id/channel_id router.delete("/:code", route({}), async (req: Request, res: Response) => { const { code } = req.params; - const invite = await Invite.findOneOrFail({ code }); + const invite = await Invite.findOneOrFail({ where: { code } }); const { guild_id, channel_id } = invite; const permission = await getPermission(req.user_id, guild_id, channel_id); diff --git a/api/src/routes/oauth2/tokens.ts b/src/api/routes/oauth2/tokens.ts
index bd284221..bd284221 100644 --- a/api/src/routes/oauth2/tokens.ts +++ b/src/api/routes/oauth2/tokens.ts
diff --git a/api/src/routes/outbound-promotions.ts b/src/api/routes/outbound-promotions.ts
index 411e95bf..411e95bf 100644 --- a/api/src/routes/outbound-promotions.ts +++ b/src/api/routes/outbound-promotions.ts
diff --git a/api/src/routes/partners/#guild_id/requirements.ts b/src/api/routes/partners/#guild_id/requirements.ts
index 545c5c78..545c5c78 100644 --- a/api/src/routes/partners/#guild_id/requirements.ts +++ b/src/api/routes/partners/#guild_id/requirements.ts
diff --git a/api/src/routes/ping.ts b/src/api/routes/ping.ts
index 3c1da2c3..3c1da2c3 100644 --- a/api/src/routes/ping.ts +++ b/src/api/routes/ping.ts
diff --git a/api/src/routes/policies/instance/domains.ts b/src/api/routes/policies/instance/domains.ts
index 20cd07ba..20cd07ba 100644 --- a/api/src/routes/policies/instance/domains.ts +++ b/src/api/routes/policies/instance/domains.ts
diff --git a/api/src/routes/policies/instance/index.ts b/src/api/routes/policies/instance/index.ts
index e3da014f..e3da014f 100644 --- a/api/src/routes/policies/instance/index.ts +++ b/src/api/routes/policies/instance/index.ts
diff --git a/api/src/routes/policies/instance/limits.ts b/src/api/routes/policies/instance/limits.ts
index 7de1476b..7de1476b 100644 --- a/api/src/routes/policies/instance/limits.ts +++ b/src/api/routes/policies/instance/limits.ts
diff --git a/api/src/routes/scheduled-maintenances/upcoming_json.ts b/src/api/routes/scheduled-maintenances/upcoming_json.ts
index 83092e44..83092e44 100644 --- a/api/src/routes/scheduled-maintenances/upcoming_json.ts +++ b/src/api/routes/scheduled-maintenances/upcoming_json.ts
diff --git a/api/src/routes/science.ts b/src/api/routes/science.ts
index 8556a3ad..8556a3ad 100644 --- a/api/src/routes/science.ts +++ b/src/api/routes/science.ts
diff --git a/api/src/routes/stage-instances.ts b/src/api/routes/stage-instances.ts
index 411e95bf..411e95bf 100644 --- a/api/src/routes/stage-instances.ts +++ b/src/api/routes/stage-instances.ts
diff --git a/api/src/routes/sticker-packs/index.ts b/src/api/routes/sticker-packs/index.ts
index e6560d12..e6560d12 100644 --- a/api/src/routes/sticker-packs/index.ts +++ b/src/api/routes/sticker-packs/index.ts
diff --git a/api/src/routes/stickers/#sticker_id/index.ts b/src/api/routes/stickers/#sticker_id/index.ts
index 293ca089..b484a7a1 100644 --- a/api/src/routes/stickers/#sticker_id/index.ts +++ b/src/api/routes/stickers/#sticker_id/index.ts
@@ -6,7 +6,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { sticker_id } = req.params; - res.json(await Sticker.find({ id: sticker_id })); + res.json(await Sticker.find({ where: { id: sticker_id } })); }); export default router; diff --git a/api/src/routes/stop.ts b/src/api/routes/stop.ts
index 7f8b78ba..7f8b78ba 100644 --- a/api/src/routes/stop.ts +++ b/src/api/routes/stop.ts
diff --git a/api/src/routes/store/published-listings/applications.ts b/src/api/routes/store/published-listings/applications.ts
index 060a4c3d..060a4c3d 100644 --- a/api/src/routes/store/published-listings/applications.ts +++ b/src/api/routes/store/published-listings/applications.ts
diff --git a/api/src/routes/store/published-listings/applications/#id/subscription-plans.ts b/src/api/routes/store/published-listings/applications/#id/subscription-plans.ts
index 54151ae5..54151ae5 100644 --- a/api/src/routes/store/published-listings/applications/#id/subscription-plans.ts +++ b/src/api/routes/store/published-listings/applications/#id/subscription-plans.ts
diff --git a/api/src/routes/store/published-listings/skus.ts b/src/api/routes/store/published-listings/skus.ts
index 060a4c3d..060a4c3d 100644 --- a/api/src/routes/store/published-listings/skus.ts +++ b/src/api/routes/store/published-listings/skus.ts
diff --git a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts b/src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts
index 03162ec8..03162ec8 100644 --- a/api/src/routes/store/published-listings/skus/#sku_id/subscription-plans.ts +++ b/src/api/routes/store/published-listings/skus/#sku_id/subscription-plans.ts
diff --git a/api/src/routes/teams.ts b/src/api/routes/teams.ts
index 7ce3abcb..7ce3abcb 100644 --- a/api/src/routes/teams.ts +++ b/src/api/routes/teams.ts
diff --git a/api/src/routes/template.ts.disabled b/src/api/routes/template.ts.disabled
index fcc59ef4..fcc59ef4 100644 --- a/api/src/routes/template.ts.disabled +++ b/src/api/routes/template.ts.disabled
diff --git a/api/src/routes/track.ts b/src/api/routes/track.ts
index 8556a3ad..8556a3ad 100644 --- a/api/src/routes/track.ts +++ b/src/api/routes/track.ts
diff --git a/api/src/routes/updates.ts b/src/api/routes/updates.ts
index cb4577c8..42f77323 100644 --- a/api/src/routes/updates.ts +++ b/src/api/routes/updates.ts
@@ -7,14 +7,14 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { client } = Config.get(); - const release = await Release.findOneOrFail({ name: client.releases.upstreamVersion}) + const release = await Release.findOneOrFail({ where: { name: client.releases.upstreamVersion } }); res.json({ - name: release.name, - pub_date: release.pub_date, - url: release.url, - notes: release.notes - }); + name: release.name, + pub_date: release.pub_date, + url: release.url, + notes: release.notes + }); }); export default router; diff --git a/api/src/routes/users/#id/index.ts b/src/api/routes/users/#id/index.ts
index bdb1060f..bdb1060f 100644 --- a/api/src/routes/users/#id/index.ts +++ b/src/api/routes/users/#id/index.ts
diff --git a/api/src/routes/users/#id/profile.ts b/src/api/routes/users/#id/profile.ts
index a77fbdb5..de96422a 100644 --- a/api/src/routes/users/#id/profile.ts +++ b/src/api/routes/users/#id/profile.ts
@@ -22,8 +22,8 @@ router.get("/", route({ test: { response: { body: "UserProfileResponse" } } }), var premium_guild_since; if (with_mutual_guilds == "true") { - const requested_member = await Member.find({ id: req.params.id, }); - const self_member = await Member.find({ id: req.user_id, }); + const requested_member = await Member.find({ where: { id: req.params.id } }); + const self_member = await Member.find({ where: { id: req.user_id } }); for (const rmem of requested_member) { if (rmem.premium_since) { @@ -44,7 +44,7 @@ router.get("/", route({ test: { response: { body: "UserProfileResponse" } } }), } const guild_member = guild_id && typeof guild_id == "string" - ? await Member.findOneOrFail({ id: req.params.id, guild_id: guild_id }, { relations: ["roles"] }) + ? await Member.findOneOrFail({ where: { id: req.params.id, guild_id: guild_id }, relations: ["roles"] }) : undefined; // TODO: make proper DTO's in util? diff --git a/api/src/routes/users/#id/relationships.ts b/src/api/routes/users/#id/relationships.ts
index de7cb9d3..de7cb9d3 100644 --- a/api/src/routes/users/#id/relationships.ts +++ b/src/api/routes/users/#id/relationships.ts
diff --git a/api/src/routes/users/@me/activities/statistics/applications.ts b/src/api/routes/users/@me/activities/statistics/applications.ts
index 014df8af..014df8af 100644 --- a/api/src/routes/users/@me/activities/statistics/applications.ts +++ b/src/api/routes/users/@me/activities/statistics/applications.ts
diff --git a/api/src/routes/users/@me/affinities/guilds.ts b/src/api/routes/users/@me/affinities/guilds.ts
index 8d744744..8d744744 100644 --- a/api/src/routes/users/@me/affinities/guilds.ts +++ b/src/api/routes/users/@me/affinities/guilds.ts
diff --git a/api/src/routes/users/@me/affinities/users.ts b/src/api/routes/users/@me/affinities/users.ts
index 6d4e4991..6d4e4991 100644 --- a/api/src/routes/users/@me/affinities/users.ts +++ b/src/api/routes/users/@me/affinities/users.ts
diff --git a/api/src/routes/users/@me/applications/#app_id/entitlements.ts b/src/api/routes/users/@me/applications/#app_id/entitlements.ts
index 411e95bf..411e95bf 100644 --- a/api/src/routes/users/@me/applications/#app_id/entitlements.ts +++ b/src/api/routes/users/@me/applications/#app_id/entitlements.ts
diff --git a/api/src/routes/users/@me/billing/country-code.ts b/src/api/routes/users/@me/billing/country-code.ts
index 33d40796..33d40796 100644 --- a/api/src/routes/users/@me/billing/country-code.ts +++ b/src/api/routes/users/@me/billing/country-code.ts
diff --git a/api/src/routes/users/@me/billing/payment-sources.ts b/src/api/routes/users/@me/billing/payment-sources.ts
index 014df8af..014df8af 100644 --- a/api/src/routes/users/@me/billing/payment-sources.ts +++ b/src/api/routes/users/@me/billing/payment-sources.ts
diff --git a/api/src/routes/users/@me/billing/subscriptions.ts b/src/api/routes/users/@me/billing/subscriptions.ts
index 411e95bf..411e95bf 100644 --- a/api/src/routes/users/@me/billing/subscriptions.ts +++ b/src/api/routes/users/@me/billing/subscriptions.ts
diff --git a/api/src/routes/users/@me/channels.ts b/src/api/routes/users/@me/channels.ts
index 78f531e1..78f531e1 100644 --- a/api/src/routes/users/@me/channels.ts +++ b/src/api/routes/users/@me/channels.ts
diff --git a/api/src/routes/users/@me/connections.ts b/src/api/routes/users/@me/connections.ts
index 411e95bf..411e95bf 100644 --- a/api/src/routes/users/@me/connections.ts +++ b/src/api/routes/users/@me/connections.ts
diff --git a/api/src/routes/users/@me/delete.ts b/src/api/routes/users/@me/delete.ts
index c24c3f1e..c24c3f1e 100644 --- a/api/src/routes/users/@me/delete.ts +++ b/src/api/routes/users/@me/delete.ts
diff --git a/api/src/routes/users/@me/devices.ts b/src/api/routes/users/@me/devices.ts
index 8556a3ad..8556a3ad 100644 --- a/api/src/routes/users/@me/devices.ts +++ b/src/api/routes/users/@me/devices.ts
diff --git a/api/src/routes/users/@me/disable.ts b/src/api/routes/users/@me/disable.ts
index 4aff3774..4aff3774 100644 --- a/api/src/routes/users/@me/disable.ts +++ b/src/api/routes/users/@me/disable.ts
diff --git a/api/src/routes/users/@me/email-settings.ts b/src/api/routes/users/@me/email-settings.ts
index 3114984e..3114984e 100644 --- a/api/src/routes/users/@me/email-settings.ts +++ b/src/api/routes/users/@me/email-settings.ts
diff --git a/api/src/routes/users/@me/entitlements.ts b/src/api/routes/users/@me/entitlements.ts
index 341e2b4c..341e2b4c 100644 --- a/api/src/routes/users/@me/entitlements.ts +++ b/src/api/routes/users/@me/entitlements.ts
diff --git a/api/src/routes/users/@me/guilds.ts b/src/api/routes/users/@me/guilds.ts
index 754a240e..754a240e 100644 --- a/api/src/routes/users/@me/guilds.ts +++ b/src/api/routes/users/@me/guilds.ts
diff --git a/api/src/routes/users/@me/guilds/#guild_id/settings.ts b/src/api/routes/users/@me/guilds/#guild_id/settings.ts
index f09be25b..f09be25b 100644 --- a/api/src/routes/users/@me/guilds/#guild_id/settings.ts +++ b/src/api/routes/users/@me/guilds/#guild_id/settings.ts
diff --git a/api/src/routes/users/@me/guilds/premium/subscription-slots.ts b/src/api/routes/users/@me/guilds/premium/subscription-slots.ts
index 014df8af..014df8af 100644 --- a/api/src/routes/users/@me/guilds/premium/subscription-slots.ts +++ b/src/api/routes/users/@me/guilds/premium/subscription-slots.ts
diff --git a/api/src/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts
index 36b62b55..36b62b55 100644 --- a/api/src/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts
diff --git a/api/src/routes/users/@me/library.ts b/src/api/routes/users/@me/library.ts
index 7ac13bae..7ac13bae 100644 --- a/api/src/routes/users/@me/library.ts +++ b/src/api/routes/users/@me/library.ts
diff --git a/api/src/routes/users/@me/mfa/codes-verification.ts b/src/api/routes/users/@me/mfa/codes-verification.ts
index 3aca44a6..09000d07 100644 --- a/api/src/routes/users/@me/mfa/codes-verification.ts +++ b/src/api/routes/users/@me/mfa/codes-verification.ts
@@ -16,7 +16,7 @@ router.post("/", route({ body: "CodesVerificationSchema" }), async (req: Request // TODO: We don't have email/etc etc, so can't send a verification code. // Once that's done, this route can verify `key` - const user = await User.findOneOrFail({ id: req.user_id }); + const user = await User.findOneOrFail({ where: { id: req.user_id } }); var codes: BackupCode[]; if (regenerate) { @@ -30,16 +30,18 @@ router.post("/", route({ body: "CodesVerificationSchema" }), async (req: Request } else { codes = await BackupCode.find({ - user: { - id: req.user_id, - }, - expired: false, + where: { + user: { + id: req.user_id, + }, + expired: false, + } }); } return res.json({ backup_codes: codes.map(x => ({ ...x, expired: undefined })), - }) + }); }); export default router; diff --git a/api/src/routes/users/@me/mfa/codes.ts b/src/api/routes/users/@me/mfa/codes.ts
index 2a1fb498..67bd3d5b 100644 --- a/api/src/routes/users/@me/mfa/codes.ts +++ b/src/api/routes/users/@me/mfa/codes.ts
@@ -15,7 +15,7 @@ export interface MfaCodesSchema { router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Response) => { const { password, regenerate } = req.body as MfaCodesSchema; - const user = await User.findOneOrFail({ id: req.user_id }, { select: ["data"] }); + const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] }); if (!await bcrypt.compare(password, user.data.hash || "")) { throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } }); @@ -33,16 +33,18 @@ router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Re } else { codes = await BackupCode.find({ - user: { - id: req.user_id, - }, - expired: false, + where: { + user: { + id: req.user_id, + }, + expired: false, + } }); } return res.json({ backup_codes: codes.map(x => ({ ...x, expired: undefined })), - }) + }); }); export default router; diff --git a/api/src/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts
index 5e039ea3..2d385fda 100644 --- a/api/src/routes/users/@me/mfa/totp/disable.ts +++ b/src/api/routes/users/@me/mfa/totp/disable.ts
@@ -13,9 +13,9 @@ export interface TotpDisableSchema { router.post("/", route({ body: "TotpDisableSchema" }), async (req: Request, res: Response) => { const body = req.body as TotpDisableSchema; - const user = await User.findOneOrFail({ id: req.user_id }, { select: ["totp_secret"] }); + const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["totp_secret"] }); - const backup = await BackupCode.findOne({ code: body.code }); + const backup = await BackupCode.findOne({ where: { code: body.code } }); if (!backup) { const ret = verifyToken(user.totp_secret!, body.code); if (!ret || ret.delta != 0) diff --git a/api/src/routes/users/@me/mfa/totp/enable.ts b/src/api/routes/users/@me/mfa/totp/enable.ts
index e4ce9ce0..e4ce9ce0 100644 --- a/api/src/routes/users/@me/mfa/totp/enable.ts +++ b/src/api/routes/users/@me/mfa/totp/enable.ts
diff --git a/api/src/routes/users/@me/notes.ts b/src/api/routes/users/@me/notes.ts
index 3c503942..f938f088 100644 --- a/api/src/routes/users/@me/notes.ts +++ b/src/api/routes/users/@me/notes.ts
@@ -29,7 +29,7 @@ router.put("/:id", route({}), async (req: Request, res: Response) => { if (note && note.length) { // upsert a note - if (await Note.findOne({ owner: { id: owner.id }, target: { id: target.id } })) { + if (await Note.findOne({ where: { owner: { id: owner.id }, target: { id: target.id } } })) { Note.update( { owner: { id: owner.id }, target: { id: target.id } }, { owner, target, content: note } diff --git a/api/src/routes/users/@me/relationships.ts b/src/api/routes/users/@me/relationships.ts
index c5a643d2..00d4da0b 100644 --- a/api/src/routes/users/@me/relationships.ts +++ b/src/api/routes/users/@me/relationships.ts
@@ -45,7 +45,7 @@ router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request return await updateRelationship( req, res, - await User.findOneOrFail({ id: req.params.id }, { relations: ["relationships", "relationships.to"], select: userProjection }), + await User.findOneOrFail({ where: { id: req.params.id }, relations: ["relationships", "relationships.to"], select: userProjection }), req.body.type ?? RelationshipType.friends ); }); @@ -75,8 +75,8 @@ router.delete("/:id", route({}), async (req: Request, res: Response) => { const { id } = req.params; if (id === req.user_id) throw new HTTPError("You can't remove yourself as a friend"); - const user = await User.findOneOrFail({ id: req.user_id }, { select: userProjection, relations: ["relationships"] }); - const friend = await User.findOneOrFail({ id: id }, { select: userProjection, relations: ["relationships"] }); + const user = await User.findOneOrFail({ where: { id: req.user_id }, select: userProjection, relations: ["relationships"] }); + const friend = await User.findOneOrFail({ where: { id: id }, select: userProjection, relations: ["relationships"] }); const relationship = user.relationships.find((x) => x.to_id === id); const friendRequest = friend.relationships.find((x) => x.to_id === req.user_id); @@ -124,10 +124,10 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ const id = friend.id; if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend"); - const user = await User.findOneOrFail( - { id: req.user_id }, - { relations: ["relationships", "relationships.to"], select: userProjection } - ); + const user = await User.findOneOrFail({ + where: { id: req.user_id }, + relations: ["relationships", "relationships.to"], select: userProjection + }); var relationship = user.relationships.find((x) => x.to_id === id); const friendRequest = friend.relationships.find((x) => x.to_id === req.user_id); @@ -139,7 +139,7 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ relationship.type = RelationshipType.blocked; await relationship.save(); } else { - relationship = await new Relationship({ to_id: id, type: RelationshipType.blocked, from_id: req.user_id }).save(); + relationship = await Relationship.create({ to_id: id, type: RelationshipType.blocked, from_id: req.user_id }).save(); } if (friendRequest && friendRequest.type !== RelationshipType.blocked) { @@ -165,8 +165,8 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ const { maxFriends } = Config.get().limits.user; if (user.relationships.length >= maxFriends) throw DiscordApiErrors.MAXIMUM_FRIENDS.withParams(maxFriends); - var incoming_relationship = new Relationship({ nickname: undefined, type: RelationshipType.incoming, to: user, from: friend }); - var outgoing_relationship = new Relationship({ + var incoming_relationship = Relationship.create({ nickname: undefined, type: RelationshipType.incoming, to: user, from: friend }); + var outgoing_relationship = Relationship.create({ nickname: undefined, type: RelationshipType.outgoing, to: friend, diff --git a/api/src/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts
index a03e2fdd..9060baf7 100644 --- a/api/src/routes/users/@me/settings.ts +++ b/src/api/routes/users/@me/settings.ts
@@ -7,10 +7,10 @@ const router = Router(); export interface UserSettingsSchema extends Partial<UserSettings> { } router.get("/", route({}), async (req: Request, res: Response) => { - const user = await User.findOneOrFail( - { id: req.user_id }, - { select: ["settings"] } - ); + const user = await User.findOneOrFail({ + where: { id: req.user_id }, + select: ["settings"] + }); return res.json(user.settings); }); @@ -18,7 +18,7 @@ router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, re const body = req.body as UserSettings; if (body.locale === "en") body.locale = "en-US"; // fix discord client crash on unkown locale - const user = await User.findOneOrFail({ id: req.user_id, bot: false }); + const user = await User.findOneOrFail({ where: { id: req.user_id, bot: false } }); user.settings = { ...user.settings, ...body }; await user.save(); diff --git a/api/src/routes/voice/regions.ts b/src/api/routes/voice/regions.ts
index 4de304ee..4de304ee 100644 --- a/api/src/routes/voice/regions.ts +++ b/src/api/routes/voice/regions.ts
diff --git a/api/src/start.ts b/src/api/start.ts
index ccb4d108..ccb4d108 100644 --- a/api/src/start.ts +++ b/src/api/start.ts
diff --git a/api/src/util/entities/blockedEmailDomains.txt b/src/api/util/entities/blockedEmailDomains.txt
index eb88305d..eb88305d 100644 --- a/api/src/util/entities/blockedEmailDomains.txt +++ b/src/api/util/entities/blockedEmailDomains.txt
diff --git a/api/src/util/entities/trustedEmailDomains.txt b/src/api/util/entities/trustedEmailDomains.txt
index 38ffa4fa..38ffa4fa 100644 --- a/api/src/util/entities/trustedEmailDomains.txt +++ b/src/api/util/entities/trustedEmailDomains.txt
diff --git a/api/src/util/handlers/Instance.ts b/src/api/util/handlers/Instance.ts
index 6bddfa98..fa134fd8 100644 --- a/api/src/util/handlers/Instance.ts +++ b/src/api/util/handlers/Instance.ts
@@ -9,7 +9,7 @@ export async function initInstance() { const { autoJoin } = Config.get().guild; if (autoJoin.enabled && !autoJoin.guilds?.length) { - let guild = await Guild.findOne({}); + let guild = await Guild.findOne({ where: {}, select: ["id"] }); if (guild) { // @ts-ignore await Config.set({ guild: { autoJoin: { guilds: [guild.id] } } }); diff --git a/api/src/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index 398b8914..7e91fb7b 100644 --- a/api/src/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -21,11 +21,13 @@ import { Webhook, Attachment, Config, + Sticker, } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import fetch from "node-fetch"; import cheerio from "cheerio"; import { MessageCreateSchema } from "../../routes/channels/#channel_id/messages"; +import { In } from "typeorm"; const allow_empty = false; // TODO: check webhook, application, system author, stickers // TODO: embed gifs/videos/images @@ -47,9 +49,11 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { const channel = await Channel.findOneOrFail({ where: { id: opts.channel_id }, relations: ["recipients"] }); if (!channel || !opts.channel_id) throw new HTTPError("Channel not found", 404); - const message = new Message({ + const stickers = opts.sticker_ids ? await Sticker.find({ where: { id: In(opts.sticker_ids) } }) : undefined; + const message = Message.create({ ...opts, - sticker_items: opts.sticker_ids?.map((x) => ({ id: x })), + id: Snowflake.generate(), + sticker_items: stickers, guild_id: channel.guild_id, channel_id: opts.channel_id, attachments: opts.attachments || [], @@ -68,10 +72,10 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { rights.hasThrow("SEND_MESSAGES"); } if (opts.application_id) { - message.application = await Application.findOneOrFail({ id: opts.application_id }); + message.application = await Application.findOneOrFail({ where: { id: opts.application_id } }); } if (opts.webhook_id) { - message.webhook = await Webhook.findOneOrFail({ id: opts.webhook_id }); + message.webhook = await Webhook.findOneOrFail({ where: { id: opts.webhook_id } }); } const permission = await getPermission(opts.author_id, channel.guild_id, opts.channel_id); @@ -85,7 +89,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { permission.hasThrow("READ_MESSAGE_HISTORY"); // code below has to be redone when we add custom message routing if (message.guild_id !== null) { - const guild = await Guild.findOneOrFail({ id: channel.guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: channel.guild_id } }); if (!guild.features.includes("CROSS_CHANNEL_REPLIES")) { if (opts.message_reference.guild_id !== channel.guild_id) throw new HTTPError("You can only reference messages from this guild"); if (opts.message_reference.channel_id !== opts.channel_id) throw new HTTPError("You can only reference messages from this channel"); @@ -120,7 +124,7 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { await Promise.all( Array.from(content.matchAll(ROLE_MENTION)).map(async ([_, mention]) => { - const role = await Role.findOneOrFail({ id: mention, guild_id: channel.guild_id }); + const role = await Role.findOneOrFail({ where: { id: mention, guild_id: channel.guild_id } }); if (role.mentionable || permission.has("MANAGE_ROLES")) { mention_role_ids.push(mention); } @@ -132,9 +136,9 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> { } } - message.mention_channels = mention_channel_ids.map((x) => new Channel({ id: x })); - message.mention_roles = mention_role_ids.map((x) => new Role({ id: x })); - message.mentions = mention_user_ids.map((x) => new User({ id: x })); + message.mention_channels = mention_channel_ids.map((x) => Channel.create({ id: x })); + message.mention_roles = mention_role_ids.map((x) => Role.create({ id: x })); + message.mentions = mention_user_ids.map((x) => User.create({ id: x })); message.mention_everyone = mention_everyone; // TODO: check and put it all in the body @@ -278,6 +282,6 @@ interface MessageOptions extends MessageCreateSchema { embeds?: Embed[]; channel_id?: string; attachments?: Attachment[]; - edited_timestamp: Date | null; + edited_timestamp?: Date; timestamp?: Date; } diff --git a/api/src/util/handlers/Voice.ts b/src/api/util/handlers/Voice.ts
index 4d60eb91..4d60eb91 100644 --- a/api/src/util/handlers/Voice.ts +++ b/src/api/util/handlers/Voice.ts
diff --git a/api/src/util/handlers/route.ts b/src/api/util/handlers/route.ts
index 3d3bbc37..c245b411 100644 --- a/api/src/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts
@@ -1,39 +1,19 @@ import { + ajv, DiscordApiErrors, EVENT, - Event, - EventData, FieldErrors, FosscordApiErrors, getPermission, getRights, + normalizeBody, PermissionResolvable, Permissions, RightResolvable, Rights } from "@fosscord/util"; import { NextFunction, Request, Response } from "express"; -import fs from "fs"; -import path from "path"; -import Ajv from "ajv"; import { AnyValidateFunction } from "ajv/dist/core"; -import addFormats from "ajv-formats"; - -const SchemaPath = path.join(__dirname, "..", "..", "..", "assets", "schemas.json"); -const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" })); - -export const ajv = new Ajv({ - allErrors: true, - parseDate: true, - allowDate: true, - schemas, - coerceTypes: true, - messages: true, - strict: true, - strictRequired: true -}); - -addFormats(ajv); declare global { namespace Express { @@ -58,34 +38,6 @@ export interface RouteOptions { }; } -// Normalizer is introduced to workaround https://github.com/ajv-validator/ajv/issues/1287 -// this removes null values as ajv doesn't treat them as undefined -// normalizeBody allows to handle circular structures without issues -// taken from https://github.com/serverless/serverless/blob/master/lib/classes/ConfigSchemaHandler/index.js#L30 (MIT license) -const normalizeBody = (body: any = {}) => { - const normalizedObjectsSet = new WeakSet(); - const normalizeObject = (object: any) => { - if (normalizedObjectsSet.has(object)) return; - normalizedObjectsSet.add(object); - if (Array.isArray(object)) { - for (const [index, value] of object.entries()) { - if (typeof value === "object") normalizeObject(value); - } - } else { - for (const [key, value] of Object.entries(object)) { - if (value == null) { - if (key === "icon" || key === "avatar" || key === "banner" || key === "splash" || key === "discovery_splash") continue; - delete object[key]; - } else if (typeof value === "object") { - normalizeObject(value); - } - } - } - }; - normalizeObject(body); - return body; -}; - export function route(opts: RouteOptions) { var validate: AnyValidateFunction<any> | undefined; if (opts.body) { diff --git a/api/src/util/index.ts b/src/api/util/index.ts
index de6b6064..de6b6064 100644 --- a/api/src/util/index.ts +++ b/src/api/util/index.ts
diff --git a/api/src/util/utility/Base64.ts b/src/api/util/utility/Base64.ts
index 46cff77a..46cff77a 100644 --- a/api/src/util/utility/Base64.ts +++ b/src/api/util/utility/Base64.ts
diff --git a/api/src/util/utility/RandomInviteID.ts b/src/api/util/utility/RandomInviteID.ts
index 7ea344e0..7ea344e0 100644 --- a/api/src/util/utility/RandomInviteID.ts +++ b/src/api/util/utility/RandomInviteID.ts
diff --git a/api/src/util/utility/String.ts b/src/api/util/utility/String.ts
index 982b7e11..982b7e11 100644 --- a/api/src/util/utility/String.ts +++ b/src/api/util/utility/String.ts
diff --git a/api/src/util/utility/captcha.ts b/src/api/util/utility/captcha.ts
index 739647d2..739647d2 100644 --- a/api/src/util/utility/captcha.ts +++ b/src/api/util/utility/captcha.ts
diff --git a/api/src/util/utility/ipAddress.ts b/src/api/util/utility/ipAddress.ts
index 13cc9603..f17b145e 100644 --- a/api/src/util/utility/ipAddress.ts +++ b/src/api/util/utility/ipAddress.ts
@@ -65,7 +65,7 @@ export async function IPAnalysis(ip: string): Promise<typeof exampleData> { const { ipdataApiKey } = Config.get().security; if (!ipdataApiKey) return { ...exampleData, ip }; - return (await fetch(`https://api.ipdata.co/${ip}?api-key=${ipdataApiKey}`)).json(); + return (await fetch(`https://api.ipdata.co/${ip}?api-key=${ipdataApiKey}`)).json() as any; // TODO: types } export function isProxy(data: typeof exampleData) { diff --git a/api/src/util/utility/passwordStrength.ts b/src/api/util/utility/passwordStrength.ts
index 439700d0..439700d0 100644 --- a/api/src/util/utility/passwordStrength.ts +++ b/src/api/util/utility/passwordStrength.ts