mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-10 09:40:11 +03:00
Pull request 2286: AGDNS-2374-slog-safesearch
Squashed commit of the following: commit 1909dfed99b8815c1215c709efcae77a70b52ea3 Merge:3856fda5f
2c64ab5a5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Oct 9 16:21:38 2024 +0300 Merge branch 'master' into AGDNS-2374-slog-safesearch commit3856fda5f3
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Oct 8 20:04:34 2024 +0300 home: imp code commitde774009aa
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Oct 7 16:41:58 2024 +0300 all: imp code commit038bae59d5
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 20:24:48 2024 +0300 all: imp code commit792975e248
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Oct 3 15:46:40 2024 +0300 all: slog safesearch
This commit is contained in:
parent
2c64ab5a51
commit
6363f8a2e7
12 changed files with 237 additions and 122 deletions
internal/home
|
@ -1,6 +1,7 @@
|
|||
package home
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -10,8 +11,10 @@ import (
|
|||
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/client"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/schedule"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/whois"
|
||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||
)
|
||||
|
||||
// clientJSON is a common structure used by several handlers to deal with
|
||||
|
@ -181,6 +184,7 @@ func initPrev(cj clientJSON, prev *client.Persistent) (c *client.Persistent, err
|
|||
// jsonToClient converts JSON object to persistent client object if there are no
|
||||
// errors.
|
||||
func (clients *clientsContainer) jsonToClient(
|
||||
ctx context.Context,
|
||||
cj clientJSON,
|
||||
prev *client.Persistent,
|
||||
) (c *client.Persistent, err error) {
|
||||
|
@ -207,14 +211,23 @@ func (clients *clientsContainer) jsonToClient(
|
|||
c.UseOwnBlockedServices = !cj.UseGlobalBlockedServices
|
||||
|
||||
if c.SafeSearchConf.Enabled {
|
||||
err = c.SetSafeSearch(
|
||||
c.SafeSearchConf,
|
||||
clients.safeSearchCacheSize,
|
||||
clients.safeSearchCacheTTL,
|
||||
logger := clients.baseLogger.With(
|
||||
slogutil.KeyPrefix, safesearch.LogPrefix,
|
||||
safesearch.LogKeyClient, c.Name,
|
||||
)
|
||||
var ss *safesearch.Default
|
||||
ss, err = safesearch.NewDefault(ctx, &safesearch.DefaultConfig{
|
||||
Logger: logger,
|
||||
ServicesConfig: c.SafeSearchConf,
|
||||
ClientName: c.Name,
|
||||
CacheSize: clients.safeSearchCacheSize,
|
||||
CacheTTL: clients.safeSearchCacheTTL,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("creating safesearch for client %q: %w", c.Name, err)
|
||||
}
|
||||
|
||||
c.SafeSearch = ss
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
@ -321,7 +334,7 @@ func (clients *clientsContainer) handleAddClient(w http.ResponseWriter, r *http.
|
|||
return
|
||||
}
|
||||
|
||||
c, err := clients.jsonToClient(cj, nil)
|
||||
c, err := clients.jsonToClient(r.Context(), cj, nil)
|
||||
if err != nil {
|
||||
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
|
||||
|
||||
|
@ -391,7 +404,7 @@ func (clients *clientsContainer) handleUpdateClient(w http.ResponseWriter, r *ht
|
|||
return
|
||||
}
|
||||
|
||||
c, err := clients.jsonToClient(dj.Data, nil)
|
||||
c, err := clients.jsonToClient(r.Context(), dj.Data, nil)
|
||||
if err != nil {
|
||||
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue