summary refs log tree commit diff
path: root/api
diff options
context:
space:
mode:
authorFeatyre <twooter.0g179@simplelogin.co>2022-01-26 08:58:36 +0800
committerFeatyre <twooter.0g179@simplelogin.co>2022-01-26 08:58:36 +0800
commit821470cc41f7922b3a5f471988e344332a34068d (patch)
tree8bc3a673bd8c03a55bc1cb6357ea8d2f35cf4dc4 /api
parentchange line (diff)
downloadserver-821470cc41f7922b3a5f471988e344332a34068d.tar.xz
Dev portal + categories load db
Diffstat (limited to 'api')
-rw-r--r--api/client_test/developers.html42
-rw-r--r--api/src/routes/applications/detectable.ts2
-rw-r--r--api/src/routes/applications/index.ts11
-rw-r--r--api/src/routes/discoverable-guilds.ts6
-rw-r--r--api/src/routes/discovery.ts21
-rw-r--r--api/src/routes/experiments.ts2
-rw-r--r--api/src/routes/guild-recommendations.ts5
-rw-r--r--api/src/routes/teams.ts11
8 files changed, 77 insertions, 23 deletions
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/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;