浏览代码

修复,检测代理和tmdb api 检测的bug

Signed-off-by: allan716 <[email protected]>
allan716 3 年之前
父节点
当前提交
a90cdab227

+ 16 - 12
internal/backend/controllers/base/proxy.go

@@ -32,6 +32,10 @@ func (cb *ControllerBase) CheckProxyHandler(c *gin.Context) {
 		return
 	}
 
+	defer func() {
+		cb.proxyCheckLocker.Unlock()
+	}()
+
 	checkProxy := backend.ReqCheckProxy{}
 	err = c.ShouldBindJSON(&checkProxy)
 	if err != nil {
@@ -42,6 +46,18 @@ func (cb *ControllerBase) CheckProxyHandler(c *gin.Context) {
 	// 赋值 Web 传递过来的需要测试的代理参数
 	settings.Get().AdvancedSettings.ProxySettings = &checkProxy.ProxySettings
 	settings.Get().AdvancedSettings.ProxySettings.UseProxy = true
+
+	defer func() {
+		// 还原
+		settings.Get().AdvancedSettings.ProxySettings = bkProxySettings
+		err = local_http_proxy_server.SetProxyInfo(settings.Get().AdvancedSettings.ProxySettings.GetInfos())
+		if err != nil {
+			return
+		}
+		// 启动代理
+		local_http_proxy_server.GetProxyUrl()
+	}()
+
 	// 设置代理
 	err = local_http_proxy_server.SetProxyInfo(settings.Get().AdvancedSettings.ProxySettings.GetInfos())
 	if err != nil {
@@ -70,17 +86,5 @@ func (cb *ControllerBase) CheckProxyHandler(c *gin.Context) {
 
 	outStatus := subSupplierHub.CheckSubSiteStatus()
 
-	defer func() {
-		// 还原
-		settings.Get().AdvancedSettings.ProxySettings = bkProxySettings
-		cb.proxyCheckLocker.Unlock()
-		err = local_http_proxy_server.SetProxyInfo(settings.Get().AdvancedSettings.ProxySettings.GetInfos())
-		if err != nil {
-			return
-		}
-		local_http_proxy_server.GetProxyUrl()
-	}()
-
 	c.JSON(http.StatusOK, outStatus)
-
 }

+ 13 - 14
internal/backend/controllers/base/tmdb_api.go

@@ -31,6 +31,16 @@ func (cb *ControllerBase) CheckTmdbApiHandler(c *gin.Context) {
 	bkProxySettings := settings.Get().AdvancedSettings.ProxySettings.CopyOne()
 	// 赋值 Web 传递过来的需要测试的代理参数
 	settings.Get().AdvancedSettings.ProxySettings = &req.ProxySettings
+	defer func() {
+		// 还原
+		settings.Get().AdvancedSettings.ProxySettings = bkProxySettings
+		err = local_http_proxy_server.SetProxyInfo(settings.Get().AdvancedSettings.ProxySettings.GetInfos())
+		if err != nil {
+			return
+		}
+		// 启动代理
+		local_http_proxy_server.GetProxyUrl()
+	}()
 	// 设置代理
 	err = local_http_proxy_server.SetProxyInfo(settings.Get().AdvancedSettings.ProxySettings.GetInfos())
 	if err != nil {
@@ -44,20 +54,9 @@ func (cb *ControllerBase) CheckTmdbApiHandler(c *gin.Context) {
 		cb.fileDownloader.Log.Errorln("NewTmdbHelper", err)
 		return
 	}
-
-	defer func() {
-		// 还原
-		settings.Get().AdvancedSettings.ProxySettings = bkProxySettings
-		cb.proxyCheckLocker.Unlock()
-		err = local_http_proxy_server.SetProxyInfo(settings.Get().AdvancedSettings.ProxySettings.GetInfos())
-		if err != nil {
-			return
-		}
-		// 启动代理
-		local_http_proxy_server.GetProxyUrl()
-	}()
-
-	if tmdbApi.Alive() == false {
+	aliveStatus := tmdbApi.Alive()
+	// 返回结果
+	if aliveStatus == false {
 		cb.fileDownloader.Log.Errorln("tmdbApi.Alive() == false")
 		c.JSON(http.StatusOK, backend.ReplyCommon{Message: "false"})
 		return

+ 8 - 0
pkg/local_http_proxy_server/local_http_proxy_server.go

@@ -43,6 +43,14 @@ func GetProxyUrl() string {
 	defer locker.Unlock()
 
 	if useProxy == false {
+
+		if localHttpProxyServer != nil && localHttpProxyServer.IsRunning() == true {
+			// 需要关闭代理
+			err := localHttpProxyServer.Stop()
+			if err != nil {
+				println("localHttpProxyServer.Stop() Error:", err.Error())
+			}
+		}
 		return ""
 	}