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

Function GetFileDeletionPreview

api/controller/file.go:1203–1254  ·  view source on GitHub ↗

GetFileDeletionPreview godoc @Summary 获取文件删除预览 @Description 获取删除文件时将会影响的数据统计 @Tags 文件管理 @Accept json @Produce json @Security BearerAuth @Param file_id path int true "文件ID" @Success 200 {object} model.CommonResponse{data=FileDeletionPreview} @Router /api/files/{file_id}/deletion-preview [get]

(c *gin.Context)

Source from the content-addressed store, hash-verified

1201// @Success 200 {object} model.CommonResponse{data=FileDeletionPreview}
1202// @Router /api/files/{file_id}/deletion-preview [get]
1203func GetFileDeletionPreview(c *gin.Context) {
1204 eid := config.GetEID(c)
1205 userID := config.GetUserId(c)
1206
1207 id := c.Param("file_id")
1208 if id == "" {
1209 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("文件ID不能为空")))
1210 return
1211 }
1212
1213 fileID, err := parseMCPStyleID(id)
1214 if err != nil {
1215 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(errors.New("无效的文件ID")))
1216 return
1217 }
1218
1219 // 获取文件信息
1220 file, err := model.GetFileByID(eid, fileID)
1221 if err != nil {
1222 c.JSON(http.StatusNotFound, model.NotFound.ToResponse(err))
1223 return
1224 }
1225
1226 permisson, err := service.GetUserPermission(eid, model.RESOURCE_TYPE_FILE, fileID, userID)
1227 if err != nil || permisson < model.PERMISSION_MANAGE {
1228 c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(err))
1229 return
1230 }
1231
1232 // 获取删除统计信息
1233 stats, err := model.GetFileDeletionStats(eid, fileID)
1234 if err != nil {
1235 c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(err))
1236 return
1237 }
1238
1239 preview := &FileDeletionPreview{
1240 FileID: fileID,
1241 FileName: file.Path,
1242 FileType: file.Type,
1243 DocumentChunks: stats.DocumentChunks,
1244 RetrievalChunks: stats.RetrievalChunks,
1245 Relations: stats.Relations,
1246 Vectors: stats.Vectors,
1247 OperationLogs: stats.OperationLogs,
1248 FileVersions: stats.FileVersions,
1249 EstimatedTime: stats.EstimateDeletionTime(),
1250 RecommendAsync: stats.ShouldUseAsync(),
1251 }
1252
1253 c.JSON(http.StatusOK, model.Success.ToResponse(preview))
1254}
1255
1256// FileDeletionPreview 文件删除预览
1257type FileDeletionPreview struct {

Callers

nothing calls this directly

Calls 6

parseMCPStyleIDFunction · 0.85
GetEIDMethod · 0.80
ToResponseMethod · 0.80
EstimateDeletionTimeMethod · 0.80
ShouldUseAsyncMethod · 0.80
NewMethod · 0.45

Tested by

no test coverage detected