mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-06-08 00:51:00 +08:00
feat(address): 支持最大地址数量设置为 0 表示无限制 (#968)
* feat(address): 支持最大地址数量设置为 0 表示无限制 - 移除角色配置中 =0 时回退到全局设置的逻辑 - 添加负数校验防止无效输入 - 更新前端文案说明 0 表示无限制 * fix(admin): 修复 maxAddressCount 验证逻辑,禁止负数和非对象输入 在 saveRoleAddressConfig 接口增加 configs 参数类型校验, 确保其为有效对象而非数组或 null。同时在 UserSettings 模型中 验证 maxAddressCount 必须大于等于 0,防止无效数据进入系统。 * style: 修正错误的缩进
This commit is contained in:
@@ -181,7 +181,16 @@ export default {
|
||||
return c.json({ configs });
|
||||
},
|
||||
saveRoleAddressConfig: async (c: Context<HonoCustomType>) => {
|
||||
const msgs = i18n.getMessagesbyContext(c);
|
||||
const { configs } = await c.req.json<{ configs: RoleAddressConfig }>();
|
||||
if (typeof configs !== "object" || configs === null || Array.isArray(configs)) {
|
||||
return c.text(msgs.InvalidMaxAddressCountMsg, 400);
|
||||
}
|
||||
for (const config of Object.values(configs)) {
|
||||
if (typeof config?.maxAddressCount === "number" && config.maxAddressCount < 0) {
|
||||
return c.text(msgs.InvalidMaxAddressCountMsg, 400);
|
||||
}
|
||||
}
|
||||
await saveSetting(c, CONSTANTS.ROLE_ADDRESS_CONFIG_KEY, JSON.stringify(configs));
|
||||
return c.json({ success: true });
|
||||
},
|
||||
|
||||
@@ -113,7 +113,7 @@ export class UserSettings {
|
||||
this.verifyMailSender = verifyMailSender;
|
||||
this.enableMailAllowList = enableMailAllowList;
|
||||
this.mailAllowList = mailAllowList;
|
||||
this.maxAddressCount = maxAddressCount || 5;
|
||||
this.maxAddressCount = (typeof maxAddressCount === "number" && maxAddressCount >= 0) ? maxAddressCount : 5;
|
||||
this.enableEmailCheckRegex = enableEmailCheckRegex;
|
||||
this.emailCheckRegex = emailCheckRegex;
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ export const getMaxAddressCount = async (
|
||||
if (!roleConfigs) return settings.maxAddressCount;
|
||||
const roleMaxCount = roleConfigs[userRole]?.maxAddressCount;
|
||||
if (typeof roleMaxCount !== 'number') return settings.maxAddressCount;
|
||||
if (roleMaxCount <= 0) return settings.maxAddressCount;
|
||||
if (roleMaxCount < 0) return settings.maxAddressCount;
|
||||
return roleMaxCount;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user