optimize: remove gopeed to avoid 429

This commit is contained in:
mzz2017 committed 2022-03-13 18:04:54 +08:00
1 parent fb7eea09cd
commit c170bc4df7
7 files changed
+37 -28

No files matched your search

+10 -3
View File
@@ -60,18 +60,25 @@ func GetHttpClientWithv2rayAPac() (client *http.Client, err error) {
return GetHttpClientWithProxy("http://" + net.JoinHostPort(host, strconv.Itoa(configure.GetPortsNotNil().HttpWithPac)))
}
func GetHttpClientAutomatically() (c *http.Client, err error) {
func GetHttpClientAutomatically() (c *http.Client) {
if !v2ray.ProcessManager.Running() || configure.GetConnectedServers() == nil || v2ray.IsTransparentOn() {
return http.DefaultClient, nil
return http.DefaultClient
}
setting := configure.GetSettingNotNil()
var err error
switch setting.ProxyModeWhenSubscribe {
case configure.ProxyModePac:
c, err = GetHttpClientWithv2rayAPac()
if err != nil {
return http.DefaultClient
}
case configure.ProxyModeProxy:
c, err = GetHttpClientWithv2rayAProxy()
if err != nil {
return http.DefaultClient
}
default:
c = http.DefaultClient
}
return
return c
}
+20
View File
@@ -2,12 +2,15 @@ package asset
import (
"errors"
"fmt"
"github.com/adrg/xdg"
"github.com/muhammadmuzzammil1998/jsonc"
"github.com/v2rayA/v2rayA/common/files"
"github.com/v2rayA/v2rayA/common/httpClient"
"github.com/v2rayA/v2rayA/conf"
"github.com/v2rayA/v2rayA/core/v2ray/where"
"github.com/v2rayA/v2rayA/pkg/util/log"
"io"
"io/fs"
"os"
"path"
@@ -136,3 +139,20 @@ func GetV2rayConfigPath() (p string) {
func GetV2rayConfigDirPath() (p string) {
return conf.GetEnvironmentConfig().V2rayConfigDirectory
}
func Download(url string, to string) (err error) {
resp, err := httpClient.GetHttpClientAutomatically().Get(url)
if err != nil || resp.StatusCode != 200 {
if err == nil {
defer resp.Body.Close()
err = fmt.Errorf("code: %v %v", resp.StatusCode, resp.Status)
}
return err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
return os.WriteFile(to, b, 0644)
}
+1 -5
View File
@@ -3,7 +3,6 @@ package dat
import (
"fmt"
"github.com/v2rayA/v2rayA/core/v2ray/asset"
gopeed2 "github.com/v2rayA/v2rayA/pkg/util/gopeed"
"github.com/v2rayA/v2rayA/pkg/util/log"
"os"
"strings"
@@ -14,10 +13,7 @@ func UpdateLocalGeoIP() (err error) {
if err != nil {
return err
}
if err = gopeed2.Down(&gopeed2.Request{
Method: "GET",
URL: "https://hubmirror.v2raya.org/v2fly/geoip/releases/latest/download/geoip.dat",
}, pathSiteDat+".new"); err != nil {
if err = asset.Download("https://hubmirror.v2raya.org/v2fly/geoip/releases/latest/download/geoip.dat", pathSiteDat+".new"); err != nil {
log.Warn("UpdateLocalGeoIP: %v", err)
return
}
+2 -5
View File
@@ -3,7 +3,6 @@ package dat
import (
"fmt"
"github.com/v2rayA/v2rayA/core/v2ray/asset"
gopeed2 "github.com/v2rayA/v2rayA/pkg/util/gopeed"
"github.com/v2rayA/v2rayA/pkg/util/log"
"os"
"strings"
@@ -14,10 +13,8 @@ func UpdateLocalGeoSite() (err error) {
if err != nil {
return err
}
if err = gopeed2.Down(&gopeed2.Request{
Method: "GET",
URL: "https://hubmirror.v2raya.org/v2fly/domain-list-community/releases/latest/download/dlc.dat",
}, pathSiteDat+".new"); err != nil {
if err = asset.Download("https://hubmirror.v2raya.org/v2fly/domain-list-community/releases/latest/download/dlc.dat", pathSiteDat+".new"); err != nil {
log.Warn("UpdateLocalGeoSite: %v", err)
return
}
+2 -6
View File
@@ -10,7 +10,6 @@ import (
"github.com/v2rayA/v2rayA/core/v2ray"
"github.com/v2rayA/v2rayA/core/v2ray/asset"
"github.com/v2rayA/v2rayA/db/configure"
gopeed2 "github.com/v2rayA/v2rayA/pkg/util/gopeed"
"github.com/v2rayA/v2rayA/pkg/util/log"
"io"
"net/http"
@@ -100,7 +99,7 @@ var (
)
func httpGet(url string) (data string, err error) {
resp, err := http.Get(url)
resp, err := httpClient.GetHttpClientAutomatically().Get(url)
if err != nil {
return
}
@@ -121,10 +120,7 @@ func UpdateLocalGFWList() (localGFWListVersionAfterUpdate string, err error) {
return "", err
}
u := fmt.Sprintf(`https://hubmirror.v2raya.org/v2rayA/dist-v2ray-rules-dat/raw/%v/geosite.dat`, gfwlist.Tag)
if err = gopeed2.Down(&gopeed2.Request{
Method: "GET",
URL: u,
}, pathSiteDat+".new"); err != nil {
if err = asset.Download(u, pathSiteDat+".new"); err != nil {
log.Warn("UpdateLocalGFWList: %v", err)
return
}
+1 -4
View File
@@ -91,10 +91,7 @@ func Import(url string, which *configure.Which) (err error) {
} else {
// maybe it is a OOCv1 token
}
c, err := httpClient.GetHttpClientAutomatically()
if err != nil {
return err
}
c := httpClient.GetHttpClientAutomatically()
c.Timeout = 90 * time.Second
infos, status, err := ResolveSubscriptionWithClient(source, c)
if err != nil {
+1 -5
View File
@@ -254,11 +254,7 @@ func getDataUsageStatus(bytesUsed, bytesRemaining uint64) (status string) {
func UpdateSubscription(index int, disconnectIfNecessary bool) (err error) {
subscriptions := configure.GetSubscriptionsV2()
addr := subscriptions[index].Address
c, err := httpClient.GetHttpClientAutomatically()
if err != nil {
reason := "failed to get proxy"
return fmt.Errorf("UpdateSubscription: %v", reason)
}
c := httpClient.GetHttpClientAutomatically()
resolv.CheckResolvConf()
subscriptionInfos, status, err := ResolveSubscriptionWithClient(addr, c)
if err != nil {