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

Function UpdateRawFileContent

api/controller/file.go:245–289  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

243// @Failure 500 {object} model.CommonResponse "服务器内部错误"
244// @Router /api/files/{file_id}/raw [put]
245func 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
291type FileSortListRequest struct {
292 Files []struct {

Callers

nothing calls this directly

Calls 8

UpdateRawFileContentMethod · 0.95
isPermissionRelatedErrorFunction · 0.85
isTestModeFunction · 0.85
GetEIDMethod · 0.80
ToResponseMethod · 0.80
IsPersonalLibraryMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected