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

Function HardDeleteFile

api/controller/file_recycle.go:202–237  ·  view source on GitHub ↗

HardDeleteFile godoc @Summary 管理员彻底删除文件 @Description 彻底删除文件及其相关数据(父级彻删同时删除已标记删除且非主动的子级) @Tags 文件管理 @Accept json @Produce json @Security BearerAuth @Param file_id path int true "文件ID" @Success 200 {object} model.CommonResponse @Router /api/files/{file_id}/hard-delete [delete]

(c *gin.Context)

Source from the content-addressed store, hash-verified

200// @Success 200 {object} model.CommonResponse
201// @Router /api/files/{file_id}/hard-delete [delete]
202func HardDeleteFile(c *gin.Context) {
203 eid := config.GetEID(c)
204 userID := config.GetUserId(c)
205
206 id := c.Param("file_id")
207 if id == "" {
208 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("文件ID不能为空")))
209 return
210 }
211 fileID, err := parseMCPStyleID(id)
212 if err != nil {
213 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("无效的文件ID")))
214 return
215 }
216
217 file, _ := model.GetFileByID(eid, fileID)
218 if err != nil {
219 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("无效的文件ID")))
220 return
221 }
222
223 // 权限
224 maxPermission, err := service.GetUserPermission(eid, model.RESOURCE_TYPE_LIBRARY, file.LibraryID, userID)
225 if err != nil || maxPermission < model.PERMISSION_MANAGE {
226 c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(errors.New("无权限管理该知识库")))
227 return
228 }
229
230 if err := model.DeleteFile(eid, fileID); err != nil {
231 logger.SysLogf("管理员彻底删除失败: eid=%d fileID=%d userID=%d err=%v", eid, fileID, userID, err)
232 c.JSON(http.StatusInternalServerError, model.FileError.ToResponse(err))
233 return
234 }
235
236 c.JSON(http.StatusOK, model.Success.ToResponse(nil))
237}

Callers

nothing calls this directly

Calls 5

parseMCPStyleIDFunction · 0.85
GetEIDMethod · 0.80
ToResponseMethod · 0.80
DeleteFileMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected