feat: establish core backend API server with S2A proxy, configuration, and mail services, alongside frontend email configuration page and toast component.
This commit is contained in:
@@ -355,7 +355,61 @@ func handleMailServices(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
api.Success(w, safeServices)
|
||||
case "POST":
|
||||
api.Error(w, http.StatusNotImplemented, "更新邮箱服务配置暂未实现")
|
||||
var req struct {
|
||||
Services []struct {
|
||||
Name string `json:"name"`
|
||||
APIBase string `json:"apiBase"`
|
||||
APIToken string `json:"apiToken"`
|
||||
Domain string `json:"domain"`
|
||||
EmailPath string `json:"emailPath"`
|
||||
AddUserAPI string `json:"addUserApi"`
|
||||
} `json:"services"`
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
logger.Error(fmt.Sprintf("解析邮箱服务配置失败: %v", err), "", "mail")
|
||||
api.Error(w, http.StatusBadRequest, "解析请求失败")
|
||||
return
|
||||
}
|
||||
|
||||
// 转换为 config.MailServiceConfig
|
||||
var services []config.MailServiceConfig
|
||||
for _, s := range req.Services {
|
||||
emailPath := s.EmailPath
|
||||
if emailPath == "" {
|
||||
emailPath = "/api/public/emailList"
|
||||
}
|
||||
addUserAPI := s.AddUserAPI
|
||||
if addUserAPI == "" {
|
||||
addUserAPI = "/api/public/addUser"
|
||||
}
|
||||
services = append(services, config.MailServiceConfig{
|
||||
Name: s.Name,
|
||||
APIBase: s.APIBase,
|
||||
APIToken: s.APIToken,
|
||||
Domain: s.Domain,
|
||||
EmailPath: emailPath,
|
||||
AddUserAPI: addUserAPI,
|
||||
})
|
||||
}
|
||||
|
||||
// 更新邮箱服务配置
|
||||
mail.Init(services)
|
||||
|
||||
// 保存到全局配置
|
||||
if config.Global != nil {
|
||||
config.Global.MailServices = services
|
||||
}
|
||||
|
||||
logger.Success(fmt.Sprintf("邮箱服务配置已保存: %d 个服务", len(services)), "", "mail")
|
||||
for _, s := range services {
|
||||
logger.Info(fmt.Sprintf(" - %s (%s) @ %s", s.Name, s.Domain, s.APIBase), "", "mail")
|
||||
}
|
||||
|
||||
api.Success(w, map[string]interface{}{
|
||||
"message": fmt.Sprintf("已保存 %d 个邮箱服务配置", len(services)),
|
||||
"count": len(services),
|
||||
})
|
||||
default:
|
||||
api.Error(w, http.StatusMethodNotAllowed, "不支持的方法")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user