implement hubs routes

This commit is contained in:
Puyodead1 2025-01-07 21:12:43 -05:00
parent dd52fbf14b
commit 8c7fabfe40
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
16 changed files with 383 additions and 2 deletions

Binary file not shown.

Binary file not shown.

BIN
package-lock.json generated

Binary file not shown.

View File

@ -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",

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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";
@ -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";
@ -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";
@ -83,4 +87,3 @@ export * from "./WebAuthnSchema";
export * from "./WebhookCreateSchema";
export * from "./WebhookExecuteSchema";
export * from "./WidgetModifySchema";
export * from "./responses";

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,31 @@
/*
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 HubDirectoryEntry {
author_id: string;
created_at: string;
description: string;
directory_channel_id: string;
guild: Guild;
primary_category_id: number;
type: number; // TODO: not exactly sure what this is, channel type?
}
export type HubDirectoryEntriesResponse = HubDirectoryEntry[];

View File

@ -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 HubWaitlistSignupResponse {
email: string;
email_domain: string;
school: string;
user_id: string;
}

View File

@ -21,6 +21,8 @@ export * from "./APIErrorResponse";
export * from "./BackupCodesChallengeResponse";
export * from "./CaptchaRequiredResponse";
export * from "./DiscoverableGuildsResponse";
export * from "./EmailDomainLookupResponse";
export * from "./EmailDomainLookupVerifyCodeResponse";
export * from "./GatewayBotResponse";
export * from "./GatewayResponse";
export * from "./GenerateRegistrationTokensResponse";
@ -34,6 +36,8 @@ export * from "./GuildVanityUrl";
export * from "./GuildVoiceRegionsResponse";
export * from "./GuildWidgetJsonResponse";
export * from "./GuildWidgetSettingsResponse";
export * from "./HubDirectoryEntriesResponse";
export * from "./HubWaitlistSignupResponse";
export * from "./InstanceDomainsResponse";
export * from "./InstancePingResponse";
export * from "./InstanceStatsResponse";
@ -47,7 +51,7 @@ export * from "./TypedResponses";
export * from "./UpdatesResponse";
export * from "./UserNoteResponse";
export * from "./UserProfileResponse";
export * from "./UserRelationsResponse";
export * from "./UserRelationshipsResponse";
export * from "./UserRelationsResponse";
export * from "./WebAuthnCreateResponse";
export * from "./WebhookCreateResponse";