add default config
This commit is contained in:
1 parent
87f2c360c5
commit
ebf715c368
3 files changed
+38
-12
No files matched your search
+32
-1
@@ -139,13 +139,15 @@ func onReceiveRemoteConfigSchema(so socketio.Socket, msg string) string {
|
||||
logger.Warn(err)
|
||||
return errorMsg
|
||||
}
|
||||
|
||||
res, err := model.SchemaRep.GetSchemasByModulesId([]int32{module.Id})
|
||||
if err != nil {
|
||||
logger.Warn(err)
|
||||
return errorMsg
|
||||
}
|
||||
var schema *entity.ConfigSchema
|
||||
if len(res) > 0 {
|
||||
schema := &res[0]
|
||||
schema = &res[0]
|
||||
schema.Schema = s.Schema
|
||||
schema.Version = s.Version
|
||||
if _, err := model.SchemaRep.UpdateConfigSchema(schema); err != nil {
|
||||
@@ -171,6 +173,35 @@ func onReceiveRemoteConfigSchema(so socketio.Socket, msg string) string {
|
||||
}
|
||||
}
|
||||
|
||||
if len(s.DefaultConfig) == 0 {
|
||||
return okMsg
|
||||
}
|
||||
|
||||
configs, err := model.ConfigRep.GetConfigByInstanceUUIDAndModuleName(instanceUuid, moduleName)
|
||||
if err != nil {
|
||||
logger.Warn(err)
|
||||
return errorMsg
|
||||
}
|
||||
if configs != nil {
|
||||
return okMsg
|
||||
}
|
||||
config := entity.Config{
|
||||
ModuleId: module.Id,
|
||||
Name: module.Name,
|
||||
Data: s.DefaultConfig,
|
||||
Active: true,
|
||||
Version: 1,
|
||||
}
|
||||
_, err = model.ConfigRep.CreateConfig(&config)
|
||||
if err != nil {
|
||||
logger.Warn(err)
|
||||
return errorMsg
|
||||
}
|
||||
_ = so.Emit(
|
||||
utils.ConfigSendConfigWhenConnected, config.Data.ToJSON(), func(so socketio.Socket, data string) {
|
||||
logger.Debug("Client ACK with data: ", data)
|
||||
},
|
||||
)
|
||||
return okMsg
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user