path_things.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package base
  2. import (
  3. "net/http"
  4. "github.com/allanpk716/ChineseSubFinder/internal/types/backend"
  5. "github.com/allanpk716/ChineseSubFinder/pkg/logic/emby_helper"
  6. "github.com/allanpk716/ChineseSubFinder/pkg/my_util"
  7. "github.com/allanpk716/ChineseSubFinder/pkg/settings"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func (cb ControllerBase) CheckPathHandler(c *gin.Context) {
  11. var err error
  12. defer func() {
  13. // 统一的异常处理
  14. cb.ErrorProcess(c, "CheckPathHandler", err)
  15. }()
  16. reqCheckPath := backend.ReqCheckPath{}
  17. err = c.ShouldBindJSON(&reqCheckPath)
  18. if err != nil {
  19. return
  20. }
  21. if my_util.IsDir(reqCheckPath.Path) == true {
  22. c.JSON(http.StatusOK, backend.ReplyCheckPath{
  23. Valid: true,
  24. })
  25. } else {
  26. c.JSON(http.StatusOK, backend.ReplyCheckPath{
  27. Valid: false,
  28. })
  29. }
  30. }
  31. func (cb *ControllerBase) CheckEmbyPathHandler(c *gin.Context) {
  32. var err error
  33. defer func() {
  34. // 统一的异常处理
  35. cb.ErrorProcess(c, "CheckEmbyPathHandler", err)
  36. }()
  37. reqCheckPath := backend.ReqCheckEmbyPath{}
  38. err = c.ShouldBindJSON(&reqCheckPath)
  39. if err != nil {
  40. return
  41. }
  42. // 需要使用 Emby 做列表转换,从发送过来的 emby_media_path 进行推算,拼接 cfs_media_path 地址,然后读取这个文件夹或者视频是否存在
  43. // 暂定还是以最近的 Emby 视频列表,再去匹配
  44. emSettings := settings.EmbySettings{
  45. Enable: true,
  46. AddressUrl: reqCheckPath.AddressUrl,
  47. APIKey: reqCheckPath.APIKey,
  48. MaxRequestVideoNumber: 2000,
  49. SkipWatched: false,
  50. MoviePathsMapping: make(map[string]string, 0),
  51. SeriesPathsMapping: make(map[string]string, 0),
  52. }
  53. if reqCheckPath.PathType == "movie" {
  54. emSettings.MoviePathsMapping[reqCheckPath.CFSMediaPath] = reqCheckPath.EmbyMediaPath
  55. } else {
  56. emSettings.SeriesPathsMapping[reqCheckPath.CFSMediaPath] = reqCheckPath.EmbyMediaPath
  57. }
  58. emHelper := emby_helper.NewEmbyHelper(cb.fileDownloader.Log, &settings.Settings{EmbySettings: &emSettings})
  59. outList, err := emHelper.CheckPath(reqCheckPath.PathType)
  60. if err != nil {
  61. return
  62. }
  63. c.JSON(http.StatusOK, backend.ReplyCheckEmbyPath{
  64. MediaList: outList,
  65. })
  66. }