fix: add content for the src/commit/*

This commit is contained in:
hang 2021-12-29 16:05:41 +08:00
parent 2dace145f7
commit 0dddf30c1c
2 changed files with 26 additions and 13 deletions

View File

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

View File

@ -128,7 +128,7 @@ func getReadmeFileFromPath(commit *git.Commit, treePath string) (*namedBlob, err
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)
if err != nil {
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
}
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
blob := entry.Blob()
dataRc, err := blob.DataAsync()
@ -728,9 +728,9 @@ func renderCode(ctx *context.Context) {
}
if entry.IsDir() {
renderDirectory(ctx, treeLink)
RenderDirectory(ctx, treeLink)
} else {
renderFile(ctx, entry, treeLink, rawLink)
RenderFile(ctx, entry, treeLink, rawLink)
}
if ctx.Written() {
return