diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-02-18 10:47:18 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-02-18 10:47:18 +1100 |
commit | 688b33960b2943265a3bee64e34f6626eec6f1ea (patch) | |
tree | 534de0392eecb287bea87fe46f1dd5c993a9655b /api | |
parent | added a absolutely terrible background image and name text to login/register ... (diff) | |
parent | Merge pull request #608 from Featyre/master (diff) | |
download | server-688b33960b2943265a3bee64e34f6626eec6f1ea.tar.xz |
Merge branch 'master' into slowcord
Diffstat (limited to 'api')
-rw-r--r-- | api/assets/fosscord-login.css | 1 | ||||
-rw-r--r-- | api/client_test/developers.html | 42 | ||||
-rw-r--r-- | api/package-lock.json | 48 | ||||
-rw-r--r-- | api/src/middlewares/TestClient.ts | 9 | ||||
-rw-r--r-- | api/src/routes/applications/detectable.ts | 2 | ||||
-rw-r--r-- | api/src/routes/applications/index.ts | 11 | ||||
-rw-r--r-- | api/src/routes/discoverable-guilds.ts | 26 | ||||
-rw-r--r-- | api/src/routes/discovery.ts | 12 | ||||
-rw-r--r-- | api/src/routes/experiments.ts | 2 | ||||
-rw-r--r-- | api/src/routes/guild-recommendations.ts | 13 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/discovery-requirements.ts | 39 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/index.ts | 2 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 21 | ||||
-rw-r--r-- | api/src/routes/partners/#guild_id/requirements.ts | 40 | ||||
-rw-r--r-- | api/src/routes/teams.ts | 11 | ||||
-rw-r--r-- | api/src/routes/users/#id/profile.ts | 17 | ||||
-rw-r--r-- | api/src/routes/users/#id/relationships.ts | 41 | ||||
-rw-r--r-- | api/src/routes/users/@me/guilds.ts | 8 | ||||
-rw-r--r-- | api/src/routes/users/@me/index.ts | 7 | ||||
-rw-r--r-- | api/src/util/handlers/route.ts | 2 |
20 files changed, 315 insertions, 39 deletions
diff --git a/api/assets/fosscord-login.css b/api/assets/fosscord-login.css index 83a119b7..ca0af064 100644 --- a/api/assets/fosscord-login.css +++ b/api/assets/fosscord-login.css @@ -26,7 +26,6 @@ h3.title-jXR8lp.marginBottom8-AtZOdT.base-1x0h_U.size24-RIRrxO::after { width: 130px; height: 23px; background-size: contain; - border-radius: 50%; } /* replace TOS text */ diff --git a/api/client_test/developers.html b/api/client_test/developers.html new file mode 100644 index 00000000..2a4402d7 --- /dev/null +++ b/api/client_test/developers.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<html class="theme-dark" data-theme="dark"> + <head> + <meta charset="utf-8" /> + <meta content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no" name="viewport" /> + + <link rel="stylesheet" href="/assets/532.03aaeef88460fae60534.css" integrity="" /> + <link rel="icon" href="/assets/07dca80a102d4149e9736d4b162cff6f.ico" /> + <title>Discord Test Client Developer Portal</title> + <meta charset="utf-8" data-react-helmet="true" /> + </head> + + <body> + <div id="app-mount"></div> + <script> + window.GLOBAL_ENV = { + API_VERSION: 9, + API_ENDPOINT: "/api", + WEBAPP_ENDPOINT: "", + CDN_HOST: `${location.hostname}:3003`, + + BRAINTREE_KEY: "production_5st77rrc_49pp2rp4phym7387", + STRIPE_KEY: "pk_live_CUQtlpQUF0vufWpnpUmQvcdi", + MARKETING_ENDPOINT: "//discord.com", + RELEASE_CHANNEL: "stable", + ALGOLIA_KEY: "aca0d7082e4e63af5ba5917d5e96bed0" + }; + GLOBAL_ENV.MEDIA_PROXY_ENDPOINT = location.protocol + "//" + GLOBAL_ENV.CDN_HOST; + const localStorage = window.localStorage; + // TODO: remote auth + // window.GLOBAL_ENV.REMOTE_AUTH_ENDPOINT = window.GLOBAL_ENV.GATEWAY_ENDPOINT.replace(/wss?:/, ""); + localStorage.setItem("gatewayURL", window.GLOBAL_ENV.GATEWAY_ENDPOINT); + localStorage.setItem( + "DeveloperOptionsStore", + `{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}` + ); + </script> + <script src="/assets/41fde19fdf180f3d4315.js" integrity=""></script> + <script src="/assets/7b04a3ab10e05dd9054e.js" integrity=""></script> + <script src="/assets/d1f811da193e5648048b.js" integrity=""></script> + </body> +</html> diff --git a/api/package-lock.json b/api/package-lock.json index 21afe02c..a7c29a79 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -34,7 +34,6 @@ "missing-native-js-functions": "^1.2.18", "morgan": "^1.10.0", "multer": "^1.4.2", - "node": ">=15.0", "node-fetch": "^3.1.1", "patch-package": "^6.4.7", "picocolors": "^1.0.0", @@ -9605,9 +9604,9 @@ } }, "node_modules/acorn": { - "version": "8.5.0", - "integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==", - "dev": true, + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", + "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", "bin": { "acorn": "bin/acorn" }, @@ -15193,9 +15192,13 @@ } }, "node_modules/vm2": { - "version": "3.9.5", - "resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.5.tgz", - "integrity": "sha512-LuCAHZN75H9tdrAiLFf030oW7nJV5xwNMuk1ymOZwopmuK3d2H4L1Kv4+GFHgarKiLfXXLFU+7LDABHnwOkWng==", + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.7.tgz", + "integrity": "sha512-g/GZ7V0Mlmch3eDVOATvAXr1GsJNg6kQ5PjvYy3HbJMCRn5slNbo/u73Uy7r5yUej1cRa3ZjtoVwcWSQuQ/fow==", + "dependencies": { + "acorn": "^8.7.0", + "acorn-walk": "^8.2.0" + }, "bin": { "vm2": "bin/vm2" }, @@ -15203,6 +15206,14 @@ "node": ">=6.0" } }, + "node_modules/vm2/node_modules/acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/w3c-hr-time": { "version": "1.0.2", "integrity": "sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==", @@ -22768,9 +22779,9 @@ } }, "acorn": { - "version": "8.5.0", - "integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==", - "dev": true + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", + "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==" }, "acorn-globals": { "version": "6.0.0", @@ -26895,9 +26906,20 @@ "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, "vm2": { - "version": "3.9.5", - "resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.5.tgz", - "integrity": "sha512-LuCAHZN75H9tdrAiLFf030oW7nJV5xwNMuk1ymOZwopmuK3d2H4L1Kv4+GFHgarKiLfXXLFU+7LDABHnwOkWng==" + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/vm2/-/vm2-3.9.7.tgz", + "integrity": "sha512-g/GZ7V0Mlmch3eDVOATvAXr1GsJNg6kQ5PjvYy3HbJMCRn5slNbo/u73Uy7r5yUej1cRa3ZjtoVwcWSQuQ/fow==", + "requires": { + "acorn": "^8.7.0", + "acorn-walk": "^8.2.0" + }, + "dependencies": { + "acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==" + } + } }, "w3c-hr-time": { "version": "1.0.2", diff --git a/api/src/middlewares/TestClient.ts b/api/src/middlewares/TestClient.ts index 5c0b081b..ecf87681 100644 --- a/api/src/middlewares/TestClient.ts +++ b/api/src/middlewares/TestClient.ts @@ -83,6 +83,15 @@ export default function TestClient(app: Application) { return res.send(buffer); }); + app.get("/developers*", (req: Request, res: Response) => { + const { useTestClient } = Config.get().client; + res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24); + res.set("content-type", "text/html"); + + 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" })); + }); app.get("*", (req: Request, res: Response) => { const { useTestClient } = Config.get().client; res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24); diff --git a/api/src/routes/applications/detectable.ts b/api/src/routes/applications/detectable.ts index 411e95bf..28ce42da 100644 --- a/api/src/routes/applications/detectable.ts +++ b/api/src/routes/applications/detectable.ts @@ -5,7 +5,7 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { //TODO - res.json([]).status(200); + res.send([]).status(200); }); export default router; diff --git a/api/src/routes/applications/index.ts b/api/src/routes/applications/index.ts new file mode 100644 index 00000000..28ce42da --- /dev/null +++ b/api/src/routes/applications/index.ts @@ -0,0 +1,11 @@ +import { Request, Response, Router } from "express"; +import { route } from "@fosscord/api"; + +const router: Router = Router(); + +router.get("/", route({}), async (req: Request, res: Response) => { + //TODO + res.send([]).status(200); +}); + +export default router; diff --git a/api/src/routes/discoverable-guilds.ts b/api/src/routes/discoverable-guilds.ts index 1cf56f84..0aa2baa9 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/api/src/routes/discoverable-guilds.ts @@ -6,15 +6,29 @@ import { route } from "@fosscord/api"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { - const { limit } = req.params; - var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery; + const { offset, limit, categories } = req.query; + var showAllGuilds = Config.get().guild.discovery.showAllGuilds; + var configLimit = Config.get().guild.discovery.limit; // ! this only works using SQL querys // TODO: implement this with default typeorm query // const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) }); - const guilds = showAllGuilds - ? await Guild.find({ take: Math.abs(Number(limit || 20)) }) - : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 20)) }); - res.send({ guilds: guilds }); + let guilds; + 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)) }); + } 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)) + }); + } + + const total = guilds ? guilds.length : undefined; + + res.send({ total: total, guilds: guilds, offset: Number(offset || Config.get().guild.discovery.offset), limit: Number(limit || configLimit) }); }); export default router; diff --git a/api/src/routes/discovery.ts b/api/src/routes/discovery.ts index bc495d42..1991400e 100644 --- a/api/src/routes/discovery.ts +++ b/api/src/routes/discovery.ts @@ -1,12 +1,18 @@ +import { Categories } from "@fosscord/util"; import { Router, Response, Request } from "express"; import { route } from "@fosscord/api"; const router = Router(); -router.get("/categories", route({}), (req: Request, res: Response) => { +router.get("/categories", route({}), async (req: Request, res: Response) => { // TODO: - //const { locale, primary_only } = req.query; - res.json([]).status(200); + // Get locale instead + + const { locale, primary_only } = req.query; + + const out = primary_only ? await Categories.find() : await Categories.find({ where: `"is_primary" = "true"` }); + + res.send(out); }); export default router; diff --git a/api/src/routes/experiments.ts b/api/src/routes/experiments.ts index 966ed99c..7be86fb8 100644 --- a/api/src/routes/experiments.ts +++ b/api/src/routes/experiments.ts @@ -5,7 +5,7 @@ const router = Router(); router.get("/", route({}), (req: Request, res: Response) => { // TODO: - res.send({ fingerprint: "", assignments: [] }); + res.send({ fingerprint: "", assignments: [], guild_experiments:[] }); }); export default router; diff --git a/api/src/routes/guild-recommendations.ts b/api/src/routes/guild-recommendations.ts index 503b19b7..1432f39c 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/api/src/routes/guild-recommendations.ts @@ -6,15 +6,18 @@ import { route } from "@fosscord/api"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { - const { limit, personalization_disabled } = req.params; - var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery; + const { limit, personalization_disabled } = req.query; + var showAllGuilds = Config.get().guild.discovery.showAllGuilds; // ! this only works using SQL querys // TODO: implement this with default typeorm query // const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) }); + + const genLoadId = (size: Number) => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join(''); + const guilds = showAllGuilds - ? await Guild.find({ take: Math.abs(Number(limit || 20)) }) - : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 100)) }); - res.send({ recommended_guilds: guilds }); + ? 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); }); export default router; diff --git a/api/src/routes/guilds/#guild_id/discovery-requirements.ts b/api/src/routes/guilds/#guild_id/discovery-requirements.ts new file mode 100644 index 00000000..ad20633f --- /dev/null +++ b/api/src/routes/guilds/#guild_id/discovery-requirements.ts @@ -0,0 +1,39 @@ +import { Guild, Config } from "@fosscord/util"; + +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; + +const router = Router(); + +router.get("/", route({}), async (req: Request, res: Response) => { + const { guild_id } = req.params; + // TODO: + // Load from database + // Admin control, but for now it allows anyone to be discoverable + + res.send({ + guild_id: guild_id, + safe_environment: true, + healthy: true, + health_score_pending: false, + size: true, + nsfw_properties: {}, + protected: true, + sufficient: true, + sufficient_without_grace_period: true, + valid_rules_channel: true, + retention_healthy: true, + engagement_healthy: true, + age: true, + minimum_age: 0, + health_score: { + avg_nonnew_participators: 0, + avg_nonnew_communicators: 0, + num_intentful_joiners: 0, + perc_ret_w1_intentful: 0 + }, + minimum_size: 0 + }); +}); + +export default router; diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts index d8ee86ff..991c3f93 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/api/src/routes/guilds/#guild_id/index.ts @@ -34,7 +34,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { // @ts-ignore guild.joined_at = member?.joined_at; - return res.json(guild); + return res.send(guild); }); router.patch("/", route({ body: "GuildUpdateSchema", permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => { diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts index ab489743..24c74af7 100644 --- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts +++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts @@ -1,5 +1,5 @@ import { Request, Response, Router } from "express"; -import { Member, getPermission, Role, GuildMemberUpdateEvent, emitEvent } from "@fosscord/util"; +import { Member, getPermission, Role, GuildMemberUpdateEvent, emitEvent, Sticker, Emoji, Guild } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import { route } from "@fosscord/api"; @@ -43,13 +43,26 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re }); router.put("/", route({}), async (req: Request, res: Response) => { + + // TODO: Lurker mode + let { guild_id, member_id } = req.params; if (member_id === "@me") member_id = req.user_id; - throw new HTTPError("Maintenance: Currently you can't add a member", 403); - // TODO: only for oauth2 applications + var guild = await Guild.findOneOrFail({ + where: { id: guild_id } }); + + var emoji = await Emoji.find({ + where: { guild_id: guild_id } }); + + var roles = await Role.find({ + where: { guild_id: guild_id } }); + + var stickers = await Sticker.find({ + where: { guild_id: guild_id } }); + await Member.addToGuild(member_id, guild_id); - res.sendStatus(204); + res.send({...guild, emojis: emoji, roles: roles, stickers: stickers}); }); router.delete("/", route({ permission: "KICK_MEMBERS" }), async (req: Request, res: Response) => { diff --git a/api/src/routes/partners/#guild_id/requirements.ts b/api/src/routes/partners/#guild_id/requirements.ts new file mode 100644 index 00000000..545c5c78 --- /dev/null +++ b/api/src/routes/partners/#guild_id/requirements.ts @@ -0,0 +1,40 @@ + +import { Guild, Config } from "@fosscord/util"; + +import { Router, Request, Response } from "express"; +import { route } from "@fosscord/api"; + +const router = Router(); + +router.get("/", route({}), async (req: Request, res: Response) => { + const { guild_id } = req.params; + // TODO: + // Load from database + // Admin control, but for now it allows anyone to be discoverable + + res.send({ + guild_id: guild_id, + safe_environment: true, + healthy: true, + health_score_pending: false, + size: true, + nsfw_properties: {}, + protected: true, + sufficient: true, + sufficient_without_grace_period: true, + valid_rules_channel: true, + retention_healthy: true, + engagement_healthy: true, + age: true, + minimum_age: 0, + health_score: { + avg_nonnew_participators: 0, + avg_nonnew_communicators: 0, + num_intentful_joiners: 0, + perc_ret_w1_intentful: 0 + }, + minimum_size: 0 + }); +}); + +export default router; diff --git a/api/src/routes/teams.ts b/api/src/routes/teams.ts new file mode 100644 index 00000000..7ce3abcb --- /dev/null +++ b/api/src/routes/teams.ts @@ -0,0 +1,11 @@ +import { Request, Response, Router } from "express"; +import { route } from "@fosscord/api"; + +const router: Router = Router(); + +router.get("/", route({}), async (req: Request, res: Response) => { + //TODO + res.send([]); +}); + +export default router; diff --git a/api/src/routes/users/#id/profile.ts b/api/src/routes/users/#id/profile.ts index 15457547..9481451d 100644 --- a/api/src/routes/users/#id/profile.ts +++ b/api/src/routes/users/#id/profile.ts @@ -1,5 +1,5 @@ import { Router, Request, Response } from "express"; -import { PublicConnectedAccount, PublicUser, User, UserPublic } from "@fosscord/util"; +import { PublicConnectedAccount, PublicUser, User, UserPublic, Member } from "@fosscord/util"; import { route } from "@fosscord/api"; const router: Router = Router(); @@ -15,11 +15,24 @@ router.get("/", route({ test: { response: { body: "UserProfileResponse" } } }), if (req.params.id === "@me") req.params.id = req.user_id; const user = await User.getPublicUser(req.params.id, { relations: ["connected_accounts"] }); + var mutual_guilds: object[] = []; + + const requested_member = await Member.find( { id: req.params.id, }) + const self_member = await Member.find( { id: req.user_id, }) + + for(const rmem of requested_member) { + for(const smem of self_member) { + if (smem.guild_id === rmem.guild_id) { + mutual_guilds.push({id: rmem.guild_id, nick: rmem.nick}) + } + } + } + res.json({ connected_accounts: user.connected_accounts, premium_guild_since: null, // TODO premium_since: null, // TODO - mutual_guilds: [], // TODO {id: "", nick: null} when ?with_mutual_guilds=true + mutual_guilds: mutual_guilds, // TODO {id: "", nick: null} when ?with_mutual_guilds=true user: { username: user.username, discriminator: user.discriminator, diff --git a/api/src/routes/users/#id/relationships.ts b/api/src/routes/users/#id/relationships.ts new file mode 100644 index 00000000..de7cb9d3 --- /dev/null +++ b/api/src/routes/users/#id/relationships.ts @@ -0,0 +1,41 @@ +import { Router, Request, Response } from "express"; +import { User } from "@fosscord/util"; +import { route } from "@fosscord/api"; + +const router: Router = Router(); + +export interface UserRelationsResponse { + object: { + id?: string, + username?: string, + avatar?: string, + discriminator?: string, + public_flags?: number + } +} + + +router.get("/", route({ test: { response: { body: "UserRelationsResponse" } } }), async (req: Request, res: Response) => { + var mutual_relations: object[] = []; + const requested_relations = await User.findOneOrFail({ + where: { id: req.params.id }, + relations: ["relationships"] + }); + const self_relations = await User.findOneOrFail({ + where: { id: req.user_id }, + relations: ["relationships"] + }); + + for(const rmem of requested_relations.relationships) { + for(const smem of self_relations.relationships) + if (rmem.to_id === smem.to_id && rmem.type === 1 && rmem.to_id !== req.user_id) { + var relation_user = await User.getPublicUser(rmem.to_id) + + mutual_relations.push({id: relation_user.id, username: relation_user.username, avatar: relation_user.avatar, discriminator: relation_user.discriminator, public_flags: relation_user.public_flags}) + } + } + + res.json(mutual_relations) +}); + +export default router; diff --git a/api/src/routes/users/@me/guilds.ts b/api/src/routes/users/@me/guilds.ts index 22a2c04c..754a240e 100644 --- a/api/src/routes/users/@me/guilds.ts +++ b/api/src/routes/users/@me/guilds.ts @@ -8,7 +8,13 @@ const router: Router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const members = await Member.find({ relations: ["guild"], where: { id: req.user_id } }); - res.json(members.map((x) => x.guild)); + let guild = members.map((x) => x.guild); + + if ("with_counts" in req.query && req.query.with_counts == "true") { + guild = []; // TODO: Load guilds with user role permissions number + } + + res.json(guild); }); // user send to leave a certain guild diff --git a/api/src/routes/users/@me/index.ts b/api/src/routes/users/@me/index.ts index 1959704a..acca8910 100644 --- a/api/src/routes/users/@me/index.ts +++ b/api/src/routes/users/@me/index.ts @@ -57,6 +57,13 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res: user.data.hash = await bcrypt.hash(body.new_password, 12); } + var check_username = body?.username?.replace(/\s/g, ''); + if(!check_username) { + throw FieldErrors({ + username: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") } + }); + } + await user.save(); // @ts-ignore diff --git a/api/src/util/handlers/route.ts b/api/src/util/handlers/route.ts index 05658ad3..0048c4dd 100644 --- a/api/src/util/handlers/route.ts +++ b/api/src/util/handlers/route.ts @@ -73,7 +73,7 @@ const normalizeBody = (body: any = {}) => { } else { for (const [key, value] of Object.entries(object)) { if (value == null) { - if (key === "icon" || key === "avatar" || key === "banner" || key === "splash") continue; + if (key === "icon" || key === "avatar" || key === "banner" || key === "splash" || key === "discovery_splash") continue; delete object[key]; } else if (typeof value === "object") { normalizeObject(value); |