home: imp code
This commit is contained in:
parent
a700bfb42e
commit
a09cd190c0
|
@ -20,6 +20,7 @@ type Client struct {
|
||||||
// upstream must be used.
|
// upstream must be used.
|
||||||
upstreamConfig *proxy.CustomUpstreamConfig
|
upstreamConfig *proxy.CustomUpstreamConfig
|
||||||
|
|
||||||
|
// TODO(d.kolyshev): Make safeSearchConf a pointer.
|
||||||
safeSearchConf filtering.SafeSearchConfig
|
safeSearchConf filtering.SafeSearchConfig
|
||||||
SafeSearch filtering.SafeSearch
|
SafeSearch filtering.SafeSearch
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ func (clients *clientsContainer) jsonToClient(cj clientJSON, prev *Client) (c *C
|
||||||
upsCacheSize = prev.UpstreamsCacheSize
|
upsCacheSize = prev.UpstreamsCacheSize
|
||||||
}
|
}
|
||||||
|
|
||||||
bs, err := copyBlockedServices(cj.Schedule, cj.BlockedServices, prev)
|
svcs, err := copyBlockedServices(cj.Schedule, cj.BlockedServices, prev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid blocked services: %w", err)
|
return nil, fmt.Errorf("invalid blocked services: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func (clients *clientsContainer) jsonToClient(cj clientJSON, prev *Client) (c *C
|
||||||
|
|
||||||
Name: cj.Name,
|
Name: cj.Name,
|
||||||
|
|
||||||
BlockedServices: bs,
|
BlockedServices: svcs,
|
||||||
|
|
||||||
IDs: cj.IDs,
|
IDs: cj.IDs,
|
||||||
Tags: cj.Tags,
|
Tags: cj.Tags,
|
||||||
|
@ -184,41 +184,41 @@ func (clients *clientsContainer) jsonToClient(cj clientJSON, prev *Client) (c *C
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// copySafeSearch returns safe search config copied from provided parameters.
|
// copySafeSearch returns safe search config created from provided parameters.
|
||||||
func copySafeSearch(
|
func copySafeSearch(
|
||||||
conf *filtering.SafeSearchConfig,
|
jsonConf *filtering.SafeSearchConfig,
|
||||||
enabled bool,
|
enabled bool,
|
||||||
) (safeSearchConf filtering.SafeSearchConfig) {
|
) (conf filtering.SafeSearchConfig) {
|
||||||
if conf != nil {
|
if jsonConf != nil {
|
||||||
safeSearchConf = *conf
|
return *jsonConf
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// TODO(d.kolyshev): Remove after cleaning the deprecated
|
// TODO(d.kolyshev): Remove after cleaning the deprecated
|
||||||
// [clientJSON.SafeSearchEnabled] field.
|
// [clientJSON.SafeSearchEnabled] field.
|
||||||
safeSearchConf = filtering.SafeSearchConfig{
|
conf = filtering.SafeSearchConfig{
|
||||||
Enabled: enabled,
|
Enabled: enabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default service flags for enabled safesearch.
|
// Set default service flags for enabled safesearch.
|
||||||
if safeSearchConf.Enabled {
|
if conf.Enabled {
|
||||||
safeSearchConf.Bing = true
|
conf.Bing = true
|
||||||
safeSearchConf.DuckDuckGo = true
|
conf.DuckDuckGo = true
|
||||||
safeSearchConf.Google = true
|
conf.Google = true
|
||||||
safeSearchConf.Pixabay = true
|
conf.Pixabay = true
|
||||||
safeSearchConf.Yandex = true
|
conf.Yandex = true
|
||||||
safeSearchConf.YouTube = true
|
conf.YouTube = true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return safeSearchConf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyBlockedServices converts a json blocked services to an internal blocked
|
// copyBlockedServices converts a json blocked services to an internal blocked
|
||||||
// services.
|
// services.
|
||||||
func copyBlockedServices(
|
func copyBlockedServices(
|
||||||
sch *schedule.Weekly,
|
sch *schedule.Weekly,
|
||||||
blockedSvc []string,
|
svcStrs []string,
|
||||||
prev *Client,
|
prev *Client,
|
||||||
) (bs *filtering.BlockedServices, err error) {
|
) (svcs *filtering.BlockedServices, err error) {
|
||||||
var weekly *schedule.Weekly
|
var weekly *schedule.Weekly
|
||||||
if sch != nil {
|
if sch != nil {
|
||||||
weekly = sch.Clone()
|
weekly = sch.Clone()
|
||||||
|
@ -228,17 +228,17 @@ func copyBlockedServices(
|
||||||
weekly = schedule.EmptyWeekly()
|
weekly = schedule.EmptyWeekly()
|
||||||
}
|
}
|
||||||
|
|
||||||
bs = &filtering.BlockedServices{
|
svcs = &filtering.BlockedServices{
|
||||||
Schedule: weekly,
|
Schedule: weekly,
|
||||||
IDs: blockedSvc,
|
IDs: svcStrs,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bs.Validate()
|
err = svcs.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("validating blocked services: %w", err)
|
return nil, fmt.Errorf("validating blocked services: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return bs, nil
|
return svcs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// clientToJSON converts Client object to JSON.
|
// clientToJSON converts Client object to JSON.
|
||||||
|
|
Loading…
Reference in New Issue