From d951824ff9c52919e2821d0e9be2504550a994fc Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 2 Sep 2015 09:54:35 -0400 Subject: [PATCH] able to download archive by API --- cmd/web.go | 1 + routers/api/v1/repo_file.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/cmd/web.go b/cmd/web.go index d3d339de4..641e331b4 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -243,6 +243,7 @@ func runWeb(ctx *cli.Context) { Post(bind(api.CreateHookOption{}), v1.CreateRepoHook) m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook) m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile) + m.Get("/archive/*", v1.GetRepoArchive) }, middleware.ApiRepoAssignment(), middleware.ApiReqToken()) }) diff --git a/routers/api/v1/repo_file.go b/routers/api/v1/repo_file.go index 73f97b2ca..540cd32fa 100644 --- a/routers/api/v1/repo_file.go +++ b/routers/api/v1/repo_file.go @@ -5,6 +5,7 @@ package v1 import ( + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/middleware" @@ -30,3 +31,15 @@ func GetRepoRawFile(ctx *middleware.Context) { ctx.JSON(500, &base.ApiJsonErr{"ServeBlob: " + err.Error(), base.DOC_URL}) } } + +func GetRepoArchive(ctx *middleware.Context) { + repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame")) + gitRepo, err := git.OpenRepository(repoPath) + if err != nil { + ctx.Handle(500, "RepoAssignment Invalid repo: "+repoPath, err) + return + } + ctx.Repo.GitRepo = gitRepo + + repo.Download(ctx) +}