summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-15 11:13:21 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-15 11:13:21 +0200
commit1a94fb1208bf0e4c669cad16aff5f57dc0bf7a3c (patch)
tree1035116ddbaacc5fcc5ae250a6592eb88f78f75c /api/src
parentDo the funny thing (make user->invite cascade delet) (diff)
parentchange dev panel path, we missed this one... (diff)
downloadserver-1a94fb1208bf0e4c669cad16aff5f57dc0bf7a3c.tar.xz
Merge branch 'dev/restructure' into staging
Diffstat (limited to '')
-rw-r--r--src/api/Server.ts (renamed from api/src/Server.ts)0
-rw-r--r--src/api/global.d.ts (renamed from api/src/global.d.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/TestClient.ts (renamed from api/src/middlewares/TestClient.ts)18
-rw-r--r--src/api/middlewares/Translation.ts (renamed from api/src/middlewares/Translation.ts)6
-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)0
-rw-r--r--src/api/routes/-/readyz.ts (renamed from api/src/routes/-/readyz.ts)0
-rw-r--r--src/api/routes/applications/#id/bot/index.ts (renamed from api/src/routes/applications/#id/bot/index.ts)0
-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/#id/index.ts (renamed from api/src/routes/applications/#id/index.ts)0
-rw-r--r--src/api/routes/applications/#id/skus.ts (renamed from api/src/routes/applications/#id/skus.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)11
-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)28
-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)28
-rw-r--r--src/api/routes/channels/#channel_id/invites.ts (renamed from api/src/routes/channels/#channel_id/invites.ts)20
-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)9
-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)4
-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)0
-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)6
-rw-r--r--src/api/routes/channels/#channel_id/messages/index.ts (renamed from api/src/routes/channels/#channel_id/messages/index.ts)36
-rw-r--r--src/api/routes/channels/#channel_id/permissions.ts (renamed from api/src/routes/channels/#channel_id/permissions.ts)7
-rw-r--r--src/api/routes/channels/#channel_id/pins.ts (renamed from api/src/routes/channels/#channel_id/pins.ts)0
-rw-r--r--src/api/routes/channels/#channel_id/purge.ts (renamed from api/src/routes/channels/#channel_id/purge.ts)7
-rw-r--r--src/api/routes/channels/#channel_id/recipients.ts (renamed from api/src/routes/channels/#channel_id/recipients.ts)0
-rw-r--r--src/api/routes/channels/#channel_id/typing.ts (renamed from api/src/routes/channels/#channel_id/typing.ts)0
-rw-r--r--src/api/routes/channels/#channel_id/webhooks.ts (renamed from api/src/routes/channels/#channel_id/webhooks.ts)9
-rw-r--r--src/api/routes/discoverable-guilds.ts (renamed from api/src/routes/discoverable-guilds.ts)0
-rw-r--r--src/api/routes/discovery.ts (renamed from api/src/routes/discovery.ts)0
-rw-r--r--src/api/routes/downloads.ts (renamed from api/src/routes/downloads.ts)0
-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)0
-rw-r--r--src/api/routes/gifs/trending-gifs.ts (renamed from api/src/routes/gifs/trending-gifs.ts)0
-rw-r--r--src/api/routes/gifs/trending.ts (renamed from api/src/routes/gifs/trending.ts)0
-rw-r--r--src/api/routes/guild-recommendations.ts (renamed from api/src/routes/guild-recommendations.ts)0
-rw-r--r--src/api/routes/guilds/#guild_id/audit-logs.ts (renamed from api/src/routes/guilds/#guild_id/audit-logs.ts)3
-rw-r--r--src/api/routes/guilds/#guild_id/bans.ts (renamed from api/src/routes/guilds/#guild_id/bans.ts)24
-rw-r--r--src/api/routes/guilds/#guild_id/channels.ts (renamed from api/src/routes/guilds/#guild_id/channels.ts)5
-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)14
-rw-r--r--src/api/routes/guilds/#guild_id/index.ts (renamed from api/src/routes/guilds/#guild_id/index.ts)19
-rw-r--r--src/api/routes/guilds/#guild_id/integrations.ts (renamed from api/src/routes/guilds/#guild_id/integrations.ts)1
-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/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)4
-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/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)7
-rw-r--r--src/api/routes/guilds/#guild_id/regions.ts (renamed from api/src/routes/guilds/#guild_id/regions.ts)0
-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)3
-rw-r--r--src/api/routes/guilds/#guild_id/roles/index.ts (renamed from api/src/routes/guilds/#guild_id/roles/index.ts)20
-rw-r--r--src/api/routes/guilds/#guild_id/stickers.ts (renamed from api/src/routes/guilds/#guild_id/stickers.ts)17
-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)14
-rw-r--r--src/api/routes/guilds/#guild_id/webhooks.ts (renamed from api/src/routes/guilds/#guild_id/webhooks.ts)1
-rw-r--r--src/api/routes/guilds/#guild_id/welcome_screen.ts (renamed from api/src/routes/guilds/#guild_id/welcome_screen.ts)13
-rw-r--r--src/api/routes/guilds/#guild_id/widget.json.ts (renamed from api/src/routes/guilds/#guild_id/widget.json.ts)0
-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)7
-rw-r--r--src/api/routes/guilds/index.ts (renamed from api/src/routes/guilds/index.ts)16
-rw-r--r--src/api/routes/guilds/templates/index.ts (renamed from api/src/routes/guilds/templates/index.ts)9
-rw-r--r--src/api/routes/invites/index.ts (renamed from api/src/routes/invites/index.ts)0
-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)0
-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)0
-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)0
-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)7
-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/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)21
-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.ts (renamed from api/src/routes/users/@me/mfa/codes.ts)7
-rw-r--r--src/api/routes/users/@me/mfa/totp/disable.ts (renamed from api/src/routes/users/@me/mfa/totp/disable.ts)6
-rw-r--r--src/api/routes/users/@me/mfa/totp/enable.ts (renamed from api/src/routes/users/@me/mfa/totp/enable.ts)8
-rw-r--r--src/api/routes/users/@me/notes.ts (renamed from api/src/routes/users/@me/notes.ts)0
-rw-r--r--src/api/routes/users/@me/relationships.ts (renamed from api/src/routes/users/@me/relationships.ts)9
-rw-r--r--src/api/routes/users/@me/settings.ts (renamed from api/src/routes/users/@me/settings.ts)6
-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/AssetCacheItem.ts (renamed from api/src/util/entities/AssetCacheItem.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)0
-rw-r--r--src/api/util/handlers/Message.ts (renamed from api/src/util/handlers/Message.ts)3
-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)7
-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/ipAddress.ts (renamed from api/src/util/utility/ipAddress.ts)0
-rw-r--r--src/api/util/utility/passwordStrength.ts (renamed from api/src/util/utility/passwordStrength.ts)0
141 files changed, 61 insertions, 416 deletions
diff --git a/api/src/Server.ts b/src/api/Server.ts

index 136f9814..136f9814 100644 --- a/api/src/Server.ts +++ b/src/api/Server.ts
diff --git a/api/src/global.d.ts b/src/api/global.d.ts
index 7751af8f..7751af8f 100644 --- a/api/src/global.d.ts +++ b/src/api/global.d.ts
diff --git a/api/src/index.ts b/src/api/index.ts
index adc7649c..adc7649c 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 2d9ccf57..2d9ccf57 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 35db3c6f..35db3c6f 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 8a046e06..8a046e06 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 47180b62..47180b62 100644 --- a/api/src/middlewares/RateLimit.ts +++ b/src/api/middlewares/RateLimit.ts
diff --git a/api/src/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts
index 4fe631cb..c8ea57f6 100644 --- a/api/src/middlewares/TestClient.ts +++ b/src/api/middlewares/TestClient.ts
@@ -7,11 +7,13 @@ import { Config } from "@fosscord/util"; import { AssetCacheItem } from "../util/entities/AssetCacheItem" import { green } from "picocolors"; +const AssetsPath = path.join(__dirname, "..", "..", "..", "assets") + export default function TestClient(app: Application) { const agent = new ProxyAgent(); //build client page - let html = fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "index.html"), { encoding: "utf8" }); + let html = fs.readFileSync(path.join(AssetsPath, "index.html"), { encoding: "utf8" }); html = applyEnv(html); html = applyInlinePlugins(html); html = applyPlugins(html); @@ -19,7 +21,7 @@ export default function TestClient(app: Application) { //load asset cache let newAssetCache: Map<string, AssetCacheItem> = new Map<string, AssetCacheItem>(); - let assetCacheDir = path.join(__dirname, "..", "..", "assets", "cache"); + let assetCacheDir = path.join(AssetsPath, "cache"); if(process.env.ASSET_CACHE_DIR) assetCacheDir = process.env.ASSET_CACHE_DIR @@ -32,7 +34,7 @@ export default function TestClient(app: Application) { newAssetCache = new Map<string, AssetCacheItem>(Object.entries(JSON.parse(rawdata.toString()))); } - app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets"))); + app.use("/assets", express.static(path.join(AssetsPath))); app.get("/assets/:file", async (req: Request, res: Response) => { delete req.headers.host; let response: FetchResponse; @@ -77,7 +79,7 @@ export default function TestClient(app: Application) { if(!useTestClient) return res.send("Test client is disabled on this instance. Use a stand-alone client to connect this instance.") - res.send(fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "developers.html"), { encoding: "utf8" })); + res.send(fs.readFileSync(path.join(__dirname, "..", "..", "..", "assets", "developers.html"), { encoding: "utf8" })); }); app.get("*", (req: Request, res: Response) => { const { useTestClient } = Config.get().client; @@ -113,7 +115,7 @@ function applyEnv(html: string): string { function applyPlugins(html: string): string { // plugins - let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins")); + let files = fs.readdirSync(path.join(AssetsPath, "plugins")); let plugins = ""; files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; }); return html.replaceAll("<!-- plugin marker -->", plugins); @@ -121,7 +123,7 @@ function applyPlugins(html: string): string { function applyInlinePlugins(html: string): string{ // inline plugins - let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "inline-plugins")); + let files = fs.readdirSync(path.join(AssetsPath, "inline-plugins")); let plugins = ""; files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/inline-plugins/${x}'></script>\n\n`; }); return html.replaceAll("<!-- inline plugin marker -->", plugins); @@ -129,9 +131,9 @@ function applyInlinePlugins(html: string): string{ function applyPreloadPlugins(html: string): string{ //preload plugins - let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins")); + let files = fs.readdirSync(path.join(AssetsPath, "preload-plugins")); let plugins = ""; - files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "assets", "preload-plugins", x))}</script>\n`; }); + files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(AssetsPath, "preload-plugins", x))}</script>\n`; }); return html.replaceAll("<!-- preload plugin marker -->", plugins); } diff --git a/api/src/middlewares/Translation.ts b/src/api/middlewares/Translation.ts
index baabf221..64b03bf8 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 @@ -19,7 +19,7 @@ export async function initTranslation(router: Router) { fallbackLng: "en", ns, backend: { - loadPath: __dirname + "/../../locales/{{lng}}/{{ns}}.json" + loadPath: __dirname + "/../../../assets/locales/{{lng}}/{{ns}}.json" }, load: "all" }); 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..f7bcfebf 100644 --- a/api/src/routes/-/healthz.ts +++ b/src/api/routes/-/healthz.ts
diff --git a/api/src/routes/-/readyz.ts b/src/api/routes/-/readyz.ts
index f7bcfebf..f7bcfebf 100644 --- a/api/src/routes/-/readyz.ts +++ b/src/api/routes/-/readyz.ts
diff --git a/api/src/routes/applications/#id/bot/index.ts b/src/api/routes/applications/#id/bot/index.ts
index 5cae5215..5cae5215 100644 --- a/api/src/routes/applications/#id/bot/index.ts +++ b/src/api/routes/applications/#id/bot/index.ts
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/#id/index.ts b/src/api/routes/applications/#id/index.ts
index 0aced582..0aced582 100644 --- a/api/src/routes/applications/#id/index.ts +++ b/src/api/routes/applications/#id/index.ts
diff --git a/api/src/routes/applications/#id/skus.ts b/src/api/routes/applications/#id/skus.ts
index 5b667f36..5b667f36 100644 --- a/api/src/routes/applications/#id/skus.ts +++ b/src/api/routes/applications/#id/skus.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 033dcc51..033dcc51 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 daef6056..9fc5924d 100644 --- a/api/src/routes/auth/login.ts +++ b/src/api/routes/auth/login.ts
@@ -1,21 +1,12 @@ import { Request, Response, Router } from "express"; import { route } from "@fosscord/api"; import bcrypt from "bcrypt"; -import { Config, User, generateToken, adjustEmail, FieldErrors } from "@fosscord/util"; +import { Config, User, generateToken, adjustEmail, FieldErrors, LoginSchema } from "@fosscord/util"; import crypto from "crypto"; const router: Router = Router(); export default router; -export interface LoginSchema { - login: string; - password: string; - undelete?: boolean; - captcha_key?: string; - login_source?: string; - gift_code_sku_id?: string; -} - router.post("/", route({ body: "LoginSchema" }), async (req: Request, res: Response) => { const { login, password, captcha_key, undelete } = req.body as LoginSchema; const email = adjustEmail(login); diff --git a/api/src/routes/auth/mfa/totp.ts b/src/api/routes/auth/mfa/totp.ts
index 255cf889..421dbafa 100644 --- a/api/src/routes/auth/mfa/totp.ts +++ b/src/api/routes/auth/mfa/totp.ts
@@ -1,17 +1,10 @@ import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; -import { BackupCode, FieldErrors, generateToken, User } from "@fosscord/util"; +import { BackupCode, FieldErrors, generateToken, TotpSchema, User } from "@fosscord/util"; import { verifyToken } from "node-2fa"; import { HTTPError } from "lambert-server"; const router = Router(); -export interface TotpSchema { - code: string, - ticket: string, - gift_code_sku_id?: string | null, - login_source?: string | null, -} - router.post("/", route({ body: "TotpSchema" }), async (req: Request, res: Response) => { const { code, ticket, gift_code_sku_id, login_source } = req.body as TotpSchema; diff --git a/api/src/routes/auth/register.ts b/src/api/routes/auth/register.ts
index 2baef98e..09366a12 100644 --- a/api/src/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts
@@ -1,37 +1,11 @@ import { Request, Response, Router } from "express"; -import { Config, generateToken, Invite, FieldErrors, User, adjustEmail, trimSpecial } from "@fosscord/util"; +import { Config, generateToken, Invite, FieldErrors, User, adjustEmail, trimSpecial, RegisterSchema } from "@fosscord/util"; import { route, getIpAdress, IPAnalysis, isProxy } from "@fosscord/api"; import bcrypt from "bcrypt"; import { HTTPError } from "@fosscord/util"; const router: Router = Router(); -export interface RegisterSchema { - /** - * @minLength 2 - * @maxLength 32 - */ - username: string; - /** - * @minLength 1 - * @maxLength 72 - */ - password?: string; - consent: boolean; - /** - * @TJS-format email - */ - email?: string; - fingerprint?: string; - invite?: string; - /** - * @TJS-type string - */ - date_of_birth?: Date; // "2000-04-03" - gift_code_sku_id?: string; - captcha_key?: string; -} - router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Response) => { const body = req.body as RegisterSchema; const { register, security } = Config.get(); 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 68b52be6..bb8b868b 100644 --- a/api/src/routes/channels/#channel_id/index.ts +++ b/src/api/routes/channels/#channel_id/index.ts
@@ -6,7 +6,8 @@ import { ChannelUpdateEvent, emitEvent, Recipient, - handleFile + handleFile, + ChannelModifySchema } from "@fosscord/util"; import { Request, Response, Router } from "express"; import { route } from "@fosscord/api"; @@ -48,31 +49,6 @@ router.delete("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request res.send(channel); }); -export interface ChannelModifySchema { - /** - * @maxLength 100 - */ - name?: string; - type?: ChannelType; - topic?: string; - icon?: string | null; - bitrate?: number; - user_limit?: number; - rate_limit_per_user?: number; - position?: number; - permission_overwrites?: { - id: string; - type: ChannelPermissionOverwriteType; - allow: string; - deny: string; - }[]; - parent_id?: string; - id?: string; // is not used (only for guild create) - nsfw?: boolean; - rtc_region?: string; - default_auto_archive_duration?: number; -} - router.patch("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => { let payload = req.body as ChannelModifySchema; const { channel_id } = req.params; diff --git a/api/src/routes/channels/#channel_id/invites.ts b/src/api/routes/channels/#channel_id/invites.ts
index a53b1de4..b5c65c0d 100644 --- a/api/src/routes/channels/#channel_id/invites.ts +++ b/src/api/routes/channels/#channel_id/invites.ts
@@ -8,18 +8,6 @@ import { OrmUtils } from "@fosscord/util"; const router: Router = Router(); -export interface InviteCreateSchema { - target_user_id?: string; - target_type?: string; - validate?: string; // ? what is this - max_age?: number; - max_uses?: number; - temporary?: boolean; - unique?: boolean; - target_user?: string; - target_user_type?: number; -} - router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE", right: "CREATE_INVITES" }), async (req: Request, res: Response) => { const { user_id } = req; @@ -35,15 +23,12 @@ router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT const expires_at = new Date(req.body.max_age * 1000 + Date.now()); const invite = await OrmUtils.mergeDeep(new Invite(),{ - code: random(), - temporary: req.body.temporary, - uses: 0, + temporary: req.body.temporary || true, max_uses: req.body.max_uses, max_age: req.body.max_age, expires_at, - created_at: new Date(), guild_id, - channel_id: channel_id, + channel_id, inviter_id: user_id }).save(); //TODO: check this, removed toJSON call @@ -57,7 +42,6 @@ router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT }); 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({ where: { id: channel_id } }); 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 c1b8d20f..041f4d5e 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
@@ -5,15 +5,6 @@ import { OrmUtils } from "@fosscord/util"; const router = Router(); -// TODO: public read receipts & privacy scoping -// TODO: send read state event to all channel members -// TODO: advance-only notification cursor - -export interface MessageAcknowledgeSchema { - manual?: boolean; - mention_count?: number; -} - router.post("/", route({ body: "MessageAcknowledgeSchema" }), async (req: Request, res: Response) => { const { channel_id, message_id } = req.params; 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 b3b310d3..d7e27062 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
@@ -12,13 +12,13 @@ import { MessageDeleteEvent, MessageUpdateEvent, Snowflake, - uploadFile + uploadFile, + MessageCreateSchema } from "@fosscord/util"; import { Router, Response, Request } from "express"; import multer from "multer"; import { route } from "@fosscord/api"; import { handleMessage, postHandleMessage } from "@fosscord/api"; -import { MessageCreateSchema } from "../index"; import { HTTPError } from "@fosscord/util"; const router = Router(); 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 d0ab35bb..d0ab35bb 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
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 2e40f110..af44b522 100644 --- a/api/src/routes/channels/#channel_id/messages/bulk-delete.ts +++ b/src/api/routes/channels/#channel_id/messages/bulk-delete.ts
@@ -8,16 +8,12 @@ const router: Router = Router(); export default router; -export interface BulkDeleteSchema { - messages: string[]; -} - // should users be able to bulk delete messages or only bots? ANSWER: all users // should this request fail, if you provide messages older than 14 days/invalid ids? ANSWER: NO // 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.findOneByOrFail({ 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); diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index c2057422..9ab0d97d 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -5,7 +5,6 @@ import { ChannelType, Config, DmChannelDTO, - Embed, emitEvent, getPermission, getRights, @@ -13,7 +12,8 @@ import { MessageCreateEvent, Snowflake, uploadFile, - Member + Member, + MessageCreateSchema } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { handleMessage, postHandleMessage, route } from "@fosscord/api"; @@ -49,38 +49,6 @@ export function isTextChannel(type: ChannelType): boolean { } } -export interface MessageCreateSchema { - type?: number; - content?: string; - nonce?: string; - channel_id?: string; - tts?: boolean; - flags?: string; - embeds?: Embed[]; - embed?: Embed; - // TODO: ^ embed is deprecated in favor of embeds (https://discord.com/developers/docs/resources/channel#message-object) - allowed_mentions?: { - parse?: string[]; - roles?: string[]; - users?: string[]; - replied_user?: boolean; - }; - message_reference?: { - message_id: string; - channel_id: string; - guild_id?: string; - fail_if_not_exists?: boolean; - }; - payload_json?: string; - file?: any; - /** - TODO: we should create an interface for attachments - TODO: OpenWAAO<-->attachment-style metadata conversion - **/ - attachments?: any[]; - sticker_ids?: string[]; -} - // https://discord.com/developers/docs/resources/channel#create-message // get messages router.get("/", async (req: Request, res: Response) => { diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/src/api/routes/channels/#channel_id/permissions.ts
index 06a124bb..34052fe5 100644 --- a/api/src/routes/channels/#channel_id/permissions.ts +++ b/src/api/routes/channels/#channel_id/permissions.ts
@@ -1,6 +1,7 @@ import { Channel, ChannelPermissionOverwrite, + ChannelPermissionOverwriteSchema, ChannelPermissionOverwriteType, ChannelUpdateEvent, emitEvent, @@ -10,13 +11,9 @@ import { } from "@fosscord/util"; import { Router, Response, Request } from "express"; import { HTTPError } from "@fosscord/util"; - import { route } from "@fosscord/api"; -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 {} +const router: Router = Router(); router.put( "/:overwrite_id", diff --git a/api/src/routes/channels/#channel_id/pins.ts b/src/api/routes/channels/#channel_id/pins.ts
index 003638c5..003638c5 100644 --- a/api/src/routes/channels/#channel_id/pins.ts +++ b/src/api/routes/channels/#channel_id/pins.ts
diff --git a/api/src/routes/channels/#channel_id/purge.ts b/src/api/routes/channels/#channel_id/purge.ts
index 7ab4ad9a..1ef6e1d7 100644 --- a/api/src/routes/channels/#channel_id/purge.ts +++ b/src/api/routes/channels/#channel_id/purge.ts
@@ -1,4 +1,4 @@ -import { HTTPError } from "@fosscord/util"; +import { HTTPError, PurgeSchema } from "@fosscord/util"; import { route } from "@fosscord/api"; import { isTextChannel } from "./messages"; import { FindManyOptions, Between, Not } from "typeorm"; @@ -10,11 +10,6 @@ const router: Router = Router(); export default router; -export interface PurgeSchema { - before: string; - after: string; -} - /** TODO: apply the delete bit by bit to prevent client and database stress **/ diff --git a/api/src/routes/channels/#channel_id/recipients.ts b/src/api/routes/channels/#channel_id/recipients.ts
index 069212e2..069212e2 100644 --- a/api/src/routes/channels/#channel_id/recipients.ts +++ b/src/api/routes/channels/#channel_id/recipients.ts
diff --git a/api/src/routes/channels/#channel_id/typing.ts b/src/api/routes/channels/#channel_id/typing.ts
index 99460f6e..99460f6e 100644 --- a/api/src/routes/channels/#channel_id/typing.ts +++ b/src/api/routes/channels/#channel_id/typing.ts
diff --git a/api/src/routes/channels/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts
index 8f0e0a7f..b11c8eb9 100644 --- a/api/src/routes/channels/#channel_id/webhooks.ts +++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -6,14 +6,6 @@ import { isTextChannel } from "./messages/index"; import { DiscordApiErrors } from "@fosscord/util"; const router: Router = Router(); -// TODO: webhooks -export interface WebhookCreateSchema { - /** - * @maxLength 80 - */ - name: string; - avatar: string; -} //TODO: implement webhooks router.get("/", route({}), async (req: Request, res: Response) => { res.json([]); @@ -36,6 +28,7 @@ router.post("/", route({ body: "WebhookCreateSchema", permission: "MANAGE_WEBHOO if (name === "clyde") throw new HTTPError("Invalid name", 400); // TODO: save webhook in database and send response + res.json(new Webhook()); }); export default router; diff --git a/api/src/routes/discoverable-guilds.ts b/src/api/routes/discoverable-guilds.ts
index 35ecf28c..35ecf28c 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/src/api/routes/discoverable-guilds.ts
diff --git a/api/src/routes/discovery.ts b/src/api/routes/discovery.ts
index 30c418c6..30c418c6 100644 --- a/api/src/routes/discovery.ts +++ b/src/api/routes/discovery.ts
diff --git a/api/src/routes/downloads.ts b/src/api/routes/downloads.ts
index 44530353..44530353 100644 --- a/api/src/routes/downloads.ts +++ b/src/api/routes/downloads.ts
diff --git a/api/src/routes/experiments.ts b/src/api/routes/experiments.ts
index fcbd9271..fcbd9271 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 1099dc4a..1099dc4a 100644 --- a/api/src/routes/gifs/search.ts +++ b/src/api/routes/gifs/search.ts
diff --git a/api/src/routes/gifs/trending-gifs.ts b/src/api/routes/gifs/trending-gifs.ts
index 2b28d9d2..2b28d9d2 100644 --- a/api/src/routes/gifs/trending-gifs.ts +++ b/src/api/routes/gifs/trending-gifs.ts
diff --git a/api/src/routes/gifs/trending.ts b/src/api/routes/gifs/trending.ts
index 61eb76c4..61eb76c4 100644 --- a/api/src/routes/gifs/trending.ts +++ b/src/api/routes/gifs/trending.ts
diff --git a/api/src/routes/guild-recommendations.ts b/src/api/routes/guild-recommendations.ts
index bd0140d6..bd0140d6 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/src/api/routes/guild-recommendations.ts
diff --git a/api/src/routes/guilds/#guild_id/audit-logs.ts b/src/api/routes/guilds/#guild_id/audit-logs.ts
index 7b1d0062..b54835fc 100644 --- a/api/src/routes/guilds/#guild_id/audit-logs.ts +++ b/src/api/routes/guilds/#guild_id/audit-logs.ts
@@ -1,8 +1,5 @@ import { Router, Response, Request } from "express"; -import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util"; -import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; -import { ChannelModifySchema } from "../../channels/#channel_id"; const router = Router(); //TODO: implement audit logs diff --git a/api/src/routes/guilds/#guild_id/bans.ts b/src/api/routes/guilds/#guild_id/bans.ts
index 0743687d..3d405344 100644 --- a/api/src/routes/guilds/#guild_id/bans.ts +++ b/src/api/routes/guilds/#guild_id/bans.ts
@@ -1,31 +1,9 @@ import { Request, Response, Router } from "express"; -import { DiscordApiErrors, emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member } from "@fosscord/util"; +import { DiscordApiErrors, emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member, BanRegistrySchema, BanModeratorSchema } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { getIpAdress, route } from "@fosscord/api"; import { OrmUtils } from "@fosscord/util"; -export interface BanCreateSchema { - delete_message_days?: string; - reason?: string; -}; - -export interface BanRegistrySchema { - id: string; - user_id: string; - guild_id: string; - executor_id: string; - ip?: string; - reason?: string | undefined; -}; - -export interface BanModeratorSchema { - id: string; - user_id: string; - guild_id: string; - executor_id: string; - reason?: string | undefined; -}; - const router: Router = Router(); /* TODO: Deleting the secrets is just a temporary go-around. Views should be implemented for both safety and better handling. */ diff --git a/api/src/routes/guilds/#guild_id/channels.ts b/src/api/routes/guilds/#guild_id/channels.ts
index b952b474..8f2d3643 100644 --- a/api/src/routes/guilds/#guild_id/channels.ts +++ b/src/api/routes/guilds/#guild_id/channels.ts
@@ -1,8 +1,7 @@ import { Router, Response, Request } from "express"; -import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util"; +import { Channel, ChannelUpdateEvent, getPermission, emitEvent, ChannelModifySchema, ChannelReorderSchema } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; -import { ChannelModifySchema } from "../../channels/#channel_id"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { @@ -22,8 +21,6 @@ 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 }[]; - router.patch("/", route({ body: "ChannelReorderSchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => { // changes guild channel position const { guild_id } = req.params; diff --git a/api/src/routes/guilds/#guild_id/delete.ts b/src/api/routes/guilds/#guild_id/delete.ts
index e2624651..e2624651 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 53a44ec3..4bf4bdcd 100644 --- a/api/src/routes/guilds/#guild_id/emojis.ts +++ b/src/api/routes/guilds/#guild_id/emojis.ts
@@ -1,22 +1,10 @@ import { Router, Request, Response } from "express"; -import { Config, DiscordApiErrors, emitEvent, Emoji, GuildEmojisUpdateEvent, handleFile, Member, Snowflake, User } from "@fosscord/util"; +import { Config, DiscordApiErrors, emitEvent, Emoji, EmojiCreateSchema, EmojiModifySchema, GuildEmojisUpdateEvent, handleFile, Member, Snowflake, User } from "@fosscord/util"; import { route } from "@fosscord/api"; import { OrmUtils } from "@fosscord/util"; const router = Router(); -export interface EmojiCreateSchema { - name?: string; - image: string; - require_colons?: boolean | null; - roles?: string[]; -} - -export interface EmojiModifySchema { - name?: string; - roles?: string[]; -} - router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; diff --git a/api/src/routes/guilds/#guild_id/index.ts b/src/api/routes/guilds/#guild_id/index.ts
index abece88e..a9712c71 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/src/api/routes/guilds/#guild_id/index.ts
@@ -1,28 +1,11 @@ import { Request, Response, Router } from "express"; -import { DiscordApiErrors, emitEvent, getPermission, getRights, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util"; +import { DiscordApiErrors, emitEvent, getPermission, getRights, Guild, GuildUpdateEvent, GuildUpdateSchema, handleFile, Member } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; -import { GuildCreateSchema } from "../index"; import { OrmUtils } from "@fosscord/util"; const router = Router(); -export interface GuildUpdateSchema extends Omit<GuildCreateSchema, "channels" | "name"> { - name?: string; - banner?: string | null; - splash?: string | null; - description?: string; - features?: string[]; - verification_level?: number; - default_message_notifications?: number; - system_channel_flags?: number; - explicit_content_filter?: number; - public_updates_channel_id?: string; - afk_timeout?: number; - afk_channel_id?: string; - preferred_locale?: string; -} - router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; diff --git a/api/src/routes/guilds/#guild_id/integrations.ts b/src/api/routes/guilds/#guild_id/integrations.ts
index 19f68563..90650111 100644 --- a/api/src/routes/guilds/#guild_id/integrations.ts +++ b/src/api/routes/guilds/#guild_id/integrations.ts
@@ -2,7 +2,6 @@ import { Router, Response, Request } from "express"; import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; -import { ChannelModifySchema } from "../../channels/#channel_id"; const router = Router(); //TODO: implement integrations list 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/members/#member_id/index.ts b/src/api/routes/guilds/#guild_id/members/#member_id/index.ts
index 824e34a4..794369d8 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
@@ -1,15 +1,11 @@ import { Request, Response, Router } from "express"; -import { Member, getPermission, getRights, Role, GuildMemberUpdateEvent, emitEvent, Sticker, Emoji, Rights, Guild } from "@fosscord/util"; +import { Member, getPermission, getRights, Role, GuildMemberUpdateEvent, emitEvent, Sticker, Emoji, Rights, Guild, MemberChangeSchema } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; import { OrmUtils } from "@fosscord/util"; const router = Router(); -export interface MemberChangeSchema { - roles?: string[]; -} - router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id, member_id } = req.params; await Member.IsInGuildOrFail(req.user_id, guild_id); 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 4dfae8da..a6c71333 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
@@ -4,10 +4,6 @@ import { Request, Response, Router } from "express"; const router = Router(); -export interface MemberNickChangeSchema { - nick: string; -} - router.patch("/", route({ body: "MemberNickChangeSchema" }), async (req: Request, res: Response) => { let { guild_id, member_id } = req.params; let permissionString: PermissionResolvable = "MANAGE_NICKNAMES"; 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 2ed28bda..2ed28bda 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/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 01f18ce4..673f022f 100644 --- a/api/src/routes/guilds/#guild_id/prune.ts +++ b/src/api/routes/guilds/#guild_id/prune.ts
@@ -62,13 +62,6 @@ router.get("/", route({}), async (req: Request, res: Response) => { res.send({ pruned: members.length }); }); -export interface PruneSchema { - /** - * @min 0 - */ - days: number; -} - router.post("/", route({ permission: "KICK_MEMBERS", right: "KICK_BAN_MEMBERS" }), async (req: Request, res: Response) => { const days = parseInt(req.body.days); diff --git a/api/src/routes/guilds/#guild_id/regions.ts b/src/api/routes/guilds/#guild_id/regions.ts
index 308d5ee5..308d5ee5 100644 --- a/api/src/routes/guilds/#guild_id/regions.ts +++ b/src/api/routes/guilds/#guild_id/regions.ts
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 0482b9ca..d4422a9c 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
@@ -1,8 +1,7 @@ import { Router, Request, Response } from "express"; -import { Role, Member, GuildRoleUpdateEvent, GuildRoleDeleteEvent, emitEvent, handleFile } from "@fosscord/util"; +import { Role, Member, GuildRoleUpdateEvent, GuildRoleDeleteEvent, emitEvent, handleFile, RoleModifySchema } from "@fosscord/util"; import { route } from "@fosscord/api"; import { HTTPError } from "@fosscord/util"; -import { RoleModifySchema } from "../"; import { OrmUtils } from "@fosscord/util"; const router = Router(); diff --git a/api/src/routes/guilds/#guild_id/roles/index.ts b/src/api/routes/guilds/#guild_id/roles/index.ts
index 6fbb8702..17f0b5e9 100644 --- a/api/src/routes/guilds/#guild_id/roles/index.ts +++ b/src/api/routes/guilds/#guild_id/roles/index.ts
@@ -9,7 +9,9 @@ import { emitEvent, Config, DiscordApiErrors, - handleFile + handleFile, + RoleModifySchema, + RolePositionUpdateSchema } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; @@ -17,22 +19,6 @@ import { OrmUtils } from "@fosscord/util"; const router: Router = Router(); -export interface RoleModifySchema { - name?: string; - permissions?: string; - color?: number; - hoist?: boolean; // whether the role should be displayed separately in the sidebar - mentionable?: boolean; // whether the role should be mentionable - position?: number; - icon?: string; - unicode_emoji?: string; -} - -export type RolePositionUpdateSchema = { - id: string; - position: number; -}[]; - router.get("/", route({}), async (req: Request, res: Response) => { const guild_id = req.params.guild_id; diff --git a/api/src/routes/guilds/#guild_id/stickers.ts b/src/api/routes/guilds/#guild_id/stickers.ts
index 157ccff4..71c9dfcd 100644 --- a/api/src/routes/guilds/#guild_id/stickers.ts +++ b/src/api/routes/guilds/#guild_id/stickers.ts
@@ -3,6 +3,7 @@ import { GuildStickersUpdateEvent, handleFile, Member, + ModifyGuildStickerSchema, Snowflake, Sticker, StickerFormatType, @@ -83,22 +84,6 @@ router.get("/:sticker_id", route({}), async (req: Request, res: Response) => { res.json(await Sticker.findOneOrFail({ where: { guild_id, id: sticker_id } })); }); -export interface ModifyGuildStickerSchema { - /** - * @minLength 2 - * @maxLength 30 - */ - name: string; - /** - * @maxLength 100 - */ - description?: string; - /** - * @maxLength 200 - */ - tags: string; -} - router.patch( "/:sticker_id", route({ body: "ModifyGuildStickerSchema", permission: "MANAGE_EMOJIS_AND_STICKERS" }), diff --git a/api/src/routes/guilds/#guild_id/templates.ts b/src/api/routes/guilds/#guild_id/templates.ts
index 3d14de41..9c79692d 100644 --- a/api/src/routes/guilds/#guild_id/templates.ts +++ b/src/api/routes/guilds/#guild_id/templates.ts
@@ -24,16 +24,6 @@ const TemplateGuildProjection: (keyof Guild)[] = [ "icon" ]; -export interface TemplateCreateSchema { - name: string; - description?: string; -} - -export interface TemplateModifySchema { - name: string; - description?: string; -} - router.get("/", route({}), async (req: Request, res: Response) => { const { guild_id } = req.params; diff --git a/api/src/routes/guilds/#guild_id/vanity-url.ts b/src/api/routes/guilds/#guild_id/vanity-url.ts
index ac46e18a..ff92ce8d 100644 --- a/api/src/routes/guilds/#guild_id/vanity-url.ts +++ b/src/api/routes/guilds/#guild_id/vanity-url.ts
@@ -1,4 +1,4 @@ -import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial } from "@fosscord/util"; +import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial, VanityUrlSchema } from "@fosscord/util"; import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; import { HTTPError } from "@fosscord/util"; @@ -25,14 +25,6 @@ router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: } }); -export interface VanityUrlSchema { - /** - * @minLength 1 - * @maxLength 20 - */ - code?: string; -} - router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => { const { guild_id } = req.params; const body = req.body as VanityUrlSchema; 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 32d1aadf..28a9e8c1 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
@@ -1,21 +1,9 @@ -import { Channel, ChannelType, DiscordApiErrors, emitEvent, getPermission, VoiceState, VoiceStateUpdateEvent } from "@fosscord/util"; +import { Channel, ChannelType, DiscordApiErrors, emitEvent, getPermission, VoiceState, VoiceStateUpdateEvent, VoiceStateUpdateSchema } from "@fosscord/util"; import { route } from "@fosscord/api"; import { Request, Response, Router } from "express"; import { OrmUtils } from "@fosscord/util"; const router = Router(); -//TODO need more testing when community guild and voice stage channel are working - -export interface VoiceStateUpdateSchema { - channel_id: string; - guild_id?: string; - suppress?: boolean; - request_to_speak_timestamp?: Date; - self_mute?: boolean; - self_deaf?: boolean; - self_video?: boolean; -} - router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request, res: Response) => { const body = req.body as VoiceStateUpdateSchema; let { guild_id, user_id } = req.params; diff --git a/api/src/routes/guilds/#guild_id/webhooks.ts b/src/api/routes/guilds/#guild_id/webhooks.ts
index 7f5b9592..c8c1eb5c 100644 --- a/api/src/routes/guilds/#guild_id/webhooks.ts +++ b/src/api/routes/guilds/#guild_id/webhooks.ts
@@ -2,7 +2,6 @@ import { Router, Response, Request } from "express"; import { Channel, ChannelUpdateEvent, getPermission, emitEvent } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; -import { ChannelModifySchema } from "../../channels/#channel_id"; const router = Router(); //TODO: implement webhooks diff --git a/api/src/routes/guilds/#guild_id/welcome_screen.ts b/src/api/routes/guilds/#guild_id/welcome_screen.ts
index 4093ec1d..d08300ba 100644 --- a/api/src/routes/guilds/#guild_id/welcome_screen.ts +++ b/src/api/routes/guilds/#guild_id/welcome_screen.ts
@@ -1,21 +1,10 @@ import { Request, Response, Router } from "express"; -import { Guild, getPermission, Snowflake, Member } from "@fosscord/util"; +import { Guild, getPermission, Snowflake, Member, GuildUpdateWelcomeScreenSchema } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; const router: Router = Router(); -export interface GuildUpdateWelcomeScreenSchema { - welcome_channels?: { - channel_id: string; - description: string; - emoji_id?: string; - emoji_name: string; - }[]; - enabled?: boolean; - description?: string; -} - router.get("/", route({}), async (req: Request, res: Response) => { const guild_id = req.params.guild_id; diff --git a/api/src/routes/guilds/#guild_id/widget.json.ts b/src/api/routes/guilds/#guild_id/widget.json.ts
index 37739418..37739418 100644 --- a/api/src/routes/guilds/#guild_id/widget.json.ts +++ b/src/api/routes/guilds/#guild_id/widget.json.ts
diff --git a/api/src/routes/guilds/#guild_id/widget.png.ts b/src/api/routes/guilds/#guild_id/widget.png.ts
index ec0ac85c..a61d938d 100644 --- a/api/src/routes/guilds/#guild_id/widget.png.ts +++ b/src/api/routes/guilds/#guild_id/widget.png.ts
@@ -34,7 +34,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { const sizeOf = require("image-size"); // TODO: Widget style templates need Fosscord branding - const source = path.join(__dirname, "..", "..", "..", "..", "assets", "widget", `${style}.png`); + const source = path.join(__dirname, "..", "..", "..", "..", "..", "assets", "widget", `${style}.png`); if (!fs.existsSync(source)) { throw new HTTPError("Widget template does not exist.", 400); } diff --git a/api/src/routes/guilds/#guild_id/widget.ts b/src/api/routes/guilds/#guild_id/widget.ts
index 103f84a3..dbb4cc0c 100644 --- a/api/src/routes/guilds/#guild_id/widget.ts +++ b/src/api/routes/guilds/#guild_id/widget.ts
@@ -1,12 +1,7 @@ import { Request, Response, Router } from "express"; -import { Guild } from "@fosscord/util"; +import { Guild, WidgetModifySchema } from "@fosscord/util"; import { route } from "@fosscord/api"; -export interface WidgetModifySchema { - enabled: boolean; // whether the widget is enabled - channel_id: string; // the widget channel id -} - const router: Router = Router(); // https://discord.com/developers/docs/resources/guild#get-guild-widget-settings diff --git a/api/src/routes/guilds/index.ts b/src/api/routes/guilds/index.ts
index 64b9454b..e4d66192 100644 --- a/api/src/routes/guilds/index.ts +++ b/src/api/routes/guilds/index.ts
@@ -1,23 +1,9 @@ import { Router, Request, Response } from "express"; -import { Role, Guild, Snowflake, Config, getRights, Member, Channel, DiscordApiErrors, handleFile } from "@fosscord/util"; +import { Role, Guild, Snowflake, Config, getRights, Member, Channel, DiscordApiErrors, handleFile, GuildCreateSchema } from "@fosscord/util"; import { route } from "@fosscord/api"; -import { ChannelModifySchema } from "../channels/#channel_id"; const router: Router = Router(); -export interface GuildCreateSchema { - /** - * @maxLength 100 - */ - name: string; - region?: string; - icon?: string | null; - channels?: ChannelModifySchema[]; - guild_template_code?: string; - system_channel_id?: string; - rules_channel_id?: string; -} - //TODO: create default channel router.post("/", route({ body: "GuildCreateSchema", right: "CREATE_GUILDS" }), async (req: Request, res: Response) => { diff --git a/api/src/routes/guilds/templates/index.ts b/src/api/routes/guilds/templates/index.ts
index bac4eb8a..3a0de9e8 100644 --- a/api/src/routes/guilds/templates/index.ts +++ b/src/api/routes/guilds/templates/index.ts
@@ -1,15 +1,8 @@ import { Request, Response, Router } from "express"; -import { Template, Guild, Role, Snowflake, Config, User, Member } from "@fosscord/util"; +import { Template, Guild, Role, Snowflake, Config, User, Member, DiscordApiErrors, OrmUtils, GuildTemplateCreateSchema } from "@fosscord/util"; import { route } from "@fosscord/api"; -import { DiscordApiErrors } from "@fosscord/util"; import fetch from "node-fetch"; const router: Router = Router(); -import { OrmUtils } from "@fosscord/util"; - -export interface GuildTemplateCreateSchema { - name: string; - avatar?: string | null; -} router.get("/:code", route({}), async (req: Request, res: Response) => { const { allowDiscordTemplates, allowRaws, enabled } = Config.get().templates; diff --git a/api/src/routes/invites/index.ts b/src/api/routes/invites/index.ts
index 1b434505..1b434505 100644 --- a/api/src/routes/invites/index.ts +++ b/src/api/routes/invites/index.ts
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 b484a7a1..b484a7a1 100644 --- a/api/src/routes/stickers/#sticker_id/index.ts +++ b/src/api/routes/stickers/#sticker_id/index.ts
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 723a5160..723a5160 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 a24e94c1..a24e94c1 100644 --- a/api/src/routes/updates.ts +++ b/src/api/routes/updates.ts
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 7a995a8c..7a995a8c 100644 --- a/api/src/routes/users/#id/profile.ts +++ b/src/api/routes/users/#id/profile.ts
diff --git a/api/src/routes/users/#id/relationships.ts b/src/api/routes/users/#id/relationships.ts
index 61655c25..61655c25 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..ad483529 100644 --- a/api/src/routes/users/@me/channels.ts +++ b/src/api/routes/users/@me/channels.ts
@@ -1,5 +1,5 @@ import { Request, Response, Router } from "express"; -import { Recipient, DmChannelDTO, Channel } from "@fosscord/util"; +import { Recipient, DmChannelDTO, Channel, DmChannelCreateSchema } from "@fosscord/util"; import { route } from "@fosscord/api"; const router: Router = Router(); @@ -12,11 +12,6 @@ router.get("/", route({}), async (req: Request, res: Response) => { res.json(await Promise.all(recipients.map((r) => DmChannelDTO.from(r.channel, [req.user_id])))); }); -export interface DmChannelCreateSchema { - name?: string; - recipients: string[]; -} - router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => { const body = req.body as DmChannelCreateSchema; res.json(await Channel.createDMChannel(body.recipients, req.user_id, body.name)); 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 1d81c2b9..1d81c2b9 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 4d4fccd4..4d4fccd4 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/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 4cf96a8d..7d095451 100644 --- a/api/src/routes/users/@me/index.ts +++ b/src/api/routes/users/@me/index.ts
@@ -1,30 +1,11 @@ import { Router, Request, Response } from "express"; -import { User, PrivateUserProjection, emitEvent, UserUpdateEvent, handleFile, FieldErrors } from "@fosscord/util"; +import { User, PrivateUserProjection, emitEvent, UserUpdateEvent, handleFile, FieldErrors, UserModifySchema } from "@fosscord/util"; import { route } from "@fosscord/api"; import bcrypt from "bcrypt"; import { OrmUtils, generateToken } from "@fosscord/util"; const router: Router = Router(); -export interface UserModifySchema { - /** - * @minLength 1 - * @maxLength 100 - */ - username?: string; - discriminator?: string; - avatar?: string | null; - /** - * @maxLength 1024 - */ - bio?: string; - accent_color?: number; - banner?: string | null; - password?: string; - new_password?: string; - code?: string; -} - router.get("/", route({}), async (req: Request, res: Response) => { res.json(await User.findOne({ select: PrivateUserProjection, where: { id: req.user_id } })); }); 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.ts b/src/api/routes/users/@me/mfa/codes.ts
index 75e3e964..4224a1c0 100644 --- a/api/src/routes/users/@me/mfa/codes.ts +++ b/src/api/routes/users/@me/mfa/codes.ts
@@ -1,15 +1,10 @@ import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; -import { BackupCode, Config, FieldErrors, generateMfaBackupCodes, User } from "@fosscord/util"; +import { BackupCode, Config, FieldErrors, generateMfaBackupCodes, MfaCodesSchema, User } from "@fosscord/util"; import bcrypt from "bcrypt"; const router = Router(); -export interface MfaCodesSchema { - password: string; - regenerate?: boolean; -} - // TODO: This route is replaced with users/@me/mfa/codes-verification in newer clients router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Response) => { diff --git a/api/src/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts
index 2d385fda..2fe9355c 100644 --- a/api/src/routes/users/@me/mfa/totp/disable.ts +++ b/src/api/routes/users/@me/mfa/totp/disable.ts
@@ -2,14 +2,10 @@ import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; import { verifyToken } from 'node-2fa'; import { HTTPError } from "lambert-server"; -import { User, generateToken, BackupCode } from "@fosscord/util"; +import { User, generateToken, BackupCode, TotpDisableSchema } from "@fosscord/util"; const router = Router(); -export interface TotpDisableSchema { - code: string; -} - router.post("/", route({ body: "TotpDisableSchema" }), async (req: Request, res: Response) => { const body = req.body as TotpDisableSchema; diff --git a/api/src/routes/users/@me/mfa/totp/enable.ts b/src/api/routes/users/@me/mfa/totp/enable.ts
index 87f36d55..ac668d1d 100644 --- a/api/src/routes/users/@me/mfa/totp/enable.ts +++ b/src/api/routes/users/@me/mfa/totp/enable.ts
@@ -1,5 +1,5 @@ import { Router, Request, Response } from "express"; -import { User, generateToken, BackupCode, generateMfaBackupCodes, Config } from "@fosscord/util"; +import { User, generateToken, BackupCode, generateMfaBackupCodes, Config, TotpEnableSchema } from "@fosscord/util"; import { route } from "@fosscord/api"; import bcrypt from "bcrypt"; import { HTTPError } from "lambert-server"; @@ -7,12 +7,6 @@ import { verifyToken } from 'node-2fa'; const router = Router(); -export interface TotpEnableSchema { - password: string; - code?: string; - secret?: string; -} - router.post("/", route({ body: "TotpEnableSchema" }), async (req: Request, res: Response) => { const body = req.body as TotpEnableSchema; diff --git a/api/src/routes/users/@me/notes.ts b/src/api/routes/users/@me/notes.ts
index f938f088..f938f088 100644 --- a/api/src/routes/users/@me/notes.ts +++ b/src/api/routes/users/@me/notes.ts
diff --git a/api/src/routes/users/@me/relationships.ts b/src/api/routes/users/@me/relationships.ts
index 6e22f4f3..f7464b99 100644 --- a/api/src/routes/users/@me/relationships.ts +++ b/src/api/routes/users/@me/relationships.ts
@@ -38,10 +38,6 @@ router.get("/", route({}), async (req: Request, res: Response) => { return res.json(related_users); }); -export interface RelationshipPutSchema { - type?: RelationshipType; -} - router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request, res: Response) => { return await updateRelationship( req, @@ -51,11 +47,6 @@ router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request ); }); -export interface RelationshipPostSchema { - discriminator: string; - username: string; -} - router.post("/", route({ body: "RelationshipPostSchema" }), async (req: Request, res: Response) => { return await updateRelationship( req, diff --git a/api/src/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts
index 70f8a218..7578d36e 100644 --- a/api/src/routes/users/@me/settings.ts +++ b/src/api/routes/users/@me/settings.ts
@@ -4,14 +4,12 @@ import { route } from "@fosscord/api"; const router = Router(); -export interface UserSettingsSchema extends Partial<UserSettings> {} - router.patch("/", route({ body: "UserSettingsSchema" }), async (req: Request, res: Response) => { 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({ where: { id: req.user_id, bot: false } }); - user.settings = { ...user.settings, ...body }; + const user = await User.findOneOrFail({ where: { id: req.user_id, bot: false }, relations: ["settings"] }); + user.settings = { ...user.settings, ...body } as UserSettings; await user.save(); res.sendStatus(204); 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 9ba198e7..9ba198e7 100644 --- a/api/src/start.ts +++ b/src/api/start.ts
diff --git a/api/src/util/entities/AssetCacheItem.ts b/src/api/util/entities/AssetCacheItem.ts
index 160dece6..160dece6 100644 --- a/api/src/util/entities/AssetCacheItem.ts +++ b/src/api/util/entities/AssetCacheItem.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 7c337270..7c337270 100644 --- a/api/src/util/handlers/Instance.ts +++ b/src/api/util/handlers/Instance.ts
diff --git a/api/src/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index 0f584c56..ff5ece75 100644 --- a/api/src/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -21,12 +21,13 @@ import { Webhook, Attachment, Config, + MessageCreateSchema, } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import fetch from "node-fetch"; import cheerio from "cheerio"; -import { MessageCreateSchema } from "../../routes/channels/#channel_id/messages"; import { OrmUtils } from "@fosscord/util"; + const allow_empty = false; // TODO: check webhook, application, system author, stickers // TODO: embed gifs/videos/images 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 eaf7dc91..71e14955 100644 --- a/api/src/util/handlers/route.ts +++ b/src/api/util/handlers/route.ts
@@ -19,7 +19,7 @@ import Ajv from "ajv"; import { AnyValidateFunction } from "ajv/dist/core"; import addFormats from "ajv-formats"; -const SchemaPath = path.join(__dirname, "..", "..", "..", "assets", "schemas.json"); +const SchemaPath = path.join(__dirname, "..", "..", "..","..", "assets", "schemas.json"); const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" })); export const ajv = new Ajv({ @@ -117,6 +117,11 @@ export function route(opts: RouteOptions) { const valid = validate(normalizeBody(req.body)); if (!valid) { const fields: Record<string, { code?: string; message: string }> = {}; + if(process.env.LOG_INVALID_BODY) { + console.log(`Got invalid request: ${req.method} ${req.originalUrl}`) + console.log(req.body) + validate.errors?.forEach(x => console.log(x.params)) + } validate.errors?.forEach((x) => (fields[x.instancePath.slice(1)] = { code: x.keyword, message: x.message || "" })); throw FieldErrors(fields); } diff --git a/api/src/util/index.ts b/src/api/util/index.ts
index b3c7559f..b3c7559f 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/ipAddress.ts b/src/api/util/utility/ipAddress.ts
index 8d986b26..8d986b26 100644 --- a/api/src/util/utility/ipAddress.ts +++ b/src/api/util/utility/ipAddress.ts
diff --git a/api/src/util/utility/passwordStrength.ts b/src/api/util/utility/passwordStrength.ts
index 8eca63b8..8eca63b8 100644 --- a/api/src/util/utility/passwordStrength.ts +++ b/src/api/util/utility/passwordStrength.ts