aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/dashboard.go9
-rw-r--r--routers/install.go13
-rw-r--r--routers/repo/issue.go1
-rw-r--r--routers/repo/repo.go75
4 files changed, 84 insertions, 14 deletions
diff --git a/routers/dashboard.go b/routers/dashboard.go
index 76ecc3f676..2c81cf23c1 100644
--- a/routers/dashboard.go
+++ b/routers/dashboard.go
@@ -5,6 +5,7 @@
package routers
import (
+ "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/routers/user"
)
@@ -14,6 +15,14 @@ func Home(ctx *middleware.Context) {
user.Dashboard(ctx)
return
}
+
+ // Check auto-login.
+ userName := ctx.GetCookie(base.CookieUserName)
+ if len(userName) != 0 {
+ ctx.Redirect("/user/login")
+ return
+ }
+
ctx.Data["PageIsHome"] = true
ctx.HTML(200, "home")
}
diff --git a/routers/install.go b/routers/install.go
new file mode 100644
index 0000000000..d7d5159efc
--- /dev/null
+++ b/routers/install.go
@@ -0,0 +1,13 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package routers
+
+import "github.com/gogits/gogs/modules/middleware"
+
+func Install(ctx *middleware.Context){
+ ctx.Data["PageIsInstall"] = true
+ ctx.Data["Title"] = "Install"
+ ctx.HTML(200,"install")
+}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index e03f115e24..d54582a2a0 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -45,6 +45,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
}
ctx.Data["Title"] = "Create issue"
+ ctx.Data["IsRepoToolbarIssues"] = true
if ctx.Req.Method == "GET" {
ctx.HTML(200, "issue/create")
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index a055b416c2..cd28d52caa 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -6,11 +6,11 @@ package repo
import (
"path"
+ "path/filepath"
"strings"
"github.com/codegangsta/martini"
- "github.com/gogits/git"
"github.com/gogits/webdav"
"github.com/gogits/gogs/models"
@@ -96,6 +96,7 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
branchLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/src/" + params["branchname"]
+ rawLink := "/" + ctx.Repo.Owner.LowerName + "/" + ctx.Repo.Repository.Name + "/raw/" + params["branchname"]
if len(treename) != 0 && repoFile == nil {
ctx.Handle(404, "repo.Single", nil)
@@ -103,12 +104,10 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
if repoFile != nil && repoFile.IsFile() {
- if repoFile.Size > 1024*1024 || repoFile.Filemode != git.FileModeBlob {
- ctx.Data["FileIsLarge"] = true
- } else if blob, err := repoFile.LookupBlob(); err != nil {
- //log.Error("repo.Single(repoFile.LookupBlob): %v", err)
+ if blob, err := repoFile.LookupBlob(); err != nil {
ctx.Handle(404, "repo.Single(repoFile.LookupBlob)", err)
} else {
+ ctx.Data["FileSize"] = repoFile.Size
ctx.Data["IsFile"] = true
ctx.Data["FileName"] = repoFile.Name
ext := path.Ext(repoFile.Name)
@@ -116,13 +115,20 @@ func Single(ctx *middleware.Context, params martini.Params) {
ext = ext[1:]
}
ctx.Data["FileExt"] = ext
+ ctx.Data["FileLink"] = rawLink + "/" + treename
+
+ data := blob.Contents()
+ _, isTextFile := base.IsTextFile(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(blob.Contents(), ""))
+ ctx.Data["FileContent"] = string(base.RenderMarkdown(data, ""))
} else {
- ctx.Data["FileContent"] = string(blob.Contents())
+ if isTextFile {
+ ctx.Data["FileContent"] = string(data)
+ }
}
}
@@ -150,18 +156,21 @@ func Single(ctx *middleware.Context, params martini.Params) {
}
if readmeFile != nil {
+ ctx.Data["ReadmeInSingle"] = true
ctx.Data["ReadmeExist"] = true
- // if file large than 1M not show it
- if readmeFile.Size > 1024*1024 || readmeFile.Filemode != git.FileModeBlob {
- ctx.Data["FileIsLarge"] = true
- } else if blob, err := readmeFile.LookupBlob(); err != nil {
+ if blob, err := readmeFile.LookupBlob(); err != nil {
ctx.Handle(404, "repo.Single(readmeFile.LookupBlob)", err)
return
} else {
- // current repo branch link
-
+ ctx.Data["FileSize"] = readmeFile.Size
+ ctx.Data["FileLink"] = rawLink + "/" + treename
+ data := blob.Contents()
+ _, isTextFile := base.IsTextFile(data)
+ ctx.Data["FileIsText"] = isTextFile
ctx.Data["FileName"] = readmeFile.Name
- ctx.Data["FileContent"] = string(base.RenderMarkdown(blob.Contents(), branchLink))
+ if isTextFile {
+ ctx.Data["FileContent"] = string(base.RenderMarkdown(data, branchLink))
+ }
}
}
}
@@ -201,6 +210,44 @@ func Single(ctx *middleware.Context, params martini.Params) {
ctx.HTML(200, "repo/single")
}
+func SingleDownload(ctx *middleware.Context, params martini.Params) {
+ if !ctx.Repo.IsValid {
+ ctx.Handle(404, "repo.SingleDownload", nil)
+ return
+ }
+
+ if len(params["branchname"]) == 0 {
+ params["branchname"] = "master"
+ }
+
+ // Get tree path
+ treename := params["_1"]
+
+ repoFile, err := models.GetTargetFile(params["username"], params["reponame"],
+ params["branchname"], params["commitid"], treename)
+
+ if err != nil {
+ ctx.Handle(404, "repo.SingleDownload(GetTargetFile)", err)
+ return
+ }
+
+ blob, err := repoFile.LookupBlob()
+ if err != nil {
+ ctx.Handle(404, "repo.SingleDownload(LookupBlob)", err)
+ return
+ }
+
+ data := blob.Contents()
+ contentType, isTextFile := base.IsTextFile(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")
+ }
+ ctx.Res.Write(data)
+}
+
func Http(ctx *middleware.Context, params martini.Params) {
/*if !ctx.Repo.IsValid {
return