(ctx context.Context, config types.SM, driveUtils drive_util.DriveUtils)
| 89 | } |
| 90 | |
| 91 | func 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 |
nothing calls this directly
no test coverage detected