GetSkillFileContent godoc @Summary 获取技能文件内容 @Description 获取技能包内指定文件的文本内容 @Tags 技能库-后台 @Accept json @Produce json @Security BearerAuth @Param id path int true "技能ID" @Param path path string true "文件相对路径" @Success 200 {object} model.CommonResponse{data=controller.SkillFileContentResponse} @Router /api
(c *gin.Context)
| 631 | // @Success 200 {object} model.CommonResponse{data=controller.SkillFileContentResponse} |
| 632 | // @Router /api/admin/skill-library/{id}/files/{path} [get] |
| 633 | func GetSkillFileContent(c *gin.Context) { |
| 634 | skillID, err := strconv.ParseInt(c.Param("id"), 10, 64) |
| 635 | if err != nil || skillID <= 0 { |
| 636 | c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(nil)) |
| 637 | return |
| 638 | } |
| 639 | |
| 640 | filePath := c.Param("path") |
| 641 | if filePath == "" { |
| 642 | c.JSON(http.StatusBadRequest, model.ParamError.ToErrorResponse(errors.New("file path is required"))) |
| 643 | return |
| 644 | } |
| 645 | filePath = strings.TrimPrefix(filePath, "/") |
| 646 | |
| 647 | eid := config.GetEID(c) |
| 648 | svc := service.NewSkillLibraryService() |
| 649 | |
| 650 | content, err := svc.GetSkillFileContent(c.Request.Context(), eid, skillID, filePath) |
| 651 | if err != nil { |
| 652 | toSkillAdminErrorResponse(c, err) |
| 653 | return |
| 654 | } |
| 655 | |
| 656 | c.JSON(http.StatusOK, model.Success.ToResponse(&SkillFileContentResponse{ |
| 657 | Path: filePath, |
| 658 | Content: content, |
| 659 | Size: int64(len(content)), |
| 660 | })) |
| 661 | } |
| 662 | |
| 663 | // PreviewSkillFile godoc |
| 664 | // @Summary 预览技能文件 |
nothing calls this directly
no test coverage detected