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 ++++++++ 9 files changed, 86 insertions(+), 23 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') 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; -- cgit 1.4.1