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

This commit is contained in:
2026-03-04 03:03:51 -08:00
parent 0c544268e5
commit 6c370485d1
14 changed files with 197 additions and 35 deletions
@@ -0,0 +1,47 @@
INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
SELECT 'verify_code',
'ExpireTime',
COALESCE(MAX(CASE WHEN `key` = 'VerifyCodeExpireTime' THEN `value` END), '900'),
'int',
'Verify code expire time (legacy)',
NOW(3),
NOW(3)
FROM `system`
WHERE `category` = 'verify_code'
ON DUPLICATE KEY UPDATE
`value` = VALUES(`value`),
`type` = VALUES(`type`),
`desc` = VALUES(`desc`),
`updated_at` = VALUES(`updated_at`);
INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
SELECT 'verify_code',
'Limit',
COALESCE(MAX(CASE WHEN `key` = 'VerifyCodeLimit' THEN `value` END), '15'),
'int',
'Verify code limit (legacy)',
NOW(3),
NOW(3)
FROM `system`
WHERE `category` = 'verify_code'
ON DUPLICATE KEY UPDATE
`value` = VALUES(`value`),
`type` = VALUES(`type`),
`desc` = VALUES(`desc`),
`updated_at` = VALUES(`updated_at`);
INSERT INTO `system` (`category`, `key`, `value`, `type`, `desc`, `created_at`, `updated_at`)
SELECT 'verify_code',
'Interval',
COALESCE(MAX(CASE WHEN `key` = 'VerifyCodeInterval' THEN `value` END), '60'),
'int',
'Verify code interval (legacy)',
NOW(3),
NOW(3)
FROM `system`
WHERE `category` = 'verify_code'
ON DUPLICATE KEY UPDATE
`value` = VALUES(`value`),
`type` = VALUES(`type`),
`desc` = VALUES(`desc`),
`updated_at` = VALUES(`updated_at`);
@@ -0,0 +1,4 @@
DELETE
FROM `system`
WHERE `category` = 'verify_code'
AND `key` IN ('ExpireTime', 'Limit', 'Interval');
+17
View File
@@ -44,5 +44,22 @@ func Verify(svc *svc.ServiceContext) {
return
}
tool.SystemConfigSliceReflectToStruct(cfg, &verifyCodeConfig)
applyVerifyCodeDefaults(&verifyCodeConfig)
svc.Config.VerifyCode = verifyCodeConfig
}
func applyVerifyCodeDefaults(cfg *config.VerifyCode) {
if cfg == nil {
return
}
if cfg.VerifyCodeExpireTime <= 0 {
cfg.VerifyCodeExpireTime = 900
}
if cfg.VerifyCodeLimit <= 0 {
cfg.VerifyCodeLimit = 15
}
if cfg.VerifyCodeInterval <= 0 {
cfg.VerifyCodeInterval = 60
}
}
+94
View File
@@ -0,0 +1,94 @@
package initialize
import (
"testing"
"github.com/perfect-panel/server/internal/config"
"github.com/perfect-panel/server/internal/model/system"
"github.com/perfect-panel/server/pkg/tool"
"github.com/stretchr/testify/assert"
)
func TestApplyVerifyCodeDefaults(t *testing.T) {
testCases := []struct {
name string
in config.VerifyCode
want config.VerifyCode
}{
{
name: "apply defaults when all zero",
in: config.VerifyCode{},
want: config.VerifyCode{
VerifyCodeExpireTime: 900,
VerifyCodeLimit: 15,
VerifyCodeInterval: 60,
},
},
{
name: "keep provided values",
in: config.VerifyCode{
VerifyCodeExpireTime: 901,
VerifyCodeLimit: 16,
VerifyCodeInterval: 61,
},
want: config.VerifyCode{
VerifyCodeExpireTime: 901,
VerifyCodeLimit: 16,
VerifyCodeInterval: 61,
},
},
{
name: "fix invalid non-positive values",
in: config.VerifyCode{
VerifyCodeExpireTime: -1,
VerifyCodeLimit: 0,
VerifyCodeInterval: -10,
},
want: config.VerifyCode{
VerifyCodeExpireTime: 900,
VerifyCodeLimit: 15,
VerifyCodeInterval: 60,
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
got := testCase.in
applyVerifyCodeDefaults(&got)
assert.Equal(t, testCase.want, got)
})
}
}
func TestVerifyCodeReflectUsesCanonicalKeys(t *testing.T) {
configs := []*system.System{
{Category: "verify_code", Key: "VerifyCodeExpireTime", Value: "901"},
{Category: "verify_code", Key: "VerifyCodeLimit", Value: "16"},
{Category: "verify_code", Key: "VerifyCodeInterval", Value: "61"},
}
var got config.VerifyCode
tool.SystemConfigSliceReflectToStruct(configs, &got)
applyVerifyCodeDefaults(&got)
assert.Equal(t, int64(901), got.VerifyCodeExpireTime)
assert.Equal(t, int64(16), got.VerifyCodeLimit)
assert.Equal(t, int64(61), got.VerifyCodeInterval)
}
func TestVerifyCodeReflectIgnoresLegacyKeys(t *testing.T) {
configs := []*system.System{
{Category: "verify_code", Key: "ExpireTime", Value: "901"},
{Category: "verify_code", Key: "Limit", Value: "16"},
{Category: "verify_code", Key: "Interval", Value: "61"},
}
var got config.VerifyCode
tool.SystemConfigSliceReflectToStruct(configs, &got)
applyVerifyCodeDefaults(&got)
assert.Equal(t, int64(900), got.VerifyCodeExpireTime)
assert.Equal(t, int64(15), got.VerifyCodeLimit)
assert.Equal(t, int64(60), got.VerifyCodeInterval)
}