tweaks
This commit is contained in:
parent
f12a018544
commit
d4827bc531
|
|
@ -24,6 +24,6 @@ S3_ENDPOINT=xxx
|
|||
S3_CDN_PREFIX=https://user-contents.proselog.com/
|
||||
NEXT_PUBLIC_S3_CDN_PREFIX=$S3_CDN_PREFIX
|
||||
|
||||
MAILGUN_APIKEY=xxx
|
||||
MAILGUN_DOMAIN=mg.proselog.com
|
||||
MAILGUN_EU=true
|
||||
MAILGUN_APIKEY=
|
||||
MAILGUN_DOMAIN=
|
||||
MAILGUN_EU=
|
||||
|
|
|
|||
|
|
@ -10,12 +10,13 @@ import {
|
|||
import type { MailgunMessageData } from "mailgun.js/interfaces/Messages"
|
||||
import { IS_PROD } from "./constants"
|
||||
import { APP_NAME, OUR_DOMAIN, SITE_URL } from "./env"
|
||||
import { PostOnArchivesPage, SubscribeFormData } from "./types"
|
||||
import { SubscribeFormData } from "./types"
|
||||
import { getSite } from "~/models/site.model"
|
||||
import { Site, User } from "@prisma/client"
|
||||
import { nanoid } from "nanoid"
|
||||
import Iron from "@hapi/iron"
|
||||
|
||||
const enableMailgun = Boolean(MAILGUN_APIKEY && MAILGUN_DOMAIN)
|
||||
|
||||
const getClient = () =>
|
||||
singleton("mailgun", () => {
|
||||
const mg = new Mailgun(FormData)
|
||||
|
|
@ -30,7 +31,7 @@ const getClient = () =>
|
|||
const sendEmail = async (message: MailgunMessageData) => {
|
||||
console.log(message)
|
||||
|
||||
if (!IS_PROD) {
|
||||
if (!enableMailgun) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ export const sendLoginEmail = async (payload: {
|
|||
}
|
||||
|
||||
const message: MailgunMessageData = {
|
||||
from: `${APP_NAME} <hi@${OUR_DOMAIN}>`,
|
||||
from: `${APP_NAME} <hi@proselog.com>`,
|
||||
to: payload.email,
|
||||
subject,
|
||||
html,
|
||||
|
|
@ -93,7 +94,7 @@ export const sendEmailForNewPost = async (payload: {
|
|||
subscribers: { id: string; email: string }[]
|
||||
}) => {
|
||||
try {
|
||||
const from = `${payload.site.name} <updates@${payload.site.subdomain}.${OUR_DOMAIN}>`
|
||||
const from = `${payload.site.name} <updates@${payload.site.subdomain}.proselog.com>`
|
||||
const subject = `${payload.post.title} - ${payload.site.name}`
|
||||
const html = `
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { MembershipRole } from "@prisma/client"
|
||||
import { MembershipRole, PageType } from "@prisma/client"
|
||||
import { nanoid } from "nanoid"
|
||||
import { prisma, Prisma } from "~/lib/db.server"
|
||||
import { type Gate } from "~/lib/gate.server"
|
||||
|
|
@ -111,7 +111,7 @@ export async function createOrUpdatePage(
|
|||
})
|
||||
|
||||
if (
|
||||
input.isPost &&
|
||||
page.type === PageType.POST &&
|
||||
!page.subscribersNotifiedAt &&
|
||||
page.published &&
|
||||
page.publishedAt <= new Date()
|
||||
|
|
@ -283,7 +283,7 @@ export const notifySubscribersForNewPost = async (
|
|||
throw new Error("You have already notified subscribers for this post")
|
||||
}
|
||||
|
||||
const subscribers = await prisma.membership.findMany({
|
||||
const memberships = await prisma.membership.findMany({
|
||||
where: {
|
||||
role: MembershipRole.SUBSCRIBER,
|
||||
siteId: site.id,
|
||||
|
|
@ -293,7 +293,7 @@ export const notifySubscribersForNewPost = async (
|
|||
},
|
||||
})
|
||||
|
||||
if (subscribers.length === 0) return
|
||||
if (memberships.length === 0) return
|
||||
|
||||
await prisma.page.update({
|
||||
where: {
|
||||
|
|
@ -304,11 +304,13 @@ export const notifySubscribersForNewPost = async (
|
|||
},
|
||||
})
|
||||
|
||||
const emailSubscribers = memberships
|
||||
.filter((member) => (member.config as Prisma.JsonObject).email)
|
||||
.map((member) => member.user)
|
||||
|
||||
sendEmailForNewPost({
|
||||
post: page,
|
||||
site,
|
||||
subscribers: subscribers
|
||||
.filter((sub) => (sub.config as Prisma.JsonObject).email)
|
||||
.map((sub) => sub.user),
|
||||
subscribers: emailSubscribers,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue