MCPcopy Create free account
hub / github.com/devld/go-drive / initConfig

Function initConfig

drive/script/utils.go:91–154  ·  view source on GitHub ↗
(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils)

Source from the content-addressed store, hash-verified

89}
90
91func initConfig(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils) (*drive_util.DriveInitConfig, error) {
92 selectedScript := config["script"]
93 if selectedScript == "" {
94 return nil, err.NewNotAllowedMessageError(i18n.T("drive.not_configured"))
95 }
96 selectedScript += ".js"
97
98 cfg, e := driveUtils.Data.Load("_script")
99 if e != nil {
100 return nil, e
101 }
102 if cfg["_script"] != selectedScript {
103 if e := driveUtils.Data.Clear(); e != nil {
104 return nil, e
105 }
106 }
107 if e := driveUtils.Data.Save(types.SM{"_script": selectedScript}); e != nil {
108 return nil, e
109 }
110
111 initForm := make([]types.FormItem, 0, 1)
112 values := make(types.SM)
113
114 ds, e := readDriveScriptMeta(selectedScript, driveUtils.Config)
115 if e != nil {
116 return nil, e
117 }
118 initForm = append(initForm, types.FormItem{Type: "md", Description: ds.Description})
119
120 retCfg := &drive_util.DriveInitConfig{
121 Configured: false,
122 Form: initForm,
123 Value: values,
124 }
125
126 vm, e := createVm(ctx, driveUtils.Config, selectedScript)
127 if e != nil {
128 return nil, e
129 }
130 defer func() { _ = vm.Dispose() }()
131
132 initConfigVal, e := vm.GetValue("__driveInitConfig")
133 if e != nil {
134 return nil, e
135 }
136 if initConfigVal.IsNil() {
137 return retCfg, nil
138 }
139
140 v, e := vm.Call(ctx, "__driveInitConfig", s.NewContext(vm, ctx), config, newScriptDriveUtils(driveUtils))
141 if e != nil {
142 return nil, e
143 }
144
145 vmCfg := &drive_util.DriveInitConfig{}
146 v.ParseInto(vmCfg)
147
148 retCfg.Configured = vmCfg.Configured

Callers

nothing calls this directly

Calls 13

TFunction · 0.92
MapCopyFunction · 0.92
readDriveScriptMetaFunction · 0.85
createVmFunction · 0.85
newScriptDriveUtilsFunction · 0.85
IsNilMethod · 0.80
ParseIntoMethod · 0.80
LoadMethod · 0.65
ClearMethod · 0.65
SaveMethod · 0.65
DisposeMethod · 0.65
GetValueMethod · 0.45

Tested by

no test coverage detected