path_things.go 672 B

1234567891011121314151617181920212223242526272829303132
  1. package v1
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  4. "github.com/allanpk716/ChineseSubFinder/internal/types/backend"
  5. "github.com/gin-gonic/gin"
  6. "net/http"
  7. )
  8. func (cb ControllerBase) CheckPathHandler(c *gin.Context) {
  9. var err error
  10. defer func() {
  11. // 统一的异常处理
  12. cb.ErrorProcess(c, "CheckPathHandler", err)
  13. }()
  14. reqCheckPath := backend.ReqCheckPath{}
  15. err = c.ShouldBindJSON(&reqCheckPath)
  16. if err != nil {
  17. return
  18. }
  19. if my_util.IsDir(reqCheckPath.Path) == true {
  20. c.JSON(http.StatusOK, backend.ReplyCheckPath{
  21. Valid: true,
  22. })
  23. } else {
  24. c.JSON(http.StatusOK, backend.ReplyCheckPath{
  25. Valid: false,
  26. })
  27. }
  28. }