diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-11-16 21:32:26 -0500 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-11-16 21:32:26 -0500 |
commit | a0f9197b4573aa9d4d868637ed00e710a435797b (patch) | |
tree | 41efdcb5813cdb1a66bd1fc3bc5c86a371c7815b /routers/api/v1/repo_file.go | |
parent | 340a4595ddc9e08f4c51f40496affb8fd3bb013d (diff) | |
download | gitea-a0f9197b4573aa9d4d868637ed00e710a435797b.tar.gz gitea-a0f9197b4573aa9d4d868637ed00e710a435797b.zip |
GetFile api
Diffstat (limited to 'routers/api/v1/repo_file.go')
-rw-r--r-- | routers/api/v1/repo_file.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/routers/api/v1/repo_file.go b/routers/api/v1/repo_file.go index ca06a2e9b8..a049904f95 100644 --- a/routers/api/v1/repo_file.go +++ b/routers/api/v1/repo_file.go @@ -3,3 +3,30 @@ // license that can be found in the LICENSE file. package v1 + +import ( + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/git" + "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/routers/repo" +) + +func GetRepoRawFile(ctx *middleware.Context) { + if ctx.Repo.Repository.IsPrivate && !ctx.Repo.HasAccess { + ctx.Error(404) + return + } + + blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName) + if err != nil { + if err == git.ErrNotExist { + ctx.Error(404) + } else { + ctx.JSON(500, &base.ApiJsonErr{"GetBlobByPath: " + err.Error(), base.DOC_URL}) + } + return + } + if err = repo.ServeBlob(ctx, blob); err != nil { + ctx.JSON(500, &base.ApiJsonErr{"ServeBlob: " + err.Error(), base.DOC_URL}) + } +} |