From de2fd012711b2d6023db76b0a7de9b3cfba36e92 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 12 Oct 2023 10:24:45 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E5=BD=93=E7=9B=AE=E5=BD=95=E4=B8=AD?= =?UTF-8?q?=E6=9C=89=E5=AD=90=E6=A8=A1=E5=9D=97=E5=AD=90=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=94=E6=89=BE=E4=B8=8D=E5=88=B0commitid=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E6=8A=A5=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/hat/repo/file.go | 4 ++-- services/repository/files/content.go | 29 +++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/routers/hat/repo/file.go b/routers/hat/repo/file.go index f990f12..63007d5 100644 --- a/routers/hat/repo/file.go +++ b/routers/hat/repo/file.go @@ -137,12 +137,12 @@ func GetReadmeContents(ctx *context.APIContext) { readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"} readmePath := "" readmePathInArrIndex := 0 - filesListInterface, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref) + filesListInterface, err := hat_files_service.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref) if err != nil { ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err) return } - filesList, ok := filesListInterface.([]*api.ContentsResponse) + filesList, ok := filesListInterface.([]*hat_api.ContentsResponse) if ok { for _, file := range filesList { for i, sortItem := range readmeSortArr { diff --git a/services/repository/files/content.go b/services/repository/files/content.go index 0705b20..fee9a61 100644 --- a/services/repository/files/content.go +++ b/services/repository/files/content.go @@ -134,21 +134,24 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref if err != nil { return nil, err } + var isTextFile = false - blob, err := gitRepo.GetBlob(entry.ID.String()) - if err != nil { - return nil, err - } - dataRc, err := blob.DataAsync() - if err != nil { - return nil, err - } - buf := make([]byte, 1024) - n, _ := util.ReadAtMost(dataRc, buf) - buf = buf[:n] + if !entry.IsSubModule() { + blob, err := gitRepo.GetBlob(entry.ID.String()) + if err != nil { + return nil, err + } + dataRc, err := blob.DataAsync() + if err != nil { + return nil, err + } + buf := make([]byte, 1024) + n, _ := util.ReadAtMost(dataRc, buf) + buf = buf[:n] - st := typesniffer.DetectContentType(buf) - isTextFile := st.IsText() + st := typesniffer.DetectContentType(buf) + isTextFile = st.IsText() + } contentsResponse := &hat_api.ContentsResponse{ ContentsResponse: &gitea_api.ContentsResponse{