fix gitea workflow path and runner label
Build docker and publish / build (20.15.1) (push) Failing after 8m21s

This commit is contained in:
2026-03-04 06:33:14 -08:00
parent 6c8f22adc8
commit a01570b59d
22 changed files with 1153 additions and 92 deletions
+29 -12
View File
@@ -13,6 +13,7 @@ import (
"github.com/hibiken/asynq"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/pkg/constant"
"github.com/perfect-panel/server/pkg/email"
"github.com/perfect-panel/server/queue/types"
)
@@ -49,9 +50,6 @@ func (l *SendEmailLogic) ProcessTask(ctx context.Context, task *asynq.Task) erro
var content string
switch payload.Type {
case types.EmailTypeVerify:
tplStr := l.svcCtx.Config.Email.VerifyEmailTemplate
// 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 {
@@ -59,18 +57,14 @@ func (l *SendEmailLogic) ProcessTask(ctx context.Context, task *asynq.Task) erro
}
typeVal, _ := payload.Content["Type"].(int)
scene := resolveVerifyScene(payload.Scene, typeVal)
tplStr := selectVerifyTemplate(l.svcCtx.Config.Email.VerifyEmailTemplates, l.svcCtx.Config.Email.VerifyEmailTemplate, scene)
// 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 &&
if tplStr == l.svcCtx.Config.Email.VerifyEmailTemplate &&
scene == constant.DeleteAccount.String() &&
!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 {
logger.WithContext(ctx).Infow("[SendEmailLogic] configured legacy verify template may not support DeleteAccount, fallback to default template")
tplStr = email.DefaultEmailVerifyTemplate
}
@@ -189,3 +183,26 @@ func (l *SendEmailLogic) ProcessTask(ctx context.Context, task *asynq.Task) erro
}
return nil
}
func resolveVerifyScene(scene string, typeVal int) string {
scene = strings.ToLower(strings.TrimSpace(scene))
if scene != "" {
return scene
}
return constant.ParseVerifyType(uint8(typeVal)).String()
}
func selectVerifyTemplate(sceneTemplates map[string]string, legacyTemplate string, scene string) string {
if sceneTemplates != nil {
if tpl := strings.TrimSpace(sceneTemplates[scene]); tpl != "" {
return tpl
}
if tpl := strings.TrimSpace(sceneTemplates["default"]); tpl != "" {
return tpl
}
}
if strings.TrimSpace(legacyTemplate) != "" {
return legacyTemplate
}
return email.DefaultEmailVerifyTemplate
}
+28
View File
@@ -0,0 +1,28 @@
package emailLogic
import (
"testing"
"github.com/perfect-panel/server/pkg/constant"
"github.com/perfect-panel/server/pkg/email"
"github.com/stretchr/testify/assert"
)
func TestSelectVerifyTemplate(t *testing.T) {
sceneTemplates := map[string]string{
"default": "DEFAULT_TEMPLATE",
"register": "REGISTER_TEMPLATE",
"delete_account": "DELETE_TEMPLATE",
}
assert.Equal(t, "REGISTER_TEMPLATE", selectVerifyTemplate(sceneTemplates, "LEGACY_TEMPLATE", "register"))
assert.Equal(t, "DEFAULT_TEMPLATE", selectVerifyTemplate(sceneTemplates, "LEGACY_TEMPLATE", "security"))
assert.Equal(t, "LEGACY_TEMPLATE", selectVerifyTemplate(nil, "LEGACY_TEMPLATE", "security"))
assert.Equal(t, email.DefaultEmailVerifyTemplate, selectVerifyTemplate(nil, "", "security"))
}
func TestResolveVerifyScene(t *testing.T) {
assert.Equal(t, "register", resolveVerifyScene("register", 0))
assert.Equal(t, constant.DeleteAccount.String(), resolveVerifyScene("", int(constant.DeleteAccount)))
assert.Equal(t, "unknown", resolveVerifyScene("", 99))
}
+1
View File
@@ -16,6 +16,7 @@ const (
type (
SendEmailPayload struct {
Type string `json:"type"`
Scene string `json:"scene,omitempty"`
Email string `json:"to"`
Subject string `json:"subject"`
Content map[string]interface{} `json:"content"`