MCPcopy Create free account
hub / github.com/53AI/53AIHub / DeleteLibrary

Function DeleteLibrary

api/controller/library.go:410–467  ·  view source on GitHub ↗

DeleteLibrary godoc @Summary 删除知识库 @Description 删除指定的知识库 @Tags 知识库管理 @Accept json @Produce json @Security BearerAuth @Param library_id path int true "知识库ID" @Success 200 {object} model.CommonResponse @Router /api/libraries/{library_id} [delete]

(c *gin.Context)

Source from the content-addressed store, hash-verified

408// @Success 200 {object} model.CommonResponse
409// @Router /api/libraries/{library_id} [delete]
410func DeleteLibrary(c *gin.Context) {
411 eid := config.GetEID(c)
412 userID := config.GetUserId(c)
413
414 id := c.Param("library_id")
415 if id == "" {
416 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("知识库ID不能为空")))
417 return
418 }
419
420 libraryID, err := strconv.ParseInt(id, 10, 64)
421 if err != nil {
422 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("无效的知识库ID")))
423 return
424 }
425
426 // 检查功能是否可用
427 params := map[string]interface{}{
428 "from": "library",
429 }
430 _, featureErr := service.IsFeatureAvailable(c, "library", params)
431 if featureErr != nil {
432 c.JSON(http.StatusForbidden, model.FeatureNotAvailableError.ToResponse(featureErr))
433 return
434 }
435
436 // 检查"可管理"权限
437 permission, err := service.GetUserPermission(eid, model.RESOURCE_TYPE_LIBRARY, libraryID, userID)
438 if err != nil || permission < model.PERMISSION_MANAGE {
439 c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(err))
440 return
441 }
442
443 // 获取知识库信息用于日志记录
444 library, err := model.GetLibraryByID(eid, libraryID)
445 if err != nil {
446 c.JSON(http.StatusNotFound, model.NotFound.ToResponse(err))
447 return
448 }
449
450 // 获取空间信息用于日志记录
451 space, _ := model.GetSpaceByID(eid, library.SpaceID)
452
453 if err := model.DeleteLibrary(eid, libraryID); err != nil {
454 c.JSON(http.StatusInternalServerError, model.FileError.ToResponse(err))
455 return
456 }
457
458 // 记录删除日志
459 var spaceName string
460 if space != nil {
461 spaceName = space.Name
462 }
463 LogLibraryDelete(c, spaceName, library.Name)
464 common.SetLibraryStop(libraryID)
465
466 c.JSON(http.StatusOK, model.Success.ToResponse(nil))
467}

Callers

nothing calls this directly

Calls 5

LogLibraryDeleteFunction · 0.85
GetEIDMethod · 0.80
ToResponseMethod · 0.80
DeleteLibraryMethod · 0.80
NewMethod · 0.45

Tested by

no test coverage detected