Merge branch 'develop'

This commit is contained in:
yystopf 2024-03-05 14:41:24 +08:00
commit c04df49a78
4 changed files with 24 additions and 3 deletions

View File

@ -22,6 +22,7 @@ type BatchFileResponse struct {
type ContentsResponse struct {
*gitea_api.ContentsResponse
IsTextFile bool `json:"is_text_file"`
LatestCommit ContentsResponseCommit `json:"latest_commit"`
}

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

@ -11,6 +11,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
gitea_api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/typesniffer"
"code.gitea.io/gitea/modules/util"
gitea_files_service "code.gitea.io/gitea/services/repository/files"
hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
@ -133,6 +134,24 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
if err != nil {
return nil, err
}
var isTextFile = false
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()
}
contentsResponse := &hat_api.ContentsResponse{
ContentsResponse: &gitea_api.ContentsResponse{
@ -146,6 +165,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
Self: &selfURLString,
},
},
IsTextFile: isTextFile,
LatestCommit: hat_api.ContentsResponseCommit{
Message: lastCommit.CommitMessage,
Sha: lastCommit.ID.String(),

View File

@ -15,7 +15,7 @@
<span class="text red hide" id="name-change-prompt"> {{.locale.Tr "settings.change_username_prompt"}}</span>
<span class="text red hide" id="name-change-redirect-prompt"> {{.locale.Tr "settings.change_username_redirect_prompt"}}</span>
</label>
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}disabled{{end}}>
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required disabled {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}disabled{{end}}>
{{if or (not .SignedUser.IsLocal) .IsReverseProxy}}
<p class="help text blue">{{$.locale.Tr "settings.password_username_disabled"}}</p>
{{end}}