Sfoglia il codice sorgente

修复 ChangeJobStatusHandler 多次判断返回值导致没有正确反馈的 bug

Signed-off-by: allan716 <[email protected]>
allan716 3 anni fa
parent
commit
6c6cdc0270

+ 79 - 0
internal/backend/controllers/v1/api.go

@@ -0,0 +1,79 @@
+package v1
+
+import (
+	"errors"
+	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
+	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
+	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
+	TTaskqueue "github.com/allanpk716/ChineseSubFinder/internal/types/task_queue"
+	"github.com/gin-gonic/gin"
+	"net/http"
+)
+
+// AddJobHandler 外部 API 接口添加任务的处理
+func (cb ControllerBase) AddJobHandler(c *gin.Context) {
+	var err error
+	defer func() {
+		// 统一的异常处理
+		cb.ErrorProcess(c, "AddJobHandler", err)
+	}()
+
+	videoListAdd := backend.ReqVideoListAdd{}
+	err = c.ShouldBindJSON(&videoListAdd)
+	if err != nil {
+		return
+	}
+	// 这里视频文件得要存在
+	if my_util.IsFile(videoListAdd.PhysicalVideoFileFullPath) == false {
+
+		c.JSON(http.StatusOK, backend.ReplyJobThings{
+			Message: "physical video file not found",
+		})
+		return
+	}
+
+	videoType := common.Movie
+	if videoListAdd.VideoType == 1 {
+		videoType = common.Series
+	}
+	nowJob := TTaskqueue.NewOneJob(
+		videoType, videoListAdd.PhysicalVideoFileFullPath, videoListAdd.TaskPriorityLevel,
+		videoListAdd.MediaServerInsideVideoID,
+	)
+	bok, err := cb.cronHelper.DownloadQueue.Add(*nowJob)
+	if err != nil {
+		return
+	}
+	if bok == false {
+		c.JSON(http.StatusOK, backend.ReplyJobThings{
+			JobID:   nowJob.Id,
+			Message: "job is already in queue",
+		})
+	} else {
+		c.JSON(http.StatusOK, backend.ReplyJobThings{
+			JobID:   nowJob.Id,
+			Message: "ok",
+		})
+	}
+}
+
+// GetJobStatusHandler 外部 API 接口获取任务的状态
+func (cb ControllerBase) GetJobStatusHandler(c *gin.Context) {
+	var err error
+	defer func() {
+		// 统一的异常处理
+		cb.ErrorProcess(c, "GetJobStatusHandler", err)
+	}()
+
+	jobID := c.DefaultQuery("job_id", "")
+	if jobID == "" {
+		err = errors.New("job_id is empty")
+		return
+	}
+
+	found, oneJob := cb.cronHelper.DownloadQueue.GetOneJobByID(jobID)
+	if found == false {
+		err = errors.New("GetOneJobByID failed, id=" + jobID)
+		return
+	}
+}

+ 0 - 6
internal/backend/controllers/v1/jobs_things.go

@@ -2,7 +2,6 @@ package v1
 
 import (
 	"bufio"
-	"errors"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
@@ -55,11 +54,6 @@ func (cb ControllerBase) ChangeJobStatusHandler(c *gin.Context) {
 	}
 
 	bok, nowOneJob := cb.cronHelper.DownloadQueue.GetOneJobByID(desJobStatus.Id)
-	if bok == false {
-		err = errors.New("GetOneJobByID failed, id=" + desJobStatus.Id)
-		return
-	}
-
 	if bok == false {
 		c.JSON(http.StatusOK, backend.ReplyCommon{Message: "job not found"})
 		return