Skip to content

Commit

Permalink
implement hubs routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Jan 8, 2025
1 parent dd52fbf commit 8c7fabf
Show file tree
Hide file tree
Showing 16 changed files with 70,143 additions and 29,418 deletions.
5,250 changes: 2,821 additions & 2,429 deletions assets/openapi.json

Large diffs are not rendered by default.

93,915 changes: 66,928 additions & 26,987 deletions assets/schemas.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"cheerio": "^1.0.0",
"cookie-parser": "^1.4.7",
"dotenv": "^16.4.5",
"email-providers": "^2.7.0",
"exif-be-gone": "^1.5.1",
"fast-zlib": "^2.0.1",
"fido2-lib": "^3.5.3",
Expand Down
41 changes: 41 additions & 0 deletions src/api/routes/channels/#channel_id/directory-entries.ts
Original file line number Diff line number Diff line change
@@ -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;
105 changes: 105 additions & 0 deletions src/api/routes/guilds/automations/email-domain-lookup.ts
Original file line number Diff line number Diff line change
@@ -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;
52 changes: 52 additions & 0 deletions src/api/routes/hub-waitlist.ts
Original file line number Diff line number Diff line change
@@ -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;
24 changes: 24 additions & 0 deletions src/util/schemas/EmailDomainLookupSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
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/>.
*/

export interface EmailDomainLookupSchema {
allow_multiple_guilds: boolean;
email: string;
use_verification_code: boolean;
guild_id?: string;
}
23 changes: 23 additions & 0 deletions src/util/schemas/EmailDomainLookupVerifyCodeSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
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/>.
*/

export interface EmailDomainLookupVerifyCodeSchema {
email: string;
guild_id: string;
code: string;
}
22 changes: 22 additions & 0 deletions src/util/schemas/HubWaitlistSignupSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
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/>.
*/

export interface HubWaitlistSignupSchema {
email: string;
school: string;
}
5 changes: 4 additions & 1 deletion src/util/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export * from "./ConnectedAccountSchema";
export * from "./ConnectionCallbackSchema";
export * from "./ConnectionUpdateSchema";
export * from "./DmChannelCreateSchema";
export * from "./EmailDomainLookupSchema";
export * from "./EmailDomainLookupVerifyCodeSchema";
export * from "./EmojiCreateSchema";
export * from "./EmojiModifySchema";
export * from "./ForgotPasswordSchema";
Expand All @@ -42,6 +44,7 @@ export * from "./GuildCreateSchema";
export * from "./GuildTemplateCreateSchema";
export * from "./GuildUpdateSchema";
export * from "./GuildUpdateWelcomeScreenSchema";
export * from "./HubWaitlistSignupSchema";
export * from "./IdentifySchema";
export * from "./InviteCreateSchema";
export * from "./LazyRequestSchema";
Expand All @@ -59,6 +62,7 @@ export * from "./RegisterSchema";
export * from "./RelationshipPostSchema";
export * from "./RelationshipPutSchema";
export * from "./RequestGuildMembersSchema";
export * from "./responses";
export * from "./RoleModifySchema";
export * from "./RolePositionUpdateSchema";
export * from "./SelectProtocolSchema";
Expand All @@ -83,4 +87,3 @@ export * from "./WebAuthnSchema";
export * from "./WebhookCreateSchema";
export * from "./WebhookExecuteSchema";
export * from "./WidgetModifySchema";
export * from "./responses";
27 changes: 27 additions & 0 deletions src/util/schemas/responses/EmailDomainLookupResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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/>.
*/
export interface HubGuild {
icon: string;
id: string;
name: string;
}

export interface EmailDomainLookupResponse {
guilds_info: HubGuild[];
has_matching_guild: boolean;
}
24 changes: 24 additions & 0 deletions src/util/schemas/responses/EmailDomainLookupVerifyCodeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
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 { Guild } from "../../entities";

export interface EmailDomainLookupVerifyCodeResponse {
guild: Guild;
joined: boolean;
}
Loading

0 comments on commit 8c7fabf

Please sign in to comment.