同步支持动态更新取件码长度,调整存量取件码以适配新长度并优化相关逻辑和文档。
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"FileRelay/internal/bootstrap"
|
||||
"FileRelay/internal/config"
|
||||
"FileRelay/internal/model"
|
||||
"FileRelay/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -51,9 +52,21 @@ func (h *ConfigHandler) UpdateConfig(c *gin.Context) {
|
||||
newConfig.Database.Path = config.GlobalConfig.Database.Path
|
||||
}
|
||||
|
||||
// 检查取件码长度是否变化
|
||||
pickupCodeLengthChanged := newConfig.Security.PickupCodeLength != config.GlobalConfig.Security.PickupCodeLength && newConfig.Security.PickupCodeLength > 0
|
||||
|
||||
// 更新内存配置
|
||||
config.UpdateGlobalConfig(&newConfig)
|
||||
|
||||
// 如果长度变化,同步更新现有取件码
|
||||
if pickupCodeLengthChanged {
|
||||
batchService := service.NewBatchService()
|
||||
if err := batchService.UpdateAllPickupCodes(newConfig.Security.PickupCodeLength); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, model.ErrorResponse(model.CodeInternalError, "Failed to update existing pickup codes: "+err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 重新初始化存储(热更新业务逻辑)
|
||||
if err := bootstrap.ReloadStorage(); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, model.ErrorResponse(model.CodeInternalError, "Failed to reload storage: "+err.Error()))
|
||||
|
||||
Reference in New Issue
Block a user