Skip to content

Commit 8c7fabf

Browse files
committed
implement hubs routes
1 parent dd52fbf commit 8c7fabf

16 files changed

+70143
-29418
lines changed

assets/openapi.json

+2,821-2,429
Large diffs are not rendered by default.

assets/schemas.json

+66,928-26,987
Large diffs are not rendered by default.

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"cheerio": "^1.0.0",
8181
"cookie-parser": "^1.4.7",
8282
"dotenv": "^16.4.5",
83+
"email-providers": "^2.7.0",
8384
"exif-be-gone": "^1.5.1",
8485
"fast-zlib": "^2.0.1",
8586
"fido2-lib": "^3.5.3",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
import { route } from "@spacebar/api";
20+
import { HubDirectoryEntriesResponse } from "@spacebar/util";
21+
import { Request, Response, Router } from "express";
22+
const router = Router();
23+
24+
router.get(
25+
"/",
26+
route({
27+
responses: {
28+
200: {
29+
body: "HubDirectoryEntriesResponse",
30+
},
31+
400: {
32+
body: "APIErrorResponse",
33+
},
34+
},
35+
}),
36+
async (req: Request, res: Response) => {
37+
res.json([] as HubDirectoryEntriesResponse);
38+
},
39+
);
40+
41+
export default router;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
import { route } from "@spacebar/api";
20+
import {
21+
EmailDomainLookupResponse,
22+
EmailDomainLookupSchema,
23+
EmailDomainLookupVerifyCodeSchema,
24+
FieldErrors,
25+
} from "@spacebar/util";
26+
import emailProviders from "email-providers/all.json";
27+
import { Request, Response, Router } from "express";
28+
import { HTTPError } from "lambert-server";
29+
30+
const router = Router();
31+
32+
router.post(
33+
"/",
34+
route({
35+
requestBody: "EmailDomainLookupSchema",
36+
responses: {
37+
200: {
38+
body: "EmailDomainLookupResponse",
39+
},
40+
400: {
41+
body: "APIErrorResponse",
42+
},
43+
},
44+
}),
45+
async (req: Request, res: Response) => {
46+
const { email } = req.body as EmailDomainLookupSchema;
47+
48+
const [_, tld] = email.split("@");
49+
50+
if (emailProviders.includes(tld.toLowerCase())) {
51+
throw FieldErrors({
52+
name: {
53+
message:
54+
"That looks like a personal email address. Please use your official student email.",
55+
code: "EMAIL_IS_UNOFFICIAL",
56+
},
57+
});
58+
}
59+
60+
return res.json({
61+
guilds_info: [],
62+
has_matching_guild: false,
63+
} as EmailDomainLookupResponse);
64+
},
65+
);
66+
67+
router.post(
68+
"/verify-code",
69+
route({
70+
requestBody: "EmailDomainLookupVerifyCodeSchema",
71+
responses: {
72+
// 200: {
73+
// body: "EmailDomainLookupVerifyCodeResponse",
74+
// },
75+
400: {
76+
body: "APIErrorResponse",
77+
},
78+
501: {},
79+
},
80+
}),
81+
async (req: Request, res: Response) => {
82+
const { email } = req.body as EmailDomainLookupVerifyCodeSchema;
83+
84+
const [_, tld] = email.split("@");
85+
86+
if (emailProviders.includes(tld.toLowerCase())) {
87+
throw FieldErrors({
88+
name: {
89+
message:
90+
"That looks like a personal email address. Please use your official student email.",
91+
code: "EMAIL_IS_UNOFFICIAL",
92+
},
93+
});
94+
}
95+
96+
throw new HTTPError("Not implemented", 501);
97+
98+
// return res.json({
99+
// guild: null,
100+
// joined: false,
101+
// } as EmailDomainLookupVerifyCodeResponse);
102+
},
103+
);
104+
105+
export default router;

src/api/routes/hub-waitlist.ts

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
import { route } from "@spacebar/api";
20+
import {
21+
HubWaitlistSignupResponse,
22+
HubWaitlistSignupSchema,
23+
} from "@spacebar/util";
24+
import { Request, Response, Router } from "express";
25+
const router = Router();
26+
27+
router.post(
28+
"/signup",
29+
route({
30+
requestBody: "HubWaitlistSignupSchema",
31+
responses: {
32+
200: {
33+
body: "HubWaitlistSignupResponse",
34+
},
35+
400: {
36+
body: "APIErrorResponse",
37+
},
38+
},
39+
}),
40+
async (req: Request, res: Response) => {
41+
const { email, school } = req.body as HubWaitlistSignupSchema;
42+
43+
res.json({
44+
email,
45+
email_domain: email.split("@")[1],
46+
school,
47+
user_id: req.user_id,
48+
} as HubWaitlistSignupResponse);
49+
},
50+
);
51+
52+
export default router;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
export interface EmailDomainLookupSchema {
20+
allow_multiple_guilds: boolean;
21+
email: string;
22+
use_verification_code: boolean;
23+
guild_id?: string;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
export interface EmailDomainLookupVerifyCodeSchema {
20+
email: string;
21+
guild_id: string;
22+
code: string;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
export interface HubWaitlistSignupSchema {
20+
email: string;
21+
school: string;
22+
}

src/util/schemas/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export * from "./ConnectedAccountSchema";
3434
export * from "./ConnectionCallbackSchema";
3535
export * from "./ConnectionUpdateSchema";
3636
export * from "./DmChannelCreateSchema";
37+
export * from "./EmailDomainLookupSchema";
38+
export * from "./EmailDomainLookupVerifyCodeSchema";
3739
export * from "./EmojiCreateSchema";
3840
export * from "./EmojiModifySchema";
3941
export * from "./ForgotPasswordSchema";
@@ -42,6 +44,7 @@ export * from "./GuildCreateSchema";
4244
export * from "./GuildTemplateCreateSchema";
4345
export * from "./GuildUpdateSchema";
4446
export * from "./GuildUpdateWelcomeScreenSchema";
47+
export * from "./HubWaitlistSignupSchema";
4548
export * from "./IdentifySchema";
4649
export * from "./InviteCreateSchema";
4750
export * from "./LazyRequestSchema";
@@ -59,6 +62,7 @@ export * from "./RegisterSchema";
5962
export * from "./RelationshipPostSchema";
6063
export * from "./RelationshipPutSchema";
6164
export * from "./RequestGuildMembersSchema";
65+
export * from "./responses";
6266
export * from "./RoleModifySchema";
6367
export * from "./RolePositionUpdateSchema";
6468
export * from "./SelectProtocolSchema";
@@ -83,4 +87,3 @@ export * from "./WebAuthnSchema";
8387
export * from "./WebhookCreateSchema";
8488
export * from "./WebhookExecuteSchema";
8589
export * from "./WidgetModifySchema";
86-
export * from "./responses";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
export interface HubGuild {
19+
icon: string;
20+
id: string;
21+
name: string;
22+
}
23+
24+
export interface EmailDomainLookupResponse {
25+
guilds_info: HubGuild[];
26+
has_matching_guild: boolean;
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
import { Guild } from "../../entities";
20+
21+
export interface EmailDomainLookupVerifyCodeResponse {
22+
guild: Guild;
23+
joined: boolean;
24+
}

0 commit comments

Comments
 (0)