UpdateRawFileContent godoc @Summary 更新文件原始内容 @Description 更新文件原始内容,支持 .md, .txt, .html, .htm 后缀。html/htm 会被转换成 markdown 存入 fileBody,同时物理文件会保存原始 html。 @Tags 文件管理 @Accept json @Produce json @Security BearerAuth @Param file_id path int true "文件ID" @Param request body UpdateRawFileContentRequest true "更
(c *gin.Context)
| 243 | // @Failure 500 {object} model.CommonResponse "服务器内部错误" |
| 244 | // @Router /api/files/{file_id}/raw [put] |
| 245 | func UpdateRawFileContent(c *gin.Context) { |
| 246 | eid := config.GetEID(c) |
| 247 | userID := config.GetUserId(c) |
| 248 | fileIDStr := c.Param("file_id") |
| 249 | fileID, _ := strconv.ParseInt(fileIDStr, 10, 64) |
| 250 | |
| 251 | var req UpdateRawFileContentRequest |
| 252 | if err := c.ShouldBindJSON(&req); err != nil { |
| 253 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 254 | return |
| 255 | } |
| 256 | |
| 257 | fileService := mcpsvc.NewFileService() |
| 258 | fileBody, err := fileService.UpdateRawFileContent(c.Request.Context(), eid, userID, fileID, req.Content) |
| 259 | if err != nil { |
| 260 | switch { |
| 261 | case isPermissionRelatedError(err): |
| 262 | c.JSON(http.StatusForbidden, model.AuthFailed.ToResponse(err)) |
| 263 | case strings.Contains(err.Error(), "不支持"): |
| 264 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err)) |
| 265 | default: |
| 266 | c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err)) |
| 267 | } |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | library, err := model.GetLibraryByID(eid, fileBody.LibraryID) |
| 272 | if err != nil { |
| 273 | c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err)) |
| 274 | return |
| 275 | } |
| 276 | |
| 277 | // 个人知识库只保存正文/原文件,不再自动触发后处理;普通知识库保持原行为 |
| 278 | if !library.IsPersonalLibrary() && !isTestMode() { |
| 279 | go func() { |
| 280 | content := req.Content |
| 281 | if fileBody != nil && fileBody.Content != "" { |
| 282 | content = fileBody.Content |
| 283 | } |
| 284 | service.ProcessAutoChunkingWithPipeline(eid, fileID, userID, content, nil) |
| 285 | }() |
| 286 | } |
| 287 | |
| 288 | c.JSON(http.StatusOK, model.Success.ToResponse(nil)) |
| 289 | } |
| 290 | |
| 291 | type FileSortListRequest struct { |
| 292 | Files []struct { |
nothing calls this directly
no test coverage detected