feat: add adminContact && DEFAULT_SEND_BALANCE (#162)

This commit is contained in:
Dream Hunter
2024-04-26 00:21:43 +08:00
committed by GitHub
parent b058a1bd12
commit f624fe5b58
17 changed files with 175 additions and 110 deletions
+1
View File
@@ -146,6 +146,7 @@ api.get('/open_api/settings', async (c) => {
"prefix": c.env.PREFIX,
"domains": getDomains(c),
"needAuth": needAuth,
"adminContact": c.env.ADMIN_CONTACT,
});
})
+5 -2
View File
@@ -8,9 +8,12 @@ api.post('/api/requset_send_mail_access', async (c) => {
return c.text("No address", 400)
}
try {
const default_balance = c.env.DEFAULT_SEND_BALANCE || 0;
const { success } = await c.env.DB.prepare(
`INSERT INTO address_sender (address, balance, enabled) VALUES (?, 1, 1)`
).bind(address).run();
`INSERT INTO address_sender (address, balance, enabled) VALUES (?, ?, ?)`
).bind(
address, default_balance, default_balance > 0 ? 1 : 0
).run();
if (!success) {
return c.text("Failed to request send mail access", 500)
}
+3 -2
View File
@@ -23,13 +23,14 @@ export const getPasswords = (c) => {
// check if PASSWORDS is an array, if not use json.parse
if (!Array.isArray(c.env.PASSWORDS)) {
try {
return JSON.parse(c.env.PASSWORDS);
let res = JSON.parse(c.env.PASSWORDS);
return res.filter((item) => item.length > 0);
} catch (e) {
console.error("Failed to parse PASSWORDS", e);
return [];
}
}
return c.env.PASSWORDS;
return c.env.PASSWORDS.filter((item) => item.length > 0);
}
export const getAdminPasswords = (c) => {