proxy.go 1.4 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. "net/http"
  12. )
  13. func (cb *ControllerBase) CheckProxyHandler(c *gin.Context) {
  14. var err error
  15. defer func() {
  16. // 统一的异常处理
  17. cb.ErrorProcess(c, "CheckProxyHandler", err)
  18. }()
  19. checkProxy := backend.ReqCheckProxy{}
  20. err = c.ShouldBindJSON(&checkProxy)
  21. if err != nil {
  22. return
  23. }
  24. tmpSettings := settings.GetSettings()
  25. tmpSettings.AdvancedSettings.ProxySettings.UseHttpProxy = true
  26. tmpSettings.AdvancedSettings.ProxySettings.HttpProxyAddress = checkProxy.HttpProxyAddress
  27. // 使用提交过来的这个代理地址,测试多个字幕网站的可用性
  28. subSupplierHub := subSupplier.NewSubSupplierHub(
  29. tmpSettings,
  30. cb.log,
  31. zimuku.NewSupplier(tmpSettings, cb.log),
  32. xunlei.NewSupplier(tmpSettings, cb.log),
  33. shooter.NewSupplier(tmpSettings, cb.log),
  34. subhd.NewSupplier(tmpSettings, cb.log),
  35. )
  36. outStatus := subSupplierHub.CheckSubSiteStatus()
  37. c.JSON(http.StatusOK, outStatus)
  38. }