2020-08-10 13:18:04 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
type SyncAPI struct {
|
|
|
|
Matrix *Global `yaml:"-"`
|
|
|
|
|
2022-09-01 13:15:41 +00:00
|
|
|
Database DatabaseOptions `yaml:"database,omitempty"`
|
2020-11-20 11:29:02 +00:00
|
|
|
|
|
|
|
RealIPHeader string `yaml:"real_ip_header"`
|
2022-09-07 16:15:54 +00:00
|
|
|
|
2022-09-27 16:06:49 +00:00
|
|
|
Fulltext Fulltext `yaml:"search"`
|
2020-08-10 13:18:04 +00:00
|
|
|
}
|
|
|
|
|
2022-09-01 13:15:41 +00:00
|
|
|
func (c *SyncAPI) Defaults(opts DefaultOpts) {
|
2022-09-07 16:15:54 +00:00
|
|
|
c.Fulltext.Defaults(opts)
|
2022-09-01 13:15:41 +00:00
|
|
|
if opts.Generate {
|
2023-02-14 11:47:47 +00:00
|
|
|
if !opts.SingleDatabase {
|
2022-09-01 13:15:41 +00:00
|
|
|
c.Database.ConnectionString = "file:syncapi.db"
|
|
|
|
}
|
2021-11-24 11:57:39 +00:00
|
|
|
}
|
2020-08-10 13:18:04 +00:00
|
|
|
}
|
|
|
|
|
2023-02-14 11:47:47 +00:00
|
|
|
func (c *SyncAPI) Verify(configErrs *ConfigErrors) {
|
|
|
|
c.Fulltext.Verify(configErrs)
|
2022-09-01 13:15:41 +00:00
|
|
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
|
|
|
checkNotEmpty(configErrs, "sync_api.database", string(c.Database.ConnectionString))
|
|
|
|
}
|
2020-08-10 13:18:04 +00:00
|
|
|
}
|
2022-09-07 16:15:54 +00:00
|
|
|
|
|
|
|
type Fulltext struct {
|
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
IndexPath Path `yaml:"index_path"`
|
|
|
|
InMemory bool `yaml:"in_memory"` // only useful in tests
|
|
|
|
Language string `yaml:"language"` // the language to use when analysing content
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fulltext) Defaults(opts DefaultOpts) {
|
|
|
|
f.Enabled = false
|
2022-09-27 16:10:47 +00:00
|
|
|
f.IndexPath = "./searchindex"
|
2022-09-07 16:15:54 +00:00
|
|
|
f.Language = "en"
|
|
|
|
}
|
|
|
|
|
2023-02-14 11:47:47 +00:00
|
|
|
func (f *Fulltext) Verify(configErrs *ConfigErrors) {
|
2022-09-09 15:19:29 +00:00
|
|
|
if !f.Enabled {
|
|
|
|
return
|
|
|
|
}
|
2022-09-27 16:06:49 +00:00
|
|
|
checkNotEmpty(configErrs, "syncapi.search.index_path", string(f.IndexPath))
|
|
|
|
checkNotEmpty(configErrs, "syncapi.search.language", f.Language)
|
2022-09-07 16:15:54 +00:00
|
|
|
}
|