diff options
author | Featyre <twooter.0g179@simplelogin.co> | 2022-01-24 22:59:14 +0800 |
---|---|---|
committer | Featyre <twooter.0g179@simplelogin.co> | 2022-01-24 22:59:14 +0800 |
commit | cc492f07dcc2be60ef6396c690028da4bcea546b (patch) | |
tree | eb4ec0989289cb4e3cbaa2ded5f1c4db8ff42561 /api/src | |
parent | Prep for Category db work (diff) | |
download | server-cc492f07dcc2be60ef6396c690028da4bcea546b.tar.xz |
Partnet + Discover fix and join
Diffstat (limited to 'api/src')
-rw-r--r-- | api/src/routes/discoverable-guilds.ts | 4 | ||||
-rw-r--r-- | api/src/routes/discovery.ts | 4 | ||||
-rw-r--r-- | api/src/routes/guild-recommendations.ts | 2 | ||||
-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/util/handlers/route.ts | 2 |
8 files changed, 105 insertions, 9 deletions
diff --git a/api/src/routes/discoverable-guilds.ts b/api/src/routes/discoverable-guilds.ts index 8b7d343f..df4448df 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/api/src/routes/discoverable-guilds.ts @@ -17,13 +17,13 @@ router.get("/", route({}), async (req: Request, res: Response) => { if (categories == undefined) { guilds = showAllGuilds ? await Guild.find({ take: Math.abs(Number(limit || configLimit)) }) - : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || configLimit)) }); + : await Guild.find({ where: `"features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || configLimit)) }); total = guilds.length; } 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 '%COMMUNITY%'`, + where: `"primary_category_id" = ${categories} AND "features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || configLimit)) }); total = guilds.length; diff --git a/api/src/routes/discovery.ts b/api/src/routes/discovery.ts index 6c004274..b6a25a13 100644 --- a/api/src/routes/discovery.ts +++ b/api/src/routes/discovery.ts @@ -9,8 +9,12 @@ router.get("/categories", route({}), (req: Request, res: Response) => { const { locale, primary_only } = req.query; + let categories; + let out; + + switch (locale) { case "en-US": switch (primary_only) { diff --git a/api/src/routes/guild-recommendations.ts b/api/src/routes/guild-recommendations.ts index ecc5e546..3e5b8f32 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/api/src/routes/guild-recommendations.ts @@ -13,7 +13,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { // const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) }); const guilds = showAllGuilds ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) - : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) }); + : await Guild.find({ where: `"features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || 24)) }); res.send({ recommended_guilds: guilds }); }); 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..18a6ed4b 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 } }); + + res.send({...guild, emojis: emoji, roles: roles, stickers: stickers}); await Member.addToGuild(member_id, guild_id); - res.sendStatus(204); }); 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/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); |