mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-06-05 23:51:39 +08:00
fix: name max 30 && /external/api/send_mail not return result (#222)
This commit is contained in:
@@ -9,8 +9,12 @@ export const newAddress = async (c, name, domain, enablePrefix) => {
|
||||
if (name.length < 0) {
|
||||
return c.text("Name too short", 400)
|
||||
}
|
||||
if (name.length > 100) {
|
||||
return c.text("Name too long (max 100)", 400)
|
||||
// create address
|
||||
if (enablePrefix) {
|
||||
name = getStringValue(c.env.PREFIX) + name;
|
||||
}
|
||||
if (name.length >= 30) {
|
||||
return c.text("Name too long (max 30)", 400)
|
||||
}
|
||||
// check domain, generate random domain
|
||||
const domains = getDomains(c);
|
||||
@@ -18,11 +22,7 @@ export const newAddress = async (c, name, domain, enablePrefix) => {
|
||||
domain = domains[Math.floor(Math.random() * domains.length)];
|
||||
}
|
||||
// create address
|
||||
if (enablePrefix) {
|
||||
name = getStringValue(c.env.PREFIX) + name + "@" + domain;
|
||||
} else {
|
||||
name = name + "@" + domain;
|
||||
}
|
||||
name = name + "@" + domain;
|
||||
try {
|
||||
const { success } = await c.env.DB.prepare(
|
||||
`INSERT INTO address(name) VALUES(?)`
|
||||
|
||||
@@ -161,7 +161,8 @@ api.post('/external/api/send_mail', async (c) => {
|
||||
return c.text("No address", 400)
|
||||
}
|
||||
const reqJson = await c.req.json();
|
||||
return await sendMail(c, address, reqJson);
|
||||
await sendMail(c, address, reqJson);
|
||||
return c.json({ status: "ok" })
|
||||
} catch (e) {
|
||||
console.error("Failed to send mail", e);
|
||||
return c.text(`Failed to send mail ${e.message}`, 400)
|
||||
|
||||
Reference in New Issue
Block a user