fix(email): get resend key by domain when send email(#37)
This commit is contained in:
@@ -143,6 +143,7 @@ pnpm dev
|
||||
- Prisma ORM 作为数据库工具
|
||||
- Cloudflare 作为主要的云基础设施
|
||||
- Vercel 作为推荐的部署平台
|
||||
- Resend 作为邮件服务
|
||||
|
||||
## 社区群组
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ Via [Installation For Developer](https://wr.do/docs/developer).
|
||||
- Prisma ORM as the database toolkit
|
||||
- Cloudflare as the primary cloud infrastructure
|
||||
- Vercel as the recommended deployment platform
|
||||
- Resend as the primary email service
|
||||
|
||||
## Community Group
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { Resend } from "resend";
|
||||
|
||||
import { checkDomainIsConfiguratedResend } from "@/lib/dto/domains";
|
||||
import { getUserSendEmailCount, saveUserSendEmail } from "@/lib/dto/email";
|
||||
import { getPlanQuota } from "@/lib/dto/plan";
|
||||
import { checkUserStatus } from "@/lib/dto/user";
|
||||
import { resend } from "@/lib/email";
|
||||
import { getCurrentUser } from "@/lib/session";
|
||||
import { restrictByTimeRange } from "@/lib/team";
|
||||
import { isValidEmail } from "@/lib/utils";
|
||||
@@ -36,13 +36,18 @@ export async function POST(req: NextRequest) {
|
||||
return NextResponse.json("Invalid email address", { status: 403 });
|
||||
}
|
||||
|
||||
if (!(await checkDomainIsConfiguratedResend(from.split("@")[1]))) {
|
||||
const resend_key = await checkDomainIsConfiguratedResend(
|
||||
from.split("@")[1],
|
||||
);
|
||||
|
||||
if (!resend_key) {
|
||||
return NextResponse.json(
|
||||
"This domain is not configured for sending emails",
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const resend = new Resend(resend_key);
|
||||
const { error } = await resend.emails.send({
|
||||
from,
|
||||
to,
|
||||
@@ -51,8 +56,10 @@ export async function POST(req: NextRequest) {
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.log("Resend error:", error);
|
||||
return NextResponse.json("Failed to send email", { status: 500 });
|
||||
console.log("Resend error:", error); // ???如果删掉这句log,下面一行读取error的message会返回undefined
|
||||
return NextResponse.json(`${error.message}`, {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
await saveUserSendEmail(user.id, from, to, subject, html);
|
||||
|
||||
@@ -63,7 +63,7 @@ export function RecordForm({
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [isDeleting, startDeleteTransition] = useTransition();
|
||||
const [currentRecordType, setCurrentRecordType] = useState(
|
||||
initData?.type || "CNAME",
|
||||
initData?.type || "A",
|
||||
);
|
||||
const [currentZoneName, setCurrentZoneName] = useState(initData?.zone_name);
|
||||
const [limitLen, setLimitLen] = useState(3);
|
||||
@@ -83,7 +83,7 @@ export function RecordForm({
|
||||
resolver: zodResolver(createRecordSchema),
|
||||
defaultValues: {
|
||||
zone_name: initData?.zone_name,
|
||||
type: initData?.type || "CNAME",
|
||||
type: initData?.type || "A",
|
||||
ttl: initData?.ttl || 1,
|
||||
proxied: initData?.proxied || false,
|
||||
comment: initData?.comment || "",
|
||||
@@ -392,7 +392,7 @@ export function RecordForm({
|
||||
setCurrentRecordType(value);
|
||||
}}
|
||||
name={"type"}
|
||||
defaultValue={initData?.type || "CNAME"}
|
||||
defaultValue={initData?.type || "A"}
|
||||
>
|
||||
<SelectTrigger className="w-full shadow-inner">
|
||||
<SelectValue placeholder="Select a type" />
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ export async function checkDomainIsConfiguratedResend(domain_name: string) {
|
||||
resend_api_key: true,
|
||||
},
|
||||
});
|
||||
return Boolean(domain?.resend_api_key);
|
||||
return domain?.resend_api_key;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to fetch domain config: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
|
||||
<url><loc>https://wr.do/robots.txt</loc><lastmod>2025-06-21T08:53:30.862Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://wr.do/manifest.json</loc><lastmod>2025-06-21T08:53:30.862Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://wr.do/opengraph-image.jpg</loc><lastmod>2025-06-21T08:53:30.862Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://wr.do/manifest.json</loc><lastmod>2025-06-29T11:28:45.465Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://wr.do/robots.txt</loc><lastmod>2025-06-29T11:28:45.465Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
||||
<url><loc>https://wr.do/opengraph-image.jpg</loc><lastmod>2025-06-29T11:28:45.465Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
|
||||
</urlset>
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user