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 | |
parent | 340a4595ddc9e08f4c51f40496affb8fd3bb013d (diff) | |
download | gitea-a0f9197b4573aa9d4d868637ed00e710a435797b.tar.gz gitea-a0f9197b4573aa9d4d868637ed00e710a435797b.zip |
GetFile api
Diffstat (limited to 'routers/api/v1')
-rw-r--r-- | routers/api/v1/repo.go | 16 | ||||
-rw-r--r-- | routers/api/v1/repo_file.go | 27 |
2 files changed, 31 insertions, 12 deletions
diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go index aeb22876bc..33e3b05a4b 100644 --- a/routers/api/v1/repo.go +++ b/routers/api/v1/repo.go @@ -15,6 +15,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" @@ -161,20 +162,14 @@ func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) { func ListMyRepos(ctx *middleware.Context) { ownRepos, err := models.GetRepositories(ctx.User.Id, true) if err != nil { - ctx.JSON(500, map[string]interface{}{ - "ok": false, - "error": err.Error(), - }) + ctx.JSON(500, &base.ApiJsonErr{"GetRepositories: " + err.Error(), base.DOC_URL}) return } numOwnRepos := len(ownRepos) collaRepos, err := models.GetCollaborativeRepos(ctx.User.Name) if err != nil { - ctx.JSON(500, map[string]interface{}{ - "ok": false, - "error": err.Error(), - }) + ctx.JSON(500, &base.ApiJsonErr{"GetCollaborativeRepos: " + err.Error(), base.DOC_URL}) return } @@ -204,10 +199,7 @@ func ListMyRepos(ctx *middleware.Context) { } for i := range collaRepos { if err = collaRepos[i].GetOwner(); err != nil { - ctx.JSON(500, map[string]interface{}{ - "ok": false, - "error": err.Error(), - }) + ctx.JSON(500, &base.ApiJsonErr{"GetOwner: " + err.Error(), base.DOC_URL}) return } j := i + numOwnRepos 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}) + } +} |