fix: name max 30 && /external/api/send_mail not return result (#222)

This commit is contained in:
Dream Hunter
2024-05-10 22:57:31 +08:00
committed by GitHub
parent cdc5c5202b
commit 46e04fd94a
3 changed files with 16 additions and 12 deletions

View File

@@ -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(?)`

View File

@@ -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)