From a5e06cd02193afe24292a5ae21a9f7e663e2f176 Mon Sep 17 00:00:00 2001 From: Featyre Date: Sun, 23 Jan 2022 23:55:43 +0800 Subject: Partial integration of categories and discovery --- api/src/routes/categories.ts | 27 +++++++++++++++++++++++++++ api/src/routes/discoverable-guilds.ts | 21 ++++++++++++++++----- api/src/routes/discovery.ts | 12 ------------ api/src/routes/guild-recommendations.ts | 6 +++--- 4 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 api/src/routes/categories.ts delete mode 100644 api/src/routes/discovery.ts (limited to 'api/src/routes') diff --git a/api/src/routes/categories.ts b/api/src/routes/categories.ts new file mode 100644 index 00000000..58322676 --- /dev/null +++ b/api/src/routes/categories.ts @@ -0,0 +1,27 @@ +import { Router, Response, Request } from "express"; +import { route } from "@fosscord/api"; + +const router = Router(); + +router.get("/", route({}), (req: Request, res: Response) => { + // TODO: + // Load categories from db instead + + const { locale, primary_only } = req.query; + + let out; + + switch (locale) { + case "en-US": + switch (primary_only) { + case "false": + out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 15, "is_primary": false, "name": "Esports"}, {"id": 30, "is_primary": false, "name": "LFG"}, {"id": 32, "is_primary": false, "name": "Theorycraft"}, {"id": 36, "is_primary": false, "name": "Business"}, {"id": 39, "is_primary": false, "name": "Fandom"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 18, "is_primary": false, "name": "Books"}, {"id": 23, "is_primary": false, "name": "Podcasts"}, {"id": 28, "is_primary": false, "name": "Investing"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 45, "is_primary": false, "name": "Mobile"}, {"id": 16, "is_primary": false, "name": "Anime & Manga"}, {"id": 17, "is_primary": false, "name": "Movies & TV"}, {"id": 19, "is_primary": false, "name": "Art"}, {"id": 20, "is_primary": false, "name": "Writing"}, {"id": 22, "is_primary": false, "name": "Programming"}, {"id": 25, "is_primary": false, "name": "Memes"}, {"id": 27, "is_primary": false, "name": "Cryptocurrency"}, {"id": 31, "is_primary": false, "name": "Customer Support"}, {"id": 33, "is_primary": false, "name": "Events"}, {"id": 34, "is_primary": false, "name": "Roleplay"}, {"id": 37, "is_primary": false, "name": "Local Group"}, {"id": 38, "is_primary": false, "name": "Collaboration"}, {"id": 40, "is_primary": false, "name": "Wiki & Guide"}, {"id": 42, "is_primary": false, "name": "Subreddit"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}, {"id": 21, "is_primary": false, "name": "Crafts, DIY, & Making"}, {"id": 48, "is_primary": false, "name": "Game Developer"}, {"id": 49, "is_primary": true, "name": "Bots"}, {"id": 24, "is_primary": false, "name": "Tabletop Games"}, {"id": 26, "is_primary": false, "name": "News & Current Events"}, {"id": 29, "is_primary": false, "name": "Studying & Teaching"}, {"id": 35, "is_primary": false, "name": "Content Creator"}, {"id": 44, "is_primary": false, "name": "Comics & Cartoons"}, {"id": 46, "is_primary": false, "name": "Console"}, {"id": 47, "is_primary": false, "name": "Charity & Nonprofit"}] + case "true": + out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}] + } + } + + res.json(out).status(200); +}); + +export default router; diff --git a/api/src/routes/discoverable-guilds.ts b/api/src/routes/discoverable-guilds.ts index 1cf56f84..a4559b59 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/api/src/routes/discoverable-guilds.ts @@ -6,15 +6,26 @@ import { route } from "@fosscord/api"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { - const { limit } = req.params; + const { limit, categories } = req.query; var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery; // ! 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; + let total; + switch (categories) { + case "1": + guilds = showAllGuilds + ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) + : await Guild.find({ where: `"primary_category_id" = 1 AND "features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) }); + total = guilds.length; + default: + guilds = showAllGuilds + ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) + : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) }); + total = guilds.length; + } + res.send({ total: total, guilds: guilds, offset: 0, limit: limit}); }); export default router; diff --git a/api/src/routes/discovery.ts b/api/src/routes/discovery.ts deleted file mode 100644 index bc495d42..00000000 --- a/api/src/routes/discovery.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Router, Response, Request } from "express"; -import { route } from "@fosscord/api"; - -const router = Router(); - -router.get("/categories", route({}), (req: Request, res: Response) => { - // TODO: - //const { locale, primary_only } = req.query; - res.json([]).status(200); -}); - -export default router; diff --git a/api/src/routes/guild-recommendations.ts b/api/src/routes/guild-recommendations.ts index 503b19b7..47017a6f 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/api/src/routes/guild-recommendations.ts @@ -6,14 +6,14 @@ import { route } from "@fosscord/api"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { - const { limit, personalization_disabled } = req.params; + const { limit, personalization_disabled } = req.query; var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery; // ! 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 || 100)) }); + ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) + : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) }); res.send({ recommended_guilds: guilds }); }); -- cgit 1.4.1 From e3f20f849d089493328314ad7d7518eaea3d862a Mon Sep 17 00:00:00 2001 From: Featyre Date: Mon, 24 Jan 2022 07:21:48 +0000 Subject: category + discovery + custom status fix, new config --- api/assets/fosscord-login.css | 1 - api/src/routes/categories.ts | 27 --------------------------- api/src/routes/discoverable-guilds.ts | 29 ++++++++++++++++------------- api/src/routes/discovery.ts | 27 +++++++++++++++++++++++++++ api/src/routes/guild-recommendations.ts | 2 +- bundle/package-lock.json | 6 +++--- bundle/package.json | 2 +- gateway/package.json | 2 +- util/src/entities/Config.ts | 16 ++++++++++++---- util/src/entities/Guild.ts | 2 +- util/src/entities/User.ts | 9 ++------- 11 files changed, 64 insertions(+), 59 deletions(-) delete mode 100644 api/src/routes/categories.ts create mode 100644 api/src/routes/discovery.ts (limited to 'api/src/routes') diff --git a/api/assets/fosscord-login.css b/api/assets/fosscord-login.css index 34cf542b..d507c545 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/src/routes/categories.ts b/api/src/routes/categories.ts deleted file mode 100644 index 58322676..00000000 --- a/api/src/routes/categories.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Router, Response, Request } from "express"; -import { route } from "@fosscord/api"; - -const router = Router(); - -router.get("/", route({}), (req: Request, res: Response) => { - // TODO: - // Load categories from db instead - - const { locale, primary_only } = req.query; - - let out; - - switch (locale) { - case "en-US": - switch (primary_only) { - case "false": - out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 15, "is_primary": false, "name": "Esports"}, {"id": 30, "is_primary": false, "name": "LFG"}, {"id": 32, "is_primary": false, "name": "Theorycraft"}, {"id": 36, "is_primary": false, "name": "Business"}, {"id": 39, "is_primary": false, "name": "Fandom"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 18, "is_primary": false, "name": "Books"}, {"id": 23, "is_primary": false, "name": "Podcasts"}, {"id": 28, "is_primary": false, "name": "Investing"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 45, "is_primary": false, "name": "Mobile"}, {"id": 16, "is_primary": false, "name": "Anime & Manga"}, {"id": 17, "is_primary": false, "name": "Movies & TV"}, {"id": 19, "is_primary": false, "name": "Art"}, {"id": 20, "is_primary": false, "name": "Writing"}, {"id": 22, "is_primary": false, "name": "Programming"}, {"id": 25, "is_primary": false, "name": "Memes"}, {"id": 27, "is_primary": false, "name": "Cryptocurrency"}, {"id": 31, "is_primary": false, "name": "Customer Support"}, {"id": 33, "is_primary": false, "name": "Events"}, {"id": 34, "is_primary": false, "name": "Roleplay"}, {"id": 37, "is_primary": false, "name": "Local Group"}, {"id": 38, "is_primary": false, "name": "Collaboration"}, {"id": 40, "is_primary": false, "name": "Wiki & Guide"}, {"id": 42, "is_primary": false, "name": "Subreddit"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}, {"id": 21, "is_primary": false, "name": "Crafts, DIY, & Making"}, {"id": 48, "is_primary": false, "name": "Game Developer"}, {"id": 49, "is_primary": true, "name": "Bots"}, {"id": 24, "is_primary": false, "name": "Tabletop Games"}, {"id": 26, "is_primary": false, "name": "News & Current Events"}, {"id": 29, "is_primary": false, "name": "Studying & Teaching"}, {"id": 35, "is_primary": false, "name": "Content Creator"}, {"id": 44, "is_primary": false, "name": "Comics & Cartoons"}, {"id": 46, "is_primary": false, "name": "Console"}, {"id": 47, "is_primary": false, "name": "Charity & Nonprofit"}] - case "true": - out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}] - } - } - - res.json(out).status(200); -}); - -export default router; diff --git a/api/src/routes/discoverable-guilds.ts b/api/src/routes/discoverable-guilds.ts index a4559b59..8b7d343f 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/api/src/routes/discoverable-guilds.ts @@ -6,26 +6,29 @@ import { route } from "@fosscord/api"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { - const { limit, categories } = req.query; - 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)) }); let guilds; let total; - switch (categories) { - case "1": - guilds = showAllGuilds - ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) - : await Guild.find({ where: `"primary_category_id" = 1 AND "features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) }); - total = guilds.length; - default: - guilds = showAllGuilds - ? await Guild.find({ take: Math.abs(Number(limit || 24)) }) - : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) }); + 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)) }); + 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%'`, + take: Math.abs(Number(limit || configLimit)) + }); total = guilds.length; } - res.send({ total: total, guilds: guilds, offset: 0, limit: limit}); + 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 new file mode 100644 index 00000000..067dd442 --- /dev/null +++ b/api/src/routes/discovery.ts @@ -0,0 +1,27 @@ +import { Router, Response, Request } from "express"; +import { route } from "@fosscord/api"; + +const router = Router(); + +router.get("/categories", route({}), (req: Request, res: Response) => { + // TODO: + // Load categories from db instead + + const { locale, primary_only } = req.query; + + let out; + + switch (locale) { + case "en-US": + switch (primary_only) { + case "false": + out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 15, "is_primary": false, "name": "Esports"}, {"id": 30, "is_primary": false, "name": "LFG"}, {"id": 32, "is_primary": false, "name": "Theorycraft"}, {"id": 36, "is_primary": false, "name": "Business"}, {"id": 39, "is_primary": false, "name": "Fandom"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 18, "is_primary": false, "name": "Books"}, {"id": 23, "is_primary": false, "name": "Podcasts"}, {"id": 28, "is_primary": false, "name": "Investing"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 45, "is_primary": false, "name": "Mobile"}, {"id": 16, "is_primary": false, "name": "Anime & Manga"}, {"id": 17, "is_primary": false, "name": "Movies & TV"}, {"id": 19, "is_primary": false, "name": "Art"}, {"id": 20, "is_primary": false, "name": "Writing"}, {"id": 22, "is_primary": false, "name": "Programming"}, {"id": 25, "is_primary": false, "name": "Memes"}, {"id": 27, "is_primary": false, "name": "Cryptocurrency"}, {"id": 31, "is_primary": false, "name": "Customer Support"}, {"id": 33, "is_primary": false, "name": "Events"}, {"id": 34, "is_primary": false, "name": "Roleplay"}, {"id": 37, "is_primary": false, "name": "Local Group"}, {"id": 38, "is_primary": false, "name": "Collaboration"}, {"id": 40, "is_primary": false, "name": "Wiki & Guide"}, {"id": 42, "is_primary": false, "name": "Subreddit"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}, {"id": 21, "is_primary": false, "name": "Crafts, DIY, & Making"}, {"id": 48, "is_primary": false, "name": "Game Developer"}, {"id": 49, "is_primary": true, "name": "Bots"}, {"id": 24, "is_primary": false, "name": "Tabletop Games"}, {"id": 26, "is_primary": false, "name": "News & Current Events"}, {"id": 29, "is_primary": false, "name": "Studying & Teaching"}, {"id": 35, "is_primary": false, "name": "Content Creator"}, {"id": 44, "is_primary": false, "name": "Comics & Cartoons"}, {"id": 46, "is_primary": false, "name": "Console"}, {"id": 47, "is_primary": false, "name": "Charity & Nonprofit"}] + case "true": + out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}] + } + } + + res.send(out); +}); + +export default router; diff --git a/api/src/routes/guild-recommendations.ts b/api/src/routes/guild-recommendations.ts index 47017a6f..ecc5e546 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/api/src/routes/guild-recommendations.ts @@ -7,7 +7,7 @@ const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { const { limit, personalization_disabled } = req.query; - var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery; + 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)) }); diff --git a/bundle/package-lock.json b/bundle/package-lock.json index d026e7c7..573d4059 100644 --- a/bundle/package-lock.json +++ b/bundle/package-lock.json @@ -46,7 +46,7 @@ "morgan": "^1.10.0", "multer": "^1.4.2", "nanocolors": "^0.2.12", - "node-fetch": "^2.6.7", + "node-fetch": "^2.6.2", "node-os-utils": "^1.3.5", "patch-package": "^6.4.7", "pg": "^8.7.1", @@ -213,7 +213,7 @@ "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.11", "missing-native-js-functions": "^1.2.18", - "node-fetch": "^3.1.1", + "node-fetch": "^2.6.2", "proxy-agent": "^5.0.0", "typeorm": "^0.2.37", "ws": "^7.4.2" @@ -13377,7 +13377,7 @@ "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.11", "missing-native-js-functions": "^1.2.18", - "node-fetch": "^3.1.1", + "node-fetch": "^2.6.2", "proxy-agent": "^5.0.0", "ts-node-dev": "^1.1.6", "ts-patch": "^1.4.4", diff --git a/bundle/package.json b/bundle/package.json index 071a4899..75827521 100644 --- a/bundle/package.json +++ b/bundle/package.json @@ -91,7 +91,7 @@ "missing-native-js-functions": "^1.2.18", "morgan": "^1.10.0", "multer": "^1.4.2", - "node-fetch": "^2.6.7", + "node-fetch": "^2.6.2", "node-os-utils": "^1.3.5", "patch-package": "^6.4.7", "pg": "^8.7.1", diff --git a/gateway/package.json b/gateway/package.json index 7daddfc0..6d0d2d1c 100644 --- a/gateway/package.json +++ b/gateway/package.json @@ -32,7 +32,7 @@ "jsonwebtoken": "^8.5.1", "lambert-server": "^1.2.11", "missing-native-js-functions": "^1.2.18", - "node-fetch": "^3.1.1", + "node-fetch": "^2.6.2", "proxy-agent": "^5.0.0", "typeorm": "^0.2.37", "ws": "^7.4.2" diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts index 4da65b36..f4a266dc 100644 --- a/util/src/entities/Config.ts +++ b/util/src/entities/Config.ts @@ -157,8 +157,12 @@ export interface ConfigValue { available: Region[]; }; guild: { - showAllGuildsInDiscovery: boolean; - homeDiscoveryUseRecommendation: boolean; // TODO: Recommendation, privacy concern? + discovery: { + showAllGuilds: boolean; + useRecommendation: boolean; // TODO: Recommendation, privacy concern? + offset: number; + limit: number; + }; autoJoin: { enabled: boolean; guilds: string[]; @@ -354,8 +358,12 @@ export const DefaultConfigOptions: ConfigValue = { ], }, guild: { - showAllGuildsInDiscovery: false, - homeDiscoveryUseRecommendation: false, + discovery: { + showAllGuilds: false, + useRecommendation: false, + offset: 0, + limit: 24, + }, autoJoin: { enabled: true, canLeave: true, diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts index 65ba2ae2..18fa7a0a 100644 --- a/util/src/entities/Guild.ts +++ b/util/src/entities/Guild.ts @@ -287,7 +287,7 @@ export class Guild extends BaseClass { default_message_notifications: 1, // defaults effect: setting the push default at mentions-only will save a lot explicit_content_filter: 0, features: [], - primary_category_id: 0, + primary_category_id: null, id: guild_id, max_members: 250000, max_presences: 250000, diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts index 5f2618e0..1027331a 100644 --- a/util/src/entities/User.ts +++ b/util/src/entities/User.ts @@ -289,12 +289,7 @@ export const defaultSettings: UserSettings = { animate_stickers: 0, contact_sync_enabled: false, convert_emoticons: false, - custom_status: { - emoji_id: undefined, - emoji_name: undefined, - expires_at: undefined, - text: undefined, - }, + custom_status: null, default_guilds_restricted: false, detect_platform_accounts: true, developer_mode: false, @@ -334,7 +329,7 @@ export interface UserSettings { emoji_name?: string; expires_at?: number; text?: string; - }; + } | null; default_guilds_restricted: boolean; detect_platform_accounts: boolean; developer_mode: boolean; -- cgit 1.4.1 From 5e868d431b431cc9f2a57efdbfa4d397e5188a3d Mon Sep 17 00:00:00 2001 From: Featyre Date: Mon, 24 Jan 2022 11:27:12 +0000 Subject: Prep for Category db work --- api/src/routes/discovery.ts | 2 +- util/src/entities/Categories.ts | 6 +----- util/src/util/Categories.ts | 1 + util/src/util/index.ts | 1 + 4 files changed, 4 insertions(+), 6 deletions(-) create mode 100644 util/src/util/Categories.ts (limited to 'api/src/routes') diff --git a/api/src/routes/discovery.ts b/api/src/routes/discovery.ts index 067dd442..6c004274 100644 --- a/api/src/routes/discovery.ts +++ b/api/src/routes/discovery.ts @@ -5,7 +5,7 @@ const router = Router(); router.get("/categories", route({}), (req: Request, res: Response) => { // TODO: - // Load categories from db instead + // Load categories from db instead of hardcoding const { locale, primary_only } = req.query; diff --git a/util/src/entities/Categories.ts b/util/src/entities/Categories.ts index 2cf89dbc..1d272118 100644 --- a/util/src/entities/Categories.ts +++ b/util/src/entities/Categories.ts @@ -15,7 +15,7 @@ import { BaseClassWithoutId } from "./BaseClass"; // }] @Entity("categories") -export class Categories extends BaseClassWithoutId { // Not using snowflake +export class CategoryEntity extends BaseClassWithoutId { // Not using snowflake @PrimaryColumn() id: number; @@ -29,8 +29,4 @@ export class Categories extends BaseClassWithoutId { // Not using snowflake @Column() is_primary: boolean; -} - -export interface DefaultCategoryValue { // TODO: Load Default Discord Categories - } \ No newline at end of file diff --git a/util/src/util/Categories.ts b/util/src/util/Categories.ts new file mode 100644 index 00000000..a3c69da7 --- /dev/null +++ b/util/src/util/Categories.ts @@ -0,0 +1 @@ +//TODO: populate default discord categories + init, get and set methods \ No newline at end of file diff --git a/util/src/util/index.ts b/util/src/util/index.ts index 98e1146c..f7a273cb 100644 --- a/util/src/util/index.ts +++ b/util/src/util/index.ts @@ -1,6 +1,7 @@ export * from "./ApiError"; export * from "./BitField"; export * from "./Token"; +//export * from "./Categories"; export * from "./cdn"; export * from "./Config"; export * from "./Constants"; -- cgit 1.4.1 From cc492f07dcc2be60ef6396c690028da4bcea546b Mon Sep 17 00:00:00 2001 From: Featyre Date: Mon, 24 Jan 2022 22:59:14 +0800 Subject: Partnet + Discover fix and join --- api/src/routes/discoverable-guilds.ts | 4 +-- api/src/routes/discovery.ts | 4 +++ api/src/routes/guild-recommendations.ts | 2 +- .../guilds/#guild_id/discovery-requirements.ts | 39 +++++++++++++++++++++ api/src/routes/guilds/#guild_id/index.ts | 2 +- .../guilds/#guild_id/members/#member_id/index.ts | 21 +++++++++--- api/src/routes/partners/#guild_id/requirements.ts | 40 ++++++++++++++++++++++ api/src/util/handlers/route.ts | 2 +- 8 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 api/src/routes/guilds/#guild_id/discovery-requirements.ts create mode 100644 api/src/routes/partners/#guild_id/requirements.ts (limited to 'api/src/routes') 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); -- cgit 1.4.1 From 5c525c1eef8de8c94a47316b23c23bd23ce54922 Mon Sep 17 00:00:00 2001 From: Featyre Date: Tue, 25 Jan 2022 00:30:16 +0800 Subject: change line --- api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/src/routes') 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 18a6ed4b..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 @@ -61,8 +61,8 @@ router.put("/", route({}), async (req: Request, res: Response) => { 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.send({...guild, emojis: emoji, roles: roles, stickers: stickers}); }); router.delete("/", route({ permission: "KICK_MEMBERS" }), async (req: Request, res: Response) => { -- cgit 1.4.1 From b01a26cdceb2840b44da7033e2f6615a27273595 Mon Sep 17 00:00:00 2001 From: Featyre Date: Wed, 26 Jan 2022 08:58:36 +0800 Subject: Dev portal + categories load db --- api/client_test/developers.html | 42 +++++++++++++++++++++++++++++++ api/src/middlewares/TestClient.ts | 9 +++++++ api/src/routes/applications/detectable.ts | 2 +- api/src/routes/applications/index.ts | 11 ++++++++ api/src/routes/discoverable-guilds.ts | 6 ++--- api/src/routes/discovery.ts | 21 +++------------- api/src/routes/experiments.ts | 2 +- api/src/routes/guild-recommendations.ts | 5 +++- api/src/routes/teams.ts | 11 ++++++++ util/src/entities/Categories.ts | 6 ++--- 10 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 api/client_test/developers.html create mode 100644 api/src/routes/applications/index.ts create mode 100644 api/src/routes/teams.ts (limited to 'api/src/routes') 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 @@ + + + + + + + + + Discord Test Client Developer Portal + + + + +
+ + + + + + 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 df4448df..0aa2baa9 100644 --- a/api/src/routes/discoverable-guilds.ts +++ b/api/src/routes/discoverable-guilds.ts @@ -13,12 +13,10 @@ router.get("/", route({}), async (req: Request, res: Response) => { // TODO: implement this with default typeorm query // const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) }); let guilds; - let total; 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)) }); - total = guilds.length; } else { guilds = showAllGuilds ? await Guild.find({ where: `"primary_category_id" = ${categories}`, take: Math.abs(Number(limit || configLimit)) }) @@ -26,8 +24,10 @@ router.get("/", route({}), async (req: Request, res: Response) => { where: `"primary_category_id" = ${categories} AND "features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || configLimit)) }); - total = guilds.length; } + + const total = guilds ? guilds.length : undefined; + res.send({ total: total, guilds: guilds, offset: Number(offset || Config.get().guild.discovery.offset), limit: Number(limit || configLimit) }); }); diff --git a/api/src/routes/discovery.ts b/api/src/routes/discovery.ts index b6a25a13..1991400e 100644 --- a/api/src/routes/discovery.ts +++ b/api/src/routes/discovery.ts @@ -1,29 +1,16 @@ +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: - // Load categories from db instead of hardcoding + // Get locale instead const { locale, primary_only } = req.query; - let categories; - - let out; - - - - switch (locale) { - case "en-US": - switch (primary_only) { - case "false": - out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 15, "is_primary": false, "name": "Esports"}, {"id": 30, "is_primary": false, "name": "LFG"}, {"id": 32, "is_primary": false, "name": "Theorycraft"}, {"id": 36, "is_primary": false, "name": "Business"}, {"id": 39, "is_primary": false, "name": "Fandom"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 18, "is_primary": false, "name": "Books"}, {"id": 23, "is_primary": false, "name": "Podcasts"}, {"id": 28, "is_primary": false, "name": "Investing"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 45, "is_primary": false, "name": "Mobile"}, {"id": 16, "is_primary": false, "name": "Anime & Manga"}, {"id": 17, "is_primary": false, "name": "Movies & TV"}, {"id": 19, "is_primary": false, "name": "Art"}, {"id": 20, "is_primary": false, "name": "Writing"}, {"id": 22, "is_primary": false, "name": "Programming"}, {"id": 25, "is_primary": false, "name": "Memes"}, {"id": 27, "is_primary": false, "name": "Cryptocurrency"}, {"id": 31, "is_primary": false, "name": "Customer Support"}, {"id": 33, "is_primary": false, "name": "Events"}, {"id": 34, "is_primary": false, "name": "Roleplay"}, {"id": 37, "is_primary": false, "name": "Local Group"}, {"id": 38, "is_primary": false, "name": "Collaboration"}, {"id": 40, "is_primary": false, "name": "Wiki & Guide"}, {"id": 42, "is_primary": false, "name": "Subreddit"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}, {"id": 21, "is_primary": false, "name": "Crafts, DIY, & Making"}, {"id": 48, "is_primary": false, "name": "Game Developer"}, {"id": 49, "is_primary": true, "name": "Bots"}, {"id": 24, "is_primary": false, "name": "Tabletop Games"}, {"id": 26, "is_primary": false, "name": "News & Current Events"}, {"id": 29, "is_primary": false, "name": "Studying & Teaching"}, {"id": 35, "is_primary": false, "name": "Content Creator"}, {"id": 44, "is_primary": false, "name": "Comics & Cartoons"}, {"id": 46, "is_primary": false, "name": "Console"}, {"id": 47, "is_primary": false, "name": "Charity & Nonprofit"}] - case "true": - out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}] - } - } + const out = primary_only ? await Categories.find() : await Categories.find({ where: `"is_primary" = "true"` }); res.send(out); }); 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 3e5b8f32..1432f39c 100644 --- a/api/src/routes/guild-recommendations.ts +++ b/api/src/routes/guild-recommendations.ts @@ -11,10 +11,13 @@ router.get("/", route({}), async (req: Request, res: Response) => { // ! 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 || 24)) }) : await Guild.find({ where: `"features" LIKE '%DISCOVERABLE%'`, take: Math.abs(Number(limit || 24)) }); - res.send({ recommended_guilds: guilds }); + res.send({ recommended_guilds: guilds, load_id: `server_recs/${genLoadId(32)}`}).status(200); }); 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/util/src/entities/Categories.ts b/util/src/entities/Categories.ts index 1d272118..269e178f 100644 --- a/util/src/entities/Categories.ts +++ b/util/src/entities/Categories.ts @@ -15,15 +15,15 @@ import { BaseClassWithoutId } from "./BaseClass"; // }] @Entity("categories") -export class CategoryEntity extends BaseClassWithoutId { // Not using snowflake +export class Categories extends BaseClassWithoutId { // Not using snowflake @PrimaryColumn() id: number; @Column() - default: string; + name: string; - @Column({ type: "simple-json", nullable: false }) + @Column({ type: "simple-json" }) localizations: string; @Column() -- cgit 1.4.1 From 7b3531cb9015ec5bdf95c97b726d5d64f2ca41fa Mon Sep 17 00:00:00 2001 From: Featyre Date: Wed, 2 Feb 2022 02:09:57 +0800 Subject: Return none for dev portal + todo for categories --- api/src/routes/users/@me/guilds.ts | 8 +++++++- util/src/entities/Categories.ts | 1 + util/src/entities/Guild.ts | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'api/src/routes') 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/util/src/entities/Categories.ts b/util/src/entities/Categories.ts index a3c1280f..81fbc303 100644 --- a/util/src/entities/Categories.ts +++ b/util/src/entities/Categories.ts @@ -13,6 +13,7 @@ import { BaseClassWithoutId } from "./BaseClass"; // }, // "is_primary": false/true // }] +// Also populate discord default categories @Entity("categories") export class Categories extends BaseClassWithoutId { // Not using snowflake diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts index 18fa7a0a..9ac148ee 100644 --- a/util/src/entities/Guild.ts +++ b/util/src/entities/Guild.ts @@ -270,6 +270,9 @@ export class Guild extends BaseClass { @Column({ nullable: true }) nsfw?: boolean; + // only for developer portal + permissions?: number; + static async createGuild(body: { name?: string; icon?: string | null; -- cgit 1.4.1