mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-02 21:59:31 +00:00
Prettier 6
This commit is contained in:
@@ -71,11 +71,7 @@ router.post(
|
||||
|
||||
if (owner.id != req.user_id) throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
|
||||
|
||||
if (
|
||||
owner.totp_secret &&
|
||||
(!req.body.code || verifyToken(owner.totp_secret, req.body.code))
|
||||
)
|
||||
throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
|
||||
if (owner.totp_secret && (!req.body.code || verifyToken(owner.totp_secret, req.body.code))) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
|
||||
|
||||
bot.data = { hash: undefined, valid_tokens_since: new Date() };
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ router.get(
|
||||
query: {
|
||||
limit: {
|
||||
type: "number",
|
||||
description:
|
||||
"max number of members to return (1-1000). default 1",
|
||||
description: "max number of members to return (1-1000). default 1",
|
||||
},
|
||||
after: {
|
||||
type: "string",
|
||||
@@ -53,8 +52,7 @@ router.get(
|
||||
async (req: Request, res: Response) => {
|
||||
const { guild_id } = req.params;
|
||||
const limit = Number(req.query.limit) || 1;
|
||||
if (limit > 1000 || limit < 1)
|
||||
throw new HTTPError("Limit must be between 1 and 1000");
|
||||
if (limit > 1000 || limit < 1) throw new HTTPError("Limit must be between 1 and 1000");
|
||||
const after = `${req.query.after}`;
|
||||
const query = after ? { id: MoreThan(after) } : {};
|
||||
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {
|
||||
MailGunConfiguration,
|
||||
MailJetConfiguration,
|
||||
SMTPConfiguration,
|
||||
} from "./subconfigurations/email";
|
||||
import { MailGunConfiguration, MailJetConfiguration, SMTPConfiguration } from "./subconfigurations/email";
|
||||
import { SendGridConfiguration } from "./subconfigurations/email/SendGrid";
|
||||
|
||||
export class EmailConfiguration {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { BaseClassWithoutId } from "./BaseClass";
|
||||
import { CustomStatus, FriendSourceFlags, GuildFolder } from "@spacebar/schemas"
|
||||
import { CustomStatus, FriendSourceFlags, GuildFolder } from "@spacebar/schemas";
|
||||
|
||||
@Entity({
|
||||
name: "user_settings",
|
||||
@@ -128,9 +128,7 @@ export class UserSettings extends BaseClassWithoutId {
|
||||
|
||||
public static async getOrDefault(userId: string) {
|
||||
// raw sql query
|
||||
const userSettingsIndex = (
|
||||
await this.getRepository().query("SELECT \"settingsIndex\" FROM users WHERE id = $1", [userId])
|
||||
)[0]?.settingsIndex as string | null;
|
||||
const userSettingsIndex = (await this.getRepository().query('SELECT "settingsIndex" FROM users WHERE id = $1', [userId]))[0]?.settingsIndex as string | null;
|
||||
|
||||
console.log(`[INFO/UserSettings] Fetched settings index for user ${userId}:`, userSettingsIndex);
|
||||
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
|
||||
// Discord.com sends ISO strings with +00:00 extension, not Z
|
||||
// This causes issues with Python bot libs
|
||||
const JSONReplacer = function (
|
||||
this: { [key: string]: unknown },
|
||||
key: string,
|
||||
value: unknown,
|
||||
) {
|
||||
const JSONReplacer = function (this: { [key: string]: unknown }, key: string, value: unknown) {
|
||||
if (this[key] instanceof Date) {
|
||||
return (this[key] as Date).toISOString().replace("Z", "+00:00");
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ export interface IEmail {
|
||||
}
|
||||
export interface IEmailClient {
|
||||
init: () => Promise<void>;
|
||||
sendMail: (
|
||||
email: IEmail,
|
||||
) => Promise<void>;
|
||||
sendMail: (email: IEmail) => Promise<void>;
|
||||
}
|
||||
|
||||
export class BaseEmailClient implements IEmailClient {
|
||||
@@ -37,4 +35,4 @@ export class BaseEmailClient implements IEmailClient {
|
||||
sendMail(email: IEmail): Promise<void> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,7 @@ import { SMTPEmailClient } from "./clients/SMTPEmailClient";
|
||||
import { MailGunEmailClient } from "./clients/MailGunEmailClient";
|
||||
import { MailJetEmailClient } from "./clients/MailJetEmailClient";
|
||||
|
||||
const ASSET_FOLDER_PATH = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"..",
|
||||
"assets",
|
||||
);
|
||||
const ASSET_FOLDER_PATH = path.join(__dirname, "..", "..", "..", "..", "assets");
|
||||
|
||||
export enum MailTypes {
|
||||
verifyEmail = "verifyEmail",
|
||||
@@ -45,21 +38,11 @@ export enum MailTypes {
|
||||
export const Email: {
|
||||
transporter: IEmailClient | null;
|
||||
init: () => Promise<void>;
|
||||
generateLink: (
|
||||
type: Omit<MailTypes, "changePassword">,
|
||||
id: string,
|
||||
) => Promise<string>;
|
||||
sendMail: (
|
||||
type: MailTypes,
|
||||
user: User,
|
||||
email: string,
|
||||
) => Promise<void>;
|
||||
generateLink: (type: Omit<MailTypes, "changePassword">, id: string) => Promise<string>;
|
||||
sendMail: (type: MailTypes, user: User, email: string) => Promise<void>;
|
||||
sendVerifyEmail: (user: User, email: string) => Promise<void>;
|
||||
sendResetPassword: (user: User, email: string) => Promise<void>;
|
||||
sendPasswordChanged: (
|
||||
user: User,
|
||||
email: string,
|
||||
) => Promise<void>;
|
||||
sendPasswordChanged: (user: User, email: string) => Promise<void>;
|
||||
doReplacements: (
|
||||
template: string,
|
||||
user: User,
|
||||
@@ -95,8 +78,7 @@ export const Email: {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.transporter)
|
||||
return console.error(`[Email] Invalid provider: ${provider}`);
|
||||
if (!this.transporter) return console.error(`[Email] Invalid provider: ${provider}`);
|
||||
console.log(`[Email] Initializing ${provider} transport...`);
|
||||
await this.transporter.init();
|
||||
console.log(`[Email] ${provider} transport initialized.`);
|
||||
@@ -148,9 +130,7 @@ export const Email: {
|
||||
generateLink: async function (type, id) {
|
||||
const token = (await generateToken(id)) as string;
|
||||
// puyodead1: this is set to api endpoint because the verification page is on the server since no clients have one, and not all 3rd party clients will have one
|
||||
const instanceUrl =
|
||||
Config.get().api.endpointPublic?.replace("/api", "") ||
|
||||
"http://localhost:3001";
|
||||
const instanceUrl = Config.get().api.endpointPublic?.replace("/api", "") || "http://localhost:3001";
|
||||
const dashedType = type.replace(/([A-Z])/g, "-$1").toLowerCase();
|
||||
const link = `${instanceUrl}/${dashedType}#token=${token}`;
|
||||
return link;
|
||||
@@ -178,51 +158,30 @@ export const Email: {
|
||||
changePassword: "password_changed.txt",
|
||||
};
|
||||
|
||||
const htmlTemplate = await fs.readFile(
|
||||
path.join(
|
||||
ASSET_FOLDER_PATH,
|
||||
"email_templates",
|
||||
htmlTemplateNames[type],
|
||||
),
|
||||
{ encoding: "utf-8" },
|
||||
);
|
||||
const htmlTemplate = await fs.readFile(path.join(ASSET_FOLDER_PATH, "email_templates", htmlTemplateNames[type]), { encoding: "utf-8" });
|
||||
|
||||
const textTemplate = await fs.readFile(
|
||||
path.join(
|
||||
ASSET_FOLDER_PATH,
|
||||
"email_templates",
|
||||
textTemplateNames[type],
|
||||
),
|
||||
{ encoding: "utf-8" },
|
||||
);
|
||||
const textTemplate = await fs.readFile(path.join(ASSET_FOLDER_PATH, "email_templates", textTemplateNames[type]), { encoding: "utf-8" });
|
||||
|
||||
// replace email template placeholders
|
||||
const html = this.doReplacements(
|
||||
htmlTemplate,
|
||||
user,
|
||||
// password change emails don't have links
|
||||
type != MailTypes.changePassword
|
||||
? await this.generateLink(type, user.id)
|
||||
: undefined,
|
||||
type != MailTypes.changePassword ? await this.generateLink(type, user.id) : undefined,
|
||||
);
|
||||
|
||||
const text = this.doReplacements(
|
||||
textTemplate,
|
||||
user,
|
||||
// password change emails don't have links
|
||||
type != MailTypes.changePassword
|
||||
? await this.generateLink(type, user.id)
|
||||
: undefined,
|
||||
type != MailTypes.changePassword ? await this.generateLink(type, user.id) : undefined,
|
||||
);
|
||||
|
||||
// extract the title from the email template to use as the email subject
|
||||
const subject = html.match(/<title>(.*)<\/title>/)?.[1] || "";
|
||||
|
||||
const message: IEmail = {
|
||||
from:
|
||||
Config.get().email.senderAddress ||
|
||||
Config.get().general.correspondenceEmail ||
|
||||
"noreply@localhost",
|
||||
from: Config.get().email.senderAddress || Config.get().general.correspondenceEmail || "noreply@localhost",
|
||||
to: email,
|
||||
subject,
|
||||
text,
|
||||
|
||||
Reference in New Issue
Block a user