tmdb_api.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package base
  2. import (
  3. "net/http"
  4. "github.com/allanpk716/ChineseSubFinder/pkg/tmdb_api"
  5. "github.com/allanpk716/ChineseSubFinder/pkg/types/backend"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func (cb *ControllerBase) CheckTmdbApiHandler(c *gin.Context) {
  9. var err error
  10. defer func() {
  11. // 统一的异常处理
  12. cb.ErrorProcess(c, "CheckTmdbApiHandler", err)
  13. }()
  14. req := tmdb_api.Req{}
  15. err = c.ShouldBindJSON(&req)
  16. if err != nil {
  17. return
  18. }
  19. if req.ApiKey == "" {
  20. c.JSON(http.StatusOK, backend.ReplyCommon{Message: "false"})
  21. return
  22. }
  23. tmdbApi, err := tmdb_api.NewTmdbHelper(cb.fileDownloader.Log,
  24. req.ApiKey,
  25. cb.fileDownloader.Settings.AdvancedSettings.ProxySettings)
  26. if err != nil {
  27. cb.fileDownloader.Log.Errorln("NewTmdbHelper", err)
  28. return
  29. }
  30. if tmdbApi.Alive() == false {
  31. cb.fileDownloader.Log.Errorln("tmdbApi.Alive() == false")
  32. c.JSON(http.StatusOK, backend.ReplyCommon{Message: "false"})
  33. return
  34. } else {
  35. cb.fileDownloader.Log.Infoln("tmdbApi.Alive() == true")
  36. c.JSON(http.StatusOK, backend.ReplyCommon{Message: "true"})
  37. return
  38. }
  39. }