summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2025-01-07 21:12:43 -0500
committerPuyodead1 <puyodead@proton.me>2025-01-07 21:12:43 -0500
commit8c7fabfe40ed8e163616e5eeaf54541d8e7d4a12 (patch)
tree5afc879fb13750620f3e0c81bcbf5650b6c2e86f /src/api
parentMerge pull request #1237 from dank074/patch/fix-prettier-eol (diff)
downloadserver-ts-8c7fabfe40ed8e163616e5eeaf54541d8e7d4a12.tar.xz
implement hubs routes
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/directory-entries.ts41
-rw-r--r--src/api/routes/guilds/automations/email-domain-lookup.ts105
-rw-r--r--src/api/routes/hub-waitlist.ts52
3 files changed, 198 insertions, 0 deletions
diff --git a/src/api/routes/channels/#channel_id/directory-entries.ts b/src/api/routes/channels/#channel_id/directory-entries.ts
new file mode 100644

index 000000000..da1ff90ec --- /dev/null +++ b/src/api/routes/channels/#channel_id/directory-entries.ts
@@ -0,0 +1,41 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import { route } from "@spacebar/api"; +import { HubDirectoryEntriesResponse } from "@spacebar/util"; +import { Request, Response, Router } from "express"; +const router = Router(); + +router.get( + "/", + route({ + responses: { + 200: { + body: "HubDirectoryEntriesResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), + async (req: Request, res: Response) => { + res.json([] as HubDirectoryEntriesResponse); + }, +); + +export default router; diff --git a/src/api/routes/guilds/automations/email-domain-lookup.ts b/src/api/routes/guilds/automations/email-domain-lookup.ts new file mode 100644
index 000000000..ebb76d7a3 --- /dev/null +++ b/src/api/routes/guilds/automations/email-domain-lookup.ts
@@ -0,0 +1,105 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import { route } from "@spacebar/api"; +import { + EmailDomainLookupResponse, + EmailDomainLookupSchema, + EmailDomainLookupVerifyCodeSchema, + FieldErrors, +} from "@spacebar/util"; +import emailProviders from "email-providers/all.json"; +import { Request, Response, Router } from "express"; +import { HTTPError } from "lambert-server"; + +const router = Router(); + +router.post( + "/", + route({ + requestBody: "EmailDomainLookupSchema", + responses: { + 200: { + body: "EmailDomainLookupResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), + async (req: Request, res: Response) => { + const { email } = req.body as EmailDomainLookupSchema; + + const [_, tld] = email.split("@"); + + if (emailProviders.includes(tld.toLowerCase())) { + throw FieldErrors({ + name: { + message: + "That looks like a personal email address. Please use your official student email.", + code: "EMAIL_IS_UNOFFICIAL", + }, + }); + } + + return res.json({ + guilds_info: [], + has_matching_guild: false, + } as EmailDomainLookupResponse); + }, +); + +router.post( + "/verify-code", + route({ + requestBody: "EmailDomainLookupVerifyCodeSchema", + responses: { + // 200: { + // body: "EmailDomainLookupVerifyCodeResponse", + // }, + 400: { + body: "APIErrorResponse", + }, + 501: {}, + }, + }), + async (req: Request, res: Response) => { + const { email } = req.body as EmailDomainLookupVerifyCodeSchema; + + const [_, tld] = email.split("@"); + + if (emailProviders.includes(tld.toLowerCase())) { + throw FieldErrors({ + name: { + message: + "That looks like a personal email address. Please use your official student email.", + code: "EMAIL_IS_UNOFFICIAL", + }, + }); + } + + throw new HTTPError("Not implemented", 501); + + // return res.json({ + // guild: null, + // joined: false, + // } as EmailDomainLookupVerifyCodeResponse); + }, +); + +export default router; diff --git a/src/api/routes/hub-waitlist.ts b/src/api/routes/hub-waitlist.ts new file mode 100644
index 000000000..a6501e0ec --- /dev/null +++ b/src/api/routes/hub-waitlist.ts
@@ -0,0 +1,52 @@ +/* + Spacebar: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Spacebar and Spacebar Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +import { route } from "@spacebar/api"; +import { + HubWaitlistSignupResponse, + HubWaitlistSignupSchema, +} from "@spacebar/util"; +import { Request, Response, Router } from "express"; +const router = Router(); + +router.post( + "/signup", + route({ + requestBody: "HubWaitlistSignupSchema", + responses: { + 200: { + body: "HubWaitlistSignupResponse", + }, + 400: { + body: "APIErrorResponse", + }, + }, + }), + async (req: Request, res: Response) => { + const { email, school } = req.body as HubWaitlistSignupSchema; + + res.json({ + email, + email_domain: email.split("@")[1], + school, + user_id: req.user_id, + } as HubWaitlistSignupResponse); + }, +); + +export default router;