diff --git a/api/router.go b/api/router.go index 921074b..6ffe0c5 100644 --- a/api/router.go +++ b/api/router.go @@ -18,6 +18,7 @@ func SetupRouter(engine *gin.RouterGroup) { formulaRouter.POST("/recognition", endpoint.CreateTask) formulaRouter.POST("/ai_enhance", endpoint.AIEnhanceRecognition) formulaRouter.GET("/recognition/:task_no", endpoint.GetTaskStatus) + formulaRouter.POST("/test_process_mathpix_task", endpoint.TestProcessMathpixTask) } taskRouter := v1.Group("/task", common.GetAuthMiddleware()) diff --git a/api/v1/formula/handler.go b/api/v1/formula/handler.go index be4a26c..e4a6687 100644 --- a/api/v1/formula/handler.go +++ b/api/v1/formula/handler.go @@ -121,3 +121,20 @@ func (endpoint *FormulaEndpoint) AIEnhanceRecognition(c *gin.Context) { c.JSON(http.StatusOK, common.SuccessResponse(c, nil)) } + +func (endpoint *FormulaEndpoint) TestProcessMathpixTask(c *gin.Context) { + postData := make(map[string]int) + if err := c.BindJSON(&postData); err != nil { + c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeParamError, "Invalid parameters")) + return + } + + taskID := postData["task_id"] + err := endpoint.recognitionService.TestProcessMathpixTask(c, int64(taskID)) + if err != nil { + c.JSON(http.StatusOK, common.ErrorResponse(c, common.CodeSystemError, err.Error())) + return + } + + c.JSON(http.StatusOK, common.SuccessResponse(c, nil)) +} diff --git a/config/config_dev.yaml b/config/config_dev.yaml index 339b63d..be99b85 100644 --- a/config/config_dev.yaml +++ b/config/config_dev.yaml @@ -47,4 +47,4 @@ aliyun: mathpix: app_id: "ocr_eede6f_ea9b5c" - app_key: "683f7133391a1039383161653531396234343536393263346632613437343332" + app_key: "fb72d251e33ac85c929bfd4eec40d78368d08d82fb2ee1cffb04a8bb967d1db5" diff --git a/internal/service/recognition_service.go b/internal/service/recognition_service.go index bed9a40..9643d45 100644 --- a/internal/service/recognition_service.go +++ b/internal/service/recognition_service.go @@ -286,7 +286,7 @@ type MathpixRequest struct { // 高级表格处理,默认false EnableTablesFallback bool `json:"enable_tables_fallback"` // 全角标点,null表示自动判断 - FullwidthPunctuation *bool `json:"fullwidth_punctuation"` + FullwidthPunctuation *bool `json:"fullwidth_punctuation,omitempty"` } // MathpixCallback 回调配置 @@ -819,3 +819,16 @@ func (s *RecognitionService) processMathpixTask(ctx context.Context, taskID int6 isSuccess = true return nil } + +func (s *RecognitionService) TestProcessMathpixTask(ctx context.Context, taskID int64) error { + task, err := dao.NewRecognitionTaskDao().GetTaskByID(dao.DB.WithContext(ctx), taskID) + if err != nil { + log.Error(ctx, "func", "TestProcessMathpixTask", "msg", "获取任务失败", "error", err) + return err + } + if task == nil { + log.Error(ctx, "func", "TestProcessMathpixTask", "msg", "任务不存在", "task_id", taskID) + return err + } + return s.processMathpixTask(ctx, taskID, task.FileURL) +} diff --git a/internal/storage/dao/result.go b/internal/storage/dao/result.go index 5ea838d..18416c3 100644 --- a/internal/storage/dao/result.go +++ b/internal/storage/dao/result.go @@ -8,9 +8,9 @@ type RecognitionResult struct { BaseModel TaskID int64 `gorm:"column:task_id;bigint;not null;default:0;comment:任务ID" json:"task_id"` TaskType TaskType `gorm:"column:task_type;varchar(16);not null;comment:任务类型;default:''" json:"task_type"` - Latex string `json:"latex"` - Markdown string `json:"markdown"` // Mathpix Markdown 格式 - MathML string `json:"mathml"` // MathML 格式 + Latex string `json:"latex" gorm:"column:latex;type:text;not null;default:''"` + Markdown string `json:"markdown" gorm:"column:markdown;type:text;not null;default:''"` // Mathpix Markdown 格式 + MathML string `json:"mathml" gorm:"column:mathml;type:text;not null;default:''"` // MathML 格式 } type RecognitionResultDao struct {