diff --git a/server/lib/email/EmailHandler.ts b/server/lib/email/EmailHandler.ts index 2599fafef..84b28a798 100644 --- a/server/lib/email/EmailHandler.ts +++ b/server/lib/email/EmailHandler.ts @@ -24,8 +24,8 @@ const sgMail = require("@sendgrid/mail"); sgMail.setApiKey(process.env.SENDGRID_API_KEY); class EmailHandler { - static SendResetEmail(domain: string, email: any, token: string) { - const link = `https://${domain}/users/r/${token}`; + static SendResetEmail(email: any, token: string) { + const link = `${process.env.DOMAIN}/users/r/${token}`; const markup = PASSWORD_RESET_TEMPLATE.replace("{{link}}", link); const msg = { to: email, @@ -41,11 +41,10 @@ class EmailHandler { return sgMail.send(msg); } static async SendVerificationEmail( - domain: string, email: string, token: string ) { - const link = `https://${domain}/users/v/${token}`; + const link = `${process.env.DOMAIN}/users/v/${token}`; const markup = VERIFICATION_TEMPLATE.replace("{{link}}", link); const msg = { diff --git a/server/lib/parser/ParserRules.ts b/server/lib/parser/ParserRules.ts index 12903fc14..c52e6c823 100644 --- a/server/lib/parser/ParserRules.ts +++ b/server/lib/parser/ParserRules.ts @@ -75,6 +75,7 @@ class ParserRules { deck_is: input.DECK, sub_deck_is: input.SUB_DECKS, tags_is: input.TAGS, + email_notification: input.EMAIL_NOTIFICATION }) .onConflict("object_id") .merge(); diff --git a/server/package-lock.json b/server/package-lock.json index 062d4a5e9..c7b2485b5 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "notion2anki-server", - "version": "0.14.1", + "version": "0.14.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "notion2anki-server", - "version": "0.14.1", + "version": "0.14.2", "license": "MIT", "dependencies": { "@notionhq/client": "^0.4.12", diff --git a/server/package.json b/server/package.json index 091072adf..efc41a7af 100644 --- a/server/package.json +++ b/server/package.json @@ -7,7 +7,7 @@ "notion2anki" ], "author": "Alexander Alemayhu", - "version": "0.14.1", + "version": "0.14.2", "engines": { "node": ">=12.0.0" }, diff --git a/server/routes/notion/convert/helpers/performConversion.ts b/server/routes/notion/convert/helpers/performConversion.ts index fe2e25c48..5572ffe32 100644 --- a/server/routes/notion/convert/helpers/performConversion.ts +++ b/server/routes/notion/convert/helpers/performConversion.ts @@ -112,10 +112,7 @@ export default async function performConversion( await job.completed(id, owner); const email = await getEmailFromOwner(DB, owner); if (size > 24) { - const prefix = req - ? `${req.protocol}://${req.get("host")}` - : "https://2anki.net"; - const link = `${prefix}/download/u/${key}`; + const link = `${process.env.DOMAIN}/download/u/${key}`; await EmailHandler.SendConversionLinkEmail(email, id, link); } else if (rules.EMAIL_NOTIFICATION) { await EmailHandler.SendConversionEmail(email, id, apkg); diff --git a/server/routes/users/index.ts b/server/routes/users/index.ts index 04b29caae..2b2090c31 100644 --- a/server/routes/users/index.ts +++ b/server/routes/users/index.ts @@ -58,7 +58,6 @@ router.post("/forgot-password", async (req, res, next) => { if (user.reset_token) { console.debug("has active reset token, so resending"); await EmailHandler.SendResetEmail( - req.hostname, req.body.email, user.reset_token ); @@ -71,7 +70,6 @@ router.post("/forgot-password", async (req, res, next) => { await DB("users").where({ email: req.body.email }).update({ reset_token }); console.debug("sending reset email"); await EmailHandler.SendResetEmail( - req.hostname, req.body.email, reset_token ); @@ -181,7 +179,6 @@ router.post("/register", async (req, res, next) => { .insert({ name, password, email, verification_token }) .returning(["id"]); await EmailHandler.SendVerificationEmail( - req.hostname, email, verification_token ); diff --git a/web/src/lib/Backend.ts b/web/src/lib/Backend.ts index 2a3df32c5..0963b670d 100644 --- a/web/src/lib/Backend.ts +++ b/web/src/lib/Backend.ts @@ -60,12 +60,14 @@ class Backend { deck: string, subDecks: string, tags: string, + email: boolean, ) { const payload = { FLASHCARD: flashcard.join(','), DECK: deck, SUB_DECKS: subDecks, TAGS: tags, + EMAIL_NOTIFICATION: email, }; return axios.post( `${this.baseURL}rules/create/${id}`, diff --git a/web/src/pages/Search/components/DefineRules.tsx b/web/src/pages/Search/components/DefineRules.tsx index 0112ef7ab..7360b5785 100644 --- a/web/src/pages/Search/components/DefineRules.tsx +++ b/web/src/pages/Search/components/DefineRules.tsx @@ -82,6 +82,7 @@ function DefineRules(props: Props) { 'page', 'child_page', tags, + sendEmail, ); setDone(); } catch (error) {