同步历史版本代码
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
@@ -48,10 +49,33 @@ func (l *SendEmailLogic) ProcessTask(ctx context.Context, task *asynq.Task) erro
|
||||
var content string
|
||||
switch payload.Type {
|
||||
case types.EmailTypeVerify:
|
||||
tpl, _ := template.New("verify").Parse(l.svcCtx.Config.Email.VerifyEmailTemplate)
|
||||
var result bytes.Buffer
|
||||
tplStr := l.svcCtx.Config.Email.VerifyEmailTemplate
|
||||
|
||||
payload.Content["Type"] = uint8(payload.Content["Type"].(float64))
|
||||
// Use int for better template compatibility
|
||||
if t, ok := payload.Content["Type"].(float64); ok {
|
||||
payload.Content["Type"] = int(t)
|
||||
} else if t, ok := payload.Content["Type"].(int); ok {
|
||||
payload.Content["Type"] = t
|
||||
}
|
||||
|
||||
typeVal, _ := payload.Content["Type"].(int)
|
||||
|
||||
// Smart Fallback: If template is empty OR (Type is 4 but template doesn't support it), use default
|
||||
// We check for "Type 4" or "Type eq 4" string in the template as a heuristic
|
||||
needDefault := tplStr == ""
|
||||
if !needDefault && typeVal == 4 &&
|
||||
!strings.Contains(tplStr, "Type 4") &&
|
||||
!strings.Contains(tplStr, "Type eq 4") {
|
||||
logger.WithContext(ctx).Infow("[SendEmailLogic] Configured template might not support DeleteAccount (Type 4), forcing default template")
|
||||
needDefault = true
|
||||
}
|
||||
|
||||
if needDefault {
|
||||
tplStr = email.DefaultEmailVerifyTemplate
|
||||
}
|
||||
|
||||
tpl, _ := template.New("verify").Parse(tplStr)
|
||||
var result bytes.Buffer
|
||||
|
||||
err = tpl.Execute(&result, payload.Content)
|
||||
if err != nil {
|
||||
@@ -63,7 +87,11 @@ func (l *SendEmailLogic) ProcessTask(ctx context.Context, task *asynq.Task) erro
|
||||
}
|
||||
content = result.String()
|
||||
case types.EmailTypeMaintenance:
|
||||
tpl, _ := template.New("maintenance").Parse(l.svcCtx.Config.Email.MaintenanceEmailTemplate)
|
||||
tplStr := l.svcCtx.Config.Email.MaintenanceEmailTemplate
|
||||
if tplStr == "" {
|
||||
tplStr = email.DefaultMaintenanceEmailTemplate
|
||||
}
|
||||
tpl, _ := template.New("maintenance").Parse(tplStr)
|
||||
var result bytes.Buffer
|
||||
err = tpl.Execute(&result, payload.Content)
|
||||
if err != nil {
|
||||
@@ -76,7 +104,11 @@ func (l *SendEmailLogic) ProcessTask(ctx context.Context, task *asynq.Task) erro
|
||||
}
|
||||
content = result.String()
|
||||
case types.EmailTypeExpiration:
|
||||
tpl, _ := template.New("expiration").Parse(l.svcCtx.Config.Email.ExpirationEmailTemplate)
|
||||
tplStr := l.svcCtx.Config.Email.ExpirationEmailTemplate
|
||||
if tplStr == "" {
|
||||
tplStr = email.DefaultExpirationEmailTemplate
|
||||
}
|
||||
tpl, _ := template.New("expiration").Parse(tplStr)
|
||||
var result bytes.Buffer
|
||||
err = tpl.Execute(&result, payload.Content)
|
||||
if err != nil {
|
||||
@@ -89,7 +121,11 @@ func (l *SendEmailLogic) ProcessTask(ctx context.Context, task *asynq.Task) erro
|
||||
}
|
||||
content = result.String()
|
||||
case types.EmailTypeTrafficExceed:
|
||||
tpl, _ := template.New("traffic_exceed").Parse(l.svcCtx.Config.Email.TrafficExceedEmailTemplate)
|
||||
tplStr := l.svcCtx.Config.Email.TrafficExceedEmailTemplate
|
||||
if tplStr == "" {
|
||||
tplStr = email.DefaultTrafficExceedEmailTemplate
|
||||
}
|
||||
tpl, _ := template.New("traffic_exceed").Parse(tplStr)
|
||||
var result bytes.Buffer
|
||||
err = tpl.Execute(&result, payload.Content)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user