proxy.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package base
  2. import (
  3. subSupplier "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier"
  4. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/shooter"
  5. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/subhd"
  6. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/xunlei"
  7. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_supplier/zimuku"
  8. "github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
  9. "github.com/allanpk716/ChineseSubFinder/internal/types/backend"
  10. "github.com/gin-gonic/gin"
  11. "github.com/huandu/go-clone"
  12. "net/http"
  13. )
  14. func (cb ControllerBase) CheckProxyHandler(c *gin.Context) {
  15. var err error
  16. defer func() {
  17. // 统一的异常处理
  18. cb.ErrorProcess(c, "CheckProxyHandler", err)
  19. }()
  20. checkProxy := backend.ReqCheckProxy{}
  21. err = c.ShouldBindJSON(&checkProxy)
  22. if err != nil {
  23. return
  24. }
  25. tmpSettings := clone.Clone(*settings.GetSettings()).(settings.Settings)
  26. tmpSettings.AdvancedSettings.ProxySettings.UseHttpProxy = true
  27. tmpSettings.AdvancedSettings.ProxySettings.HttpProxyAddress = checkProxy.HttpProxyAddress
  28. // 使用提交过来的这个代理地址,测试多个字幕网站的可用性
  29. subSupplierHub := subSupplier.NewSubSupplierHub(
  30. tmpSettings,
  31. zimuku.NewSupplier(tmpSettings),
  32. xunlei.NewSupplier(tmpSettings),
  33. shooter.NewSupplier(tmpSettings),
  34. subhd.NewSupplier(tmpSettings),
  35. )
  36. outStatus := subSupplierHub.CheckSubSiteStatus()
  37. c.JSON(http.StatusOK, outStatus)
  38. }