mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-05-11 18:10:01 +08:00
feat: add custom address (#13)
* feat: add custom address * feat: update readme
This commit is contained in:
@@ -18,14 +18,31 @@ api.get('/api/settings', async (c) => {
|
||||
return c.json(c.get("jwtPayload"));
|
||||
})
|
||||
|
||||
api.get('/open_api/settings', async (c) => {
|
||||
return c.json({
|
||||
"prefix": c.env.PREFIX,
|
||||
"domain": c.env.DOMAIN,
|
||||
});
|
||||
})
|
||||
|
||||
api.get('/api/new_address', async (c) => {
|
||||
// insert new address
|
||||
const name = Math.random().toString(36).substring(2, 15)
|
||||
const { success } = await c.env.DB.prepare(
|
||||
`INSERT INTO address (name) VALUES (?)`
|
||||
).bind(name).run();
|
||||
if (!success) {
|
||||
return c.json({ "error": "Failed to create address" }, 500)
|
||||
let { name } = await c.req.query();
|
||||
if (!name) {
|
||||
name = Math.random().toString(36).substring(2, 15)
|
||||
}
|
||||
try {
|
||||
const { success } = await c.env.DB.prepare(
|
||||
`INSERT INTO address (name) VALUES (?)`
|
||||
).bind(name).run();
|
||||
if (!success) {
|
||||
return c.text("Failed to create address", 500)
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.message && e.message.includes("UNIQUE")) {
|
||||
return c.text("Please retry a new address", 400)
|
||||
}
|
||||
return c.text("Failed to create address", 500)
|
||||
}
|
||||
// create jwt
|
||||
const jwt = await Jwt.sign({
|
||||
|
||||
Reference in New Issue
Block a user