summaryrefslogtreecommitdiffstats
path: root/routers/repo/download.go
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-11-16 21:32:26 -0500
committerUnknwon <joe2010xtmf@163.com>2014-11-16 21:32:26 -0500
commita0f9197b4573aa9d4d868637ed00e710a435797b (patch)
tree41efdcb5813cdb1a66bd1fc3bc5c86a371c7815b /routers/repo/download.go
parent340a4595ddc9e08f4c51f40496affb8fd3bb013d (diff)
downloadgitea-a0f9197b4573aa9d4d868637ed00e710a435797b.tar.gz
gitea-a0f9197b4573aa9d4d868637ed00e710a435797b.zip
GetFile api
Diffstat (limited to 'routers/repo/download.go')
-rw-r--r--routers/repo/download.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/routers/repo/download.go b/routers/repo/download.go
index 17642a57ea..6367c40e28 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -9,20 +9,14 @@ import (
"path"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/middleware"
)
-func SingleDownload(ctx *middleware.Context) {
- blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
- if err != nil {
- ctx.Handle(500, "GetBlobByPath", err)
- return
- }
-
+func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
dataRc, err := blob.Data()
if err != nil {
- ctx.Handle(500, "Data", err)
- return
+ return err
}
buf := make([]byte, 1024)
@@ -40,4 +34,20 @@ func SingleDownload(ctx *middleware.Context) {
}
ctx.Resp.Write(buf)
io.Copy(ctx.Resp, dataRc)
+ return nil
+}
+
+func SingleDownload(ctx *middleware.Context) {
+ blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
+ if err != nil {
+ if err == git.ErrNotExist {
+ ctx.Handle(404, "GetBlobByPath", nil)
+ } else {
+ ctx.Handle(500, "GetBlobByPath", err)
+ }
+ return
+ }
+ if err = ServeBlob(ctx, blob); err != nil {
+ ctx.Handle(500, "ServeBlob", err)
+ }
}