CreateMySpaceRecordingFolder godoc @Summary 创建我的录音文件夹 @Description 在当前用户的个人知识库中创建录音相关文件夹,并标记为录音来源 @Tags 我的录音 @Accept json @Produce json @Security BearerAuth @Param request body controller.CreateRecordingFolderRequest true "录音文件夹创建请求" @Success 200 {object} model.CommonResponse{data=controller.Recordi
(c *gin.Context)
| 354 | // @Failure 500 {object} model.CommonResponse |
| 355 | // @Router /api/my-space/recordings/folders [post] |
| 356 | func CreateMySpaceRecordingFolder(c *gin.Context) { |
| 357 | var req CreateRecordingFolderRequest |
| 358 | if err := c.ShouldBindJSON(&req); err != nil { |
| 359 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 360 | return |
| 361 | } |
| 362 | |
| 363 | eid := config.GetEID(c) |
| 364 | userID := config.GetUserId(c) |
| 365 | spaceSvc := service.NewPersonalSpaceService(eid) |
| 366 | _, library, err := spaceSvc.EnsurePersonalWorkspace(c.Request.Context(), userID) |
| 367 | if err != nil { |
| 368 | logger.SysErrorf("【录音】创建录音文件夹失败: eid=%d user_id=%d path=%s err=%v", eid, userID, req.Path, err) |
| 369 | if errors.Is(err, service.ErrPersonalWorkspaceInitializing) { |
| 370 | c.JSON(http.StatusTooManyRequests, model.OperateTooFast.ToResponse(err)) |
| 371 | return |
| 372 | } |
| 373 | c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(err)) |
| 374 | return |
| 375 | } |
| 376 | |
| 377 | recordingSvc := service.NewMySpaceRecordingService(eid) |
| 378 | activeJobID, activeErr := recordingSvc.ActiveRecordingJobID(c.Request.Context(), userID) |
| 379 | if activeErr != nil { |
| 380 | logger.SysErrorf("【录音】获取活跃录音任务失败: eid=%d user_id=%d err=%v", eid, userID, activeErr) |
| 381 | c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(activeErr)) |
| 382 | return |
| 383 | } |
| 384 | |
| 385 | fileSvc := mcpsvc.NewFileService() |
| 386 | result, err := fileSvc.CreateFileOrFolder(c.Request.Context(), eid, userID, library.ID, req.Path, model.FILE_TYPE_DIR, "") |
| 387 | if err != nil { |
| 388 | logger.SysErrorf("【录音】创建录音文件夹失败: eid=%d user_id=%d path=%s err=%v", eid, userID, req.Path, err) |
| 389 | c.JSON(http.StatusInternalServerError, model.FileError.ToResponse(err)) |
| 390 | return |
| 391 | } |
| 392 | if result == nil || result.File == nil { |
| 393 | c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(errors.New("创建录音文件夹失败"))) |
| 394 | return |
| 395 | } |
| 396 | |
| 397 | result.File.SetRecordingFolderOrigin(activeJobID) |
| 398 | if err := model.DB.Model(result.File).Updates(map[string]interface{}{ |
| 399 | "origin_type": result.File.OriginType, |
| 400 | "origin_ref_id": result.File.OriginRefID, |
| 401 | "origin_source": result.File.OriginSource, |
| 402 | }).Error; err != nil { |
| 403 | logger.SysErrorf("【录音】标记录音文件夹失败: eid=%d user_id=%d file_id=%d err=%v", eid, userID, result.File.ID, err) |
| 404 | c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(err)) |
| 405 | return |
| 406 | } |
| 407 | |
| 408 | c.JSON(http.StatusOK, model.Success.ToResponse(RecordingFolderResponse{Folder: result.File})) |
| 409 | } |
| 410 | |
| 411 | // GetMySpaceRecordings godoc |
| 412 | // @Summary 获取“我的录音”资源列表 |
nothing calls this directly
no test coverage detected