all: sync with master
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
"github.com/AdguardTeam/golibs/logutil/slogutil"
|
||||
"github.com/google/renameio/v2/maybe"
|
||||
)
|
||||
@@ -22,20 +23,19 @@ func main() {
|
||||
l := slogutil.New(nil)
|
||||
|
||||
urlStr := "https://adguardteam.github.io/HostlistsRegistry/assets/filters.json"
|
||||
if v, ok := os.LookupEnv("URL"); ok {
|
||||
urlStr = v
|
||||
if s := os.Getenv("URL"); s != "" {
|
||||
urlStr = s
|
||||
}
|
||||
|
||||
// Validate the URL.
|
||||
_, err := url.Parse(urlStr)
|
||||
check(err)
|
||||
errors.Check(err)
|
||||
|
||||
c := &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
resp, err := c.Get(urlStr)
|
||||
check(err)
|
||||
resp := errors.Must(c.Get(urlStr))
|
||||
defer slogutil.CloseAndLog(ctx, l, resp.Body, slog.LevelError)
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
|
||||
hlFlt := &hlFilters{}
|
||||
err = json.NewDecoder(resp.Body).Decode(hlFlt)
|
||||
check(err)
|
||||
errors.Check(err)
|
||||
|
||||
aghFlt := &aghFilters{
|
||||
Categories: map[string]*aghFiltersCategory{
|
||||
@@ -93,11 +93,10 @@ func main() {
|
||||
enc := json.NewEncoder(buf)
|
||||
enc.SetIndent("", " ")
|
||||
|
||||
err = enc.Encode(aghFlt)
|
||||
check(err)
|
||||
errors.Check(enc.Encode(aghFlt))
|
||||
|
||||
err = maybe.WriteFile("client/src/helpers/filters/filters.ts", buf.Bytes(), 0o644)
|
||||
check(err)
|
||||
errors.Check(err)
|
||||
}
|
||||
|
||||
// jsHeader is the header for the generated JavaScript file. It informs the
|
||||
@@ -109,13 +108,6 @@ const jsHeader = `// Code generated by go run ./scripts/vetted-filters/main.go;
|
||||
|
||||
export default `
|
||||
|
||||
// check is a simple error-checking helper for scripts.
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// hlFilters is the JSON structure for the Hostlists Registry rule list index.
|
||||
type hlFilters struct {
|
||||
Filters []*hlFiltersFilter `json:"filters"`
|
||||
|
||||
Reference in New Issue
Block a user