You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package v1
  5. import (
  6. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/git"
  8. "github.com/gogits/gogs/modules/middleware"
  9. "github.com/gogits/gogs/routers/repo"
  10. )
  11. func GetRepoRawFile(ctx *middleware.Context) {
  12. if !ctx.Repo.HasAccess() {
  13. ctx.Error(404)
  14. return
  15. }
  16. blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
  17. if err != nil {
  18. if err == git.ErrNotExist {
  19. ctx.Error(404)
  20. } else {
  21. ctx.APIError(500, "GetBlobByPath", err)
  22. }
  23. return
  24. }
  25. if err = repo.ServeBlob(ctx, blob); err != nil {
  26. ctx.APIError(500, "ServeBlob", err)
  27. }
  28. }
  29. func GetRepoArchive(ctx *middleware.Context) {
  30. repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
  31. gitRepo, err := git.OpenRepository(repoPath)
  32. if err != nil {
  33. ctx.APIError(500, "OpenRepository", err)
  34. return
  35. }
  36. ctx.Repo.GitRepo = gitRepo
  37. repo.Download(ctx)
  38. }