feat(fastestvpn): update servers data using API instead of zip file
- Add city filter - More dynamic to servers updates on fastestvpn's end - Update servers data
This commit is contained in:
@@ -4,48 +4,26 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/common"
|
||||
"github.com/qdm12/gluetun/internal/updater/openvpn"
|
||||
)
|
||||
|
||||
func (u *Updater) FetchServers(ctx context.Context, minServers int) (
|
||||
servers []models.Server, err error) {
|
||||
const url = "https://support.fastestvpn.com/download/fastestvpn_ovpn"
|
||||
contents, err := u.unzipper.FetchAndExtract(ctx, url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if len(contents) < minServers {
|
||||
return nil, fmt.Errorf("%w: %d and expected at least %d",
|
||||
common.ErrNotEnoughServers, len(contents), minServers)
|
||||
}
|
||||
|
||||
protocols := []string{"tcp", "udp"}
|
||||
hts := make(hostToServer)
|
||||
|
||||
for fileName, content := range contents {
|
||||
if !strings.HasSuffix(fileName, ".ovpn") {
|
||||
continue // not an OpenVPN file
|
||||
}
|
||||
|
||||
country, tcp, udp, err := parseFilename(fileName)
|
||||
for _, protocol := range protocols {
|
||||
apiServers, err := fetchAPIServers(ctx, u.client, protocol)
|
||||
if err != nil {
|
||||
u.warner.Warn(err.Error())
|
||||
continue
|
||||
return nil, fmt.Errorf("fetching %s servers from API: %w", protocol, err)
|
||||
}
|
||||
|
||||
host, warning, err := openvpn.ExtractHost(content)
|
||||
if warning != "" {
|
||||
u.warner.Warn(warning)
|
||||
for _, apiServer := range apiServers {
|
||||
tcp := protocol == "tcp"
|
||||
udp := protocol == "udp"
|
||||
hts.add(apiServer.hostname, apiServer.country, apiServer.city, tcp, udp)
|
||||
}
|
||||
if err != nil {
|
||||
// treat error as warning and go to next file
|
||||
u.warner.Warn(err.Error() + " in " + fileName)
|
||||
continue
|
||||
}
|
||||
|
||||
hts.add(host, country, tcp, udp)
|
||||
}
|
||||
|
||||
if len(hts) < minServers {
|
||||
|
||||
Reference in New Issue
Block a user