From 677643b812cdc3bce3b7ef7839239b3059376684 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:07:22 +0800 Subject: fix read commit source --- routers/repo/repo.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'routers/repo/repo.go') diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 43558747..3c8d24a6 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -57,19 +57,23 @@ func Single(ctx *middleware.Context, params martini.Params) { return } + branchName := params["branchname"] + userName := params["username"] + repoName := params["reponame"] + // Get tree path treename := params["_1"] if len(treename) > 0 && treename[len(treename)-1] == '/' { ctx.Redirect("/" + ctx.Repo.Owner.LowerName + "/" + - ctx.Repo.Repository.Name + "/src/" + params["branchname"] + "/" + treename[:len(treename)-1]) + ctx.Repo.Repository.Name + "/src/" + branchName + "/" + treename[:len(treename)-1]) return } ctx.Data["IsRepoToolbarSource"] = true // Branches. - brs, err := models.GetBranches(params["username"], params["reponame"]) + brs, err := models.GetBranches(userName, repoName) if err != nil { ctx.Handle(404, "repo.Single(GetBranches)", err) return @@ -80,15 +84,20 @@ func Single(ctx *middleware.Context, params martini.Params) { } ctx.Data["Branches"] = brs - repoFile, err := models.GetTargetFile(params["username"], params["reponame"], - params["branchname"], params["commitid"], treename) + var commitId string + if !models.IsBranchExist(userName, repoName, branchName) { + commitId = branchName + } + + repoFile, err := models.GetTargetFile(userName, repoName, + branchName, commitId, treename) if err != nil && err != models.ErrRepoFileNotExist { ctx.Handle(404, "repo.Single(GetTargetFile)", err) return } - branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"] - rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + params["branchname"] + branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + branchName + rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + branchName if len(treename) != 0 && repoFile == nil { ctx.Handle(404, "repo.Single", nil) @@ -126,8 +135,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } else { // Directory and file list. - files, err := models.GetReposFiles(params["username"], params["reponame"], - params["branchname"], params["commitid"], treename) + files, err := models.GetReposFiles(userName, repoName, + branchName, commitId, treename) if err != nil { ctx.Handle(404, "repo.Single(GetReposFiles)", err) return @@ -166,8 +175,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } } - ctx.Data["Username"] = params["username"] - ctx.Data["Reponame"] = params["reponame"] + ctx.Data["Username"] = userName + ctx.Data["Reponame"] = repoName var treenames []string Paths := make([]string, 0) @@ -185,8 +194,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } // Get latest commit according username and repo name. - commit, err := models.GetCommit(params["username"], params["reponame"], - params["branchname"], params["commitid"]) + commit, err := models.GetCommit(userName, repoName, + branchName, commitId) if err != nil { log.Error("repo.Single(GetCommit): %v", err) ctx.Handle(404, "repo.Single(GetCommit)", err) @@ -194,6 +203,8 @@ func Single(ctx *middleware.Context, params martini.Params) { } ctx.Data["LastCommit"] = commit + ctx.Data["CommitId"] = commitId + ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames ctx.Data["BranchLink"] = branchLink -- cgit v1.2.3 From 346db02d89ae0337956607eec43a0cd3f184fda8 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:30:20 +0800 Subject: fix image display --- modules/base/markdown.go | 8 ++++++++ routers/repo/repo.go | 19 ++++++++++++------- templates/repo/single_file.tmpl | 8 ++++++-- 3 files changed, 26 insertions(+), 9 deletions(-) (limited to 'routers/repo/repo.go') diff --git a/modules/base/markdown.go b/modules/base/markdown.go index c722f04b..a98ca8cf 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -51,6 +51,14 @@ func IsTextFile(data []byte) (string, bool) { return contentType, false } +func IsImageFile(data []byte) (string, bool) { + contentType := http.DetectContentType(data) + if strings.Index(contentType, "img/") != -1 { + return contentType, true + } + return contentType, false +} + func IsReadmeFile(name string) bool { name = strings.ToLower(name) if len(name) < 6 { diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3c8d24a6..4573a3e4 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -120,15 +120,20 @@ func Single(ctx *middleware.Context, params martini.Params) { data := blob.Contents() _, isTextFile := base.IsTextFile(data) + _, isImageFile := base.IsImageFile(data) ctx.Data["FileIsText"] = isTextFile - readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name) - ctx.Data["ReadmeExist"] = readmeExist - if readmeExist { - ctx.Data["FileContent"] = string(base.RenderMarkdown(data, "")) + if isImageFile { + ctx.Data["IsImageFile"] = true } else { - if isTextFile { - ctx.Data["FileContent"] = string(data) + readmeExist := base.IsMarkdownFile(repoFile.Name) || base.IsReadmeFile(repoFile.Name) + ctx.Data["ReadmeExist"] = readmeExist + if readmeExist { + ctx.Data["FileContent"] = string(base.RenderMarkdown(data, "")) + } else { + if isTextFile { + ctx.Data["FileContent"] = string(data) + } } } } @@ -236,9 +241,9 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { data := blob.Contents() contentType, isTextFile := base.IsTextFile(data) + _, isImageFile := base.IsImageFile(data) ctx.Res.Header().Set("Content-Type", contentType) if !isTextFile { - ctx.Res.Header().Set("Content-Type", contentType) ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename)) ctx.Res.Header().Set("Content-Transfer-Encoding", "binary") } diff --git a/templates/repo/single_file.tmpl b/templates/repo/single_file.tmpl index cf398595..9199ca91 100644 --- a/templates/repo/single_file.tmpl +++ b/templates/repo/single_file.tmpl @@ -23,7 +23,11 @@ {{if not .FileIsText}} {{else}} {{if .ReadmeExist}} @@ -43,4 +47,4 @@ {{end}} {{end}} - \ No newline at end of file + -- cgit v1.2.3 From 417d861be679654652dc63801981a3f4e3873283 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:38:44 +0800 Subject: fix download --- routers/repo/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'routers/repo/repo.go') diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 4573a3e4..8c686bc3 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -243,7 +243,7 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { contentType, isTextFile := base.IsTextFile(data) _, isImageFile := base.IsImageFile(data) ctx.Res.Header().Set("Content-Type", contentType) - if !isTextFile { + if !isTextFile && !isImageFile { ctx.Res.Header().Set("Content-Disposition", "attachment; filename="+filepath.Base(treename)) ctx.Res.Header().Set("Content-Transfer-Encoding", "binary") } -- cgit v1.2.3 From 10b412d237e7594951ab3633dc8eebb965e25f68 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:50:13 +0800 Subject: commit raw file --- modules/base/markdown.go | 2 +- routers/repo/repo.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'routers/repo/repo.go') diff --git a/modules/base/markdown.go b/modules/base/markdown.go index a98ca8cf..962e1ae1 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -53,7 +53,7 @@ func IsTextFile(data []byte) (string, bool) { func IsImageFile(data []byte) (string, bool) { contentType := http.DetectContentType(data) - if strings.Index(contentType, "img/") != -1 { + if strings.Index(contentType, "image/") != -1 { return contentType, true } return contentType, false diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 8c686bc3..3b57cb39 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -225,8 +225,18 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { // Get tree path treename := params["_1"] - repoFile, err := models.GetTargetFile(params["username"], params["reponame"], - params["branchname"], params["commitid"], treename) + branchName := params["branchname"] + userName := params["username"] + repoName := params["reponame"] + + var commitId string + if !models.IsBranchExist(userName, repoName, branchName) { + commitId = branchName + branchName = "" + } + + repoFile, err := models.GetTargetFile(userName, repoName, + branchName, commitId, treename) if err != nil { ctx.Handle(404, "repo.SingleDownload(GetTargetFile)", err) -- cgit v1.2.3 From 5344a0300383c4921e4a5810dff58c7686412f0c Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 27 Mar 2014 21:15:53 -0400 Subject: Bug fix --- modules/middleware/repo.go | 4 +++- routers/repo/issue.go | 3 +++ routers/repo/repo.go | 4 +++- templates/repo/toolbar.tmpl | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) (limited to 'routers/repo/repo.go') diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index bc90c05c..cb4a8632 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -56,7 +56,9 @@ func RepoAssignment(redirect bool) martini.Handler { // get repository repo, err := models.GetRepositoryByName(user.Id, params["reponame"]) if err != nil { - if redirect { + if err == models.ErrRepoNotExist { + ctx.Handle(404, "RepoAssignment", err) + } else if redirect { ctx.Redirect("/") return } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index ba0669a0..77e35bba 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -6,6 +6,7 @@ package repo import ( "fmt" + "net/url" "github.com/codegangsta/martini" @@ -35,7 +36,9 @@ func Issues(ctx *middleware.Context) { var posterId int64 = 0 if ctx.Query("type") == "created_by" { if !ctx.IsSigned { + ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) ctx.Redirect("/user/login/", 302) + return } posterId = ctx.User.Id ctx.Data["ViewType"] = "created_by" diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 3b57cb39..e7107ad1 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -85,9 +85,11 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Branches"] = brs var commitId string - if !models.IsBranchExist(userName, repoName, branchName) { + isViewBranch := models.IsBranchExist(userName, repoName, branchName) + if !isViewBranch { commitId = branchName } + ctx.Data["IsViewBranch"] = isViewBranch repoFile, err := models.GetTargetFile(userName, repoName, branchName, commitId, treename) diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index e3390c77..ac516c37 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -5,7 +5,7 @@