fixed 当目录中有子模块子代码且找不到commitid的情况下报错处理

(cherry picked from commit de2fd01271)
This commit is contained in:
xxq250 2023-10-12 10:24:45 +08:00
parent b2624f6562
commit b1142b9b68
2 changed files with 18 additions and 15 deletions

View File

@ -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 {

View File

@ -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{