Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow users to request email notification for "small" uploads #630

Merged
merged 3 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions server/lib/email/EmailHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions server/lib/parser/ParserRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions server/package-lock.json

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

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"notion2anki"
],
"author": "Alexander Alemayhu",
"version": "0.14.1",
"version": "0.14.2",
"engines": {
"node": ">=12.0.0"
},
Expand Down
5 changes: 1 addition & 4 deletions server/routes/notion/convert/helpers/performConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions server/routes/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/Backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
1 change: 1 addition & 0 deletions web/src/pages/Search/components/DefineRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function DefineRules(props: Props) {
'page',
'child_page',
tags,
sendEmail,
);
setDone();
} catch (error) {
Expand Down