添加文本转文档的任务接口
This commit is contained in:
parent
933b969ad9
commit
9d5fdb5cf9
|
|
@ -73,6 +73,9 @@ func SetUpToolGroup(router *gin.Engine) {
|
|||
toolGroup.POST("/spark_ppt_create_status", GetSparkCreatePPTStatus)
|
||||
//国外服务器处理请求
|
||||
toolGroup.POST("/online_server_request", HandleOnlineServerRequest)
|
||||
//文本转为文档接口
|
||||
toolGroup.POST("/text_to_docx", HandleMessageTextToDocx)
|
||||
toolGroup.GET("/get_text_docx_set", GetTextDocxSet)
|
||||
}
|
||||
|
||||
func SetDeviceStatusV2(c *gin.Context) {
|
||||
|
|
@ -894,3 +897,63 @@ func HandleOnlineServerRequest(c *gin.Context) {
|
|||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func HandleMessageTextToDocx(c *gin.Context) {
|
||||
var req proto.MessageTextToDocxReq
|
||||
var resp proto.GenerateResp
|
||||
userID, _ := c.Get("user_id")
|
||||
if err := c.ShouldBind(&req); err == nil {
|
||||
req.UserID = int(userID.(float64))
|
||||
reqStr, err2 := json.Marshal(req)
|
||||
if err2 != nil {
|
||||
resp.Code = proto.ParameterError
|
||||
resp.Message = "参数错误,解析错误"
|
||||
} else {
|
||||
//设置到redis set
|
||||
success := worker.SetRedisSetAdd("message_text_to_docx", string(reqStr))
|
||||
if success {
|
||||
resp.Code = proto.SuccessCode
|
||||
resp.Message = "success"
|
||||
resp.Data = "success"
|
||||
} else {
|
||||
resp.Code = proto.OperationFailed
|
||||
resp.Message = "操作失败"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resp.Code = proto.ParameterError
|
||||
resp.Message = "参数错误"
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetTextDocxSet(c *gin.Context) {
|
||||
var resp proto.GenerateResp
|
||||
userID, _ := c.Get("user_id")
|
||||
//查看用户是否是管理员
|
||||
user := service.GetUserByIDWithCache(int(userID.(float64)))
|
||||
if user.Role != "admin" {
|
||||
resp.Code = proto.PermissionDenied
|
||||
resp.Message = "没有权限"
|
||||
} else {
|
||||
//获取redis set
|
||||
strList := worker.GetRedisSetMembers("message_text_to_docx")
|
||||
//解析json
|
||||
var data []proto.MessageTextToDocxReq
|
||||
for _, str := range strList {
|
||||
var req proto.MessageTextToDocxReq
|
||||
err := json.Unmarshal([]byte(str), &req)
|
||||
if err != nil {
|
||||
log.Println("json unmarshal error:", err)
|
||||
} else {
|
||||
data = append(data, req)
|
||||
}
|
||||
}
|
||||
worker.DelRedis("message_text_to_docx")
|
||||
resp.Code = proto.SuccessCode
|
||||
resp.Message = "success"
|
||||
resp.Data = data
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
|
|
|||
3
main.go
3
main.go
|
|
@ -184,6 +184,9 @@ func JWTAuthMiddleware() gin.HandlerFunc {
|
|||
// 将用户信息添加到上下文中
|
||||
c.Set("id", token.Claims.(jwt.MapClaims)["id"])
|
||||
c.Set("username", token.Claims.(jwt.MapClaims)["username"])
|
||||
id := token.Claims.(jwt.MapClaims)["id"]
|
||||
userID := int(id.(float64))
|
||||
c.Set("user_id", userID)
|
||||
|
||||
if UserFuncIntercept(int(token.Claims.(jwt.MapClaims)["id"].(float64)), c.Request.URL.Path) {
|
||||
c.AbortWithStatus(200)
|
||||
|
|
|
|||
|
|
@ -318,3 +318,10 @@ type QQUserInfoResponse struct {
|
|||
Level string `json:"level"`
|
||||
IsYellowYearVip string `json:"is_yellow_year_vip"`
|
||||
}
|
||||
|
||||
type MessageTextToDocxReq struct {
|
||||
Text string `json:"text"` // 文本内容
|
||||
FileName string `json:"file_name"` // 文件名称,必须
|
||||
FileType string `json:"file_type"` // 文件类型,docx,txt,md,pdf
|
||||
UserID int `json:"user_id"` // 用户ID
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue