mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-07 04:20:12 +02:00
feat(nordvpn): filter with SERVER_CATEGORIES (#1806)
- update NordVPN servers data built-in
This commit is contained in:
@@ -61,6 +61,10 @@ func filterServer(server models.Server,
|
||||
return true
|
||||
}
|
||||
|
||||
if filterAnyByPossibilities(server.Categories, selection.Categories) {
|
||||
return true
|
||||
}
|
||||
|
||||
if filterByPossibilities(server.Region, selection.Regions) {
|
||||
return true
|
||||
}
|
||||
@@ -101,3 +105,17 @@ func filterByPossibilities[T string | uint16](value T, possibilities []T) (filte
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func filterAnyByPossibilities(values, possibilities []string) (filtered bool) {
|
||||
if len(possibilities) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, value := range values {
|
||||
if !filterByPossibilities(value, possibilities) {
|
||||
return false // found a valid value
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -179,6 +179,19 @@ func Test_FilterServers(t *testing.T) {
|
||||
{City: "b", VPN: vpn.OpenVPN, UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by category": {
|
||||
selection: settings.ServerSelection{
|
||||
Categories: []string{"legacy_p2p"},
|
||||
}.WithDefaults(providers.Nordvpn),
|
||||
servers: []models.Server{
|
||||
{Categories: []string{"legacy_p2p"}, VPN: vpn.OpenVPN, UDP: true},
|
||||
{Categories: []string{"legacy_standard"}, VPN: vpn.OpenVPN, UDP: true},
|
||||
{VPN: vpn.OpenVPN, UDP: true},
|
||||
},
|
||||
filtered: []models.Server{
|
||||
{Categories: []string{"legacy_p2p"}, VPN: vpn.OpenVPN, UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by ISP": {
|
||||
selection: settings.ServerSelection{
|
||||
ISPs: []string{"b"},
|
||||
|
||||
Reference in New Issue
Block a user