Fix initial setup issue issues (#1380)

* Refactor initial setup behaviour
* Adjust wizard
This commit is contained in:
WithoutPants
2021-05-13 22:15:21 +10:00
committed by GitHub
parent 5a37e6cf52
commit e0623eb302
6 changed files with 133 additions and 34 deletions

View File

@@ -141,7 +141,9 @@ func (e MissingConfigError) Error() string {
return fmt.Sprintf("missing the following mandatory settings: %s", strings.Join(e.missingFields, ", "))
}
type Instance struct{}
type Instance struct {
isNewSystem bool
}
var instance *Instance
@@ -152,6 +154,10 @@ func GetInstance() *Instance {
return instance
}
func (i *Instance) IsNewSystem() bool {
return i.isNewSystem
}
func (i *Instance) SetConfigFile(fn string) {
viper.SetConfigFile(fn)
}
@@ -687,29 +693,26 @@ func (i *Instance) Validate() error {
return nil
}
func (i *Instance) setDefaultValues() {
func (i *Instance) setDefaultValues() error {
viper.SetDefault(ParallelTasks, parallelTasksDefault)
viper.SetDefault(PreviewSegmentDuration, previewSegmentDurationDefault)
viper.SetDefault(PreviewSegments, previewSegmentsDefault)
viper.SetDefault(PreviewExcludeStart, previewExcludeStartDefault)
viper.SetDefault(PreviewExcludeEnd, previewExcludeEndDefault)
// #1356 - only set these defaults once config file exists
if i.GetConfigFile() != "" {
viper.SetDefault(Database, i.GetDefaultDatabaseFilePath())
viper.SetDefault(Database, i.GetDefaultDatabaseFilePath())
// Set generated to the metadata path for backwards compat
viper.SetDefault(Generated, viper.GetString(Metadata))
// Set generated to the metadata path for backwards compat
viper.SetDefault(Generated, viper.GetString(Metadata))
// Set default scrapers and plugins paths
viper.SetDefault(ScrapersPath, i.GetDefaultScrapersPath())
viper.SetDefault(PluginsPath, i.GetDefaultPluginsPath())
viper.WriteConfig()
}
// Set default scrapers and plugins paths
viper.SetDefault(ScrapersPath, i.GetDefaultScrapersPath())
viper.SetDefault(PluginsPath, i.GetDefaultPluginsPath())
return viper.WriteConfig()
}
// SetInitialConfig fills in missing required config fields
func (i *Instance) SetInitialConfig() {
func (i *Instance) SetInitialConfig() error {
// generate some api keys
const apiKeyLength = 32
@@ -723,5 +726,9 @@ func (i *Instance) SetInitialConfig() {
i.Set(SessionStoreKey, sessionStoreKey)
}
i.setDefaultValues()
return i.setDefaultValues()
}
func (i *Instance) FinalizeSetup() {
i.isNewSystem = false
}