Merge pull request '在接口 src/commit/* 添加 content' (#45) from wonderful/gitea-1156:develop into develop

This commit is contained in:
wonderful 2021-12-29 16:43:07 +08:00
commit ce0e3224c4
2 changed files with 26 additions and 13 deletions

View File

@ -6,9 +6,11 @@
package repo package repo
import ( import (
"code.gitea.io/gitea/modules/setting"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"code.gitea.io/gitea/modules/setting"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -18,6 +20,7 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repofiles" "code.gitea.io/gitea/modules/repofiles"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
@ -717,7 +720,7 @@ func safeURL(address string) string {
} }
const ( const (
tplMigrating base.TplName = "repo/migrating" tplMigrating base.TplName = "repo/migrate/migrating"
tplRepoEMPTY base.TplName = "repo/empty" tplRepoEMPTY base.TplName = "repo/empty"
) )
@ -738,10 +741,19 @@ func GetFileContents(ctx *context.APIContext) {
ctx.Data["Repo"] = ctx.Repo ctx.Data["Repo"] = ctx.Repo
ctx.Data["MigrateTask"] = task ctx.Data["MigrateTask"] = task
ctx.Data["CloneAddr"] = safeURL(cfg.CloneAddr) ctx.Data["CloneAddr"] = safeURL(cfg.CloneAddr)
ctx.HTML(200, tplMigrating) ctx.Data["Failed"] = task.Status == api.TaskStatusFailed
ctx.HTML(http.StatusOK, tplMigrating)
return return
} }
if ctx.IsSigned {
// Set repo notification-status read if unread
if err := ctx.Repo.Repository.ReadBy(ctx.User.ID); err != nil {
ctx.ServerError("ReadBy", err)
return
}
}
var firstUnit *models.Unit var firstUnit *models.Unit
for _, repoUnit := range ctx.Repo.Units { for _, repoUnit := range ctx.Repo.Units {
if repoUnit.Type == models.UnitTypeCode { if repoUnit.Type == models.UnitTypeCode {
@ -751,6 +763,7 @@ func GetFileContents(ctx *context.APIContext) {
}{ }{
Content: ctx.Data["FileContent"], Content: ctx.Data["FileContent"],
} }
log.Info("filecontent = \n", fileContent)
ctx.JSON(http.StatusOK, fileContent) ctx.JSON(http.StatusOK, fileContent)
return return
} }
@ -774,7 +787,7 @@ func renderCode(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true ctx.Data["PageIsViewCode"] = true
if ctx.Repo.Repository.IsEmpty { if ctx.Repo.Repository.IsEmpty {
ctx.HTML(200, tplRepoEMPTY) ctx.HTML(http.StatusOK, tplRepoEMPTY)
return return
} }
@ -786,7 +799,7 @@ func renderCode(ctx *context.Context) {
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL() branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
treeLink := branchLink treeLink := branchLink
// rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL() rawLink := ctx.Repo.RepoLink + "/raw/" + ctx.Repo.BranchNameSubURL()
if len(ctx.Repo.TreePath) > 0 { if len(ctx.Repo.TreePath) > 0 {
treeLink += "/" + ctx.Repo.TreePath treeLink += "/" + ctx.Repo.TreePath
@ -801,6 +814,7 @@ func renderCode(ctx *context.Context) {
// Get current entry user currently looking at. // Get current entry user currently looking at.
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath) entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
if err != nil { if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.GetTreeEntryByPath", git.IsErrNotExist, err)
return return
} }
@ -810,9 +824,9 @@ func renderCode(ctx *context.Context) {
} }
if entry.IsDir() { if entry.IsDir() {
// renderDirectory(ctx, treeLink) repo.RenderDirectory(ctx, treeLink)
} else { } else {
// renderFile(ctx, entry, treeLink, rawLink) repo.RenderFile(ctx, entry, treeLink, rawLink)
} }
if ctx.Written() { if ctx.Written() {
return return
@ -836,9 +850,8 @@ func renderCode(ctx *context.Context) {
ctx.Data["TreeLink"] = treeLink ctx.Data["TreeLink"] = treeLink
ctx.Data["TreeNames"] = treeNames ctx.Data["TreeNames"] = treeNames
ctx.Data["BranchLink"] = branchLink ctx.Data["BranchLink"] = branchLink
// ctx.HTML(200, tplRepoHome) // ctx.HTML(http.StatusOK, tplRepoHome)
} }
func renderRepoTopics(ctx *context.Context) { func renderRepoTopics(ctx *context.Context) {
topics, err := models.FindTopics(&models.FindTopicOptions{ topics, err := models.FindTopics(&models.FindTopicOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,

View File

@ -128,7 +128,7 @@ func getReadmeFileFromPath(commit *git.Commit, treePath string) (*namedBlob, err
return readmeFile, nil return readmeFile, nil
} }
func renderDirectory(ctx *context.Context, treeLink string) { func RenderDirectory(ctx *context.Context, treeLink string) {
tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath) tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath)
if err != nil { if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err) ctx.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err)
@ -396,7 +396,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
ctx.Data["SSHDomain"] = setting.SSH.Domain ctx.Data["SSHDomain"] = setting.SSH.Domain
} }
func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) { func RenderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) {
ctx.Data["IsViewFile"] = true ctx.Data["IsViewFile"] = true
blob := entry.Blob() blob := entry.Blob()
dataRc, err := blob.DataAsync() dataRc, err := blob.DataAsync()
@ -728,9 +728,9 @@ func renderCode(ctx *context.Context) {
} }
if entry.IsDir() { if entry.IsDir() {
renderDirectory(ctx, treeLink) RenderDirectory(ctx, treeLink)
} else { } else {
renderFile(ctx, entry, treeLink, rawLink) RenderFile(ctx, entry, treeLink, rawLink)
} }
if ctx.Written() { if ctx.Written() {
return return