feat: add faker-js (#107)

This commit is contained in:
Dream Hunter
2024-04-09 19:30:35 +08:00
committed by GitHub
parent a124e00766
commit 42a828e98b
4 changed files with 35 additions and 3 deletions

View File

@@ -131,11 +131,20 @@ api.get('/open_api/settings', async (c) => {
})
api.get('/api/new_address', async (c) => {
let { name, domain } = await c.req.query();
let { name, domain } = c.req.query();
// if no name, generate random name
if (!name) {
name = Math.random().toString(36).substring(2, 15);
}
// remove special characters
name = name.replace(/[^a-zA-Z0-9.]/g, '')
// check name length
if (name.length < 0) {
return c.text("Name too short", 400)
}
if (name.length > 100) {
return c.text("Name too long (max 100)", 400)
}
// check domain, generate random domain
if (!domain || !c.env.DOMAINS.includes(domain)) {
domain = c.env.DOMAINS[Math.floor(Math.random() * c.env.DOMAINS.length)];