AnalyzeTask @Title AnalyzeTask @Tag Task API @Description analyze task document and generate structured report @Param id query string true "The id (owner/name) of the task" @Success 200 {object} object.TaskResult The Response object @router /analyze-task [post]
()
| 254 | // @Success 200 {object} object.TaskResult The Response object |
| 255 | // @router /analyze-task [post] |
| 256 | func (c *ApiController) AnalyzeTask() { |
| 257 | id := c.Input().Get("id") |
| 258 | logs.Info("[analyze-task] HTTP request id=%s user=%s", id, c.GetSessionUsername()) |
| 259 | |
| 260 | task, err := object.GetTask(id) |
| 261 | if err != nil { |
| 262 | logs.Error("[analyze-task] GetTask failed id=%s: %v", id, err) |
| 263 | c.ResponseError(err.Error()) |
| 264 | return |
| 265 | } |
| 266 | if task == nil { |
| 267 | c.ResponseError(c.T("general:The task does not exist")) |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | if !c.IsAdmin() { |
| 272 | username := c.GetSessionUsername() |
| 273 | if task.Owner != username { |
| 274 | logs.Warn("[analyze-task] forbidden id=%s taskOwner=%s user=%s", id, task.Owner, username) |
| 275 | c.ResponseError(c.T("auth:Unauthorized operation")) |
| 276 | return |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | result, err := object.AnalyzeTask(task, c.GetAcceptLanguage()) |
| 281 | if err != nil { |
| 282 | logs.Error("[analyze-task] AnalyzeTask failed id=%s: %v", id, err) |
| 283 | c.ResponseError(err.Error()) |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | logs.Info("[analyze-task] serializing result id=%s", id) |
| 288 | resultBytes, err := json.Marshal(result) |
| 289 | if err != nil { |
| 290 | logs.Error("[analyze-task] json.Marshal failed id=%s: %v", id, err) |
| 291 | c.ResponseError(err.Error()) |
| 292 | return |
| 293 | } |
| 294 | task.Result = string(resultBytes) |
| 295 | task.Score = result.Score |
| 296 | logs.Info("[analyze-task] saving task id=%s resultBytes=%d", id, len(resultBytes)) |
| 297 | _, err = object.UpdateTask(id, task) |
| 298 | if err != nil { |
| 299 | logs.Error("[analyze-task] UpdateTask failed id=%s: %v", id, err) |
| 300 | c.ResponseError(err.Error()) |
| 301 | return |
| 302 | } |
| 303 | |
| 304 | logs.Info("[analyze-task] HTTP OK id=%s", id) |
| 305 | c.ResponseOk(result) |
| 306 | } |
nothing calls this directly
no test coverage detected