repo_file.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/base"
  8. "github.com/gogits/gogs/modules/git"
  9. "github.com/gogits/gogs/modules/middleware"
  10. "github.com/gogits/gogs/routers/repo"
  11. )
  12. func GetRepoRawFile(ctx *middleware.Context) {
  13. if !ctx.Repo.HasAccess() {
  14. ctx.Error(404)
  15. return
  16. }
  17. blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
  18. if err != nil {
  19. if err == git.ErrNotExist {
  20. ctx.Error(404)
  21. } else {
  22. ctx.JSON(500, &base.ApiJsonErr{"GetBlobByPath: " + err.Error(), base.DOC_URL})
  23. }
  24. return
  25. }
  26. if err = repo.ServeBlob(ctx, blob); err != nil {
  27. ctx.JSON(500, &base.ApiJsonErr{"ServeBlob: " + err.Error(), base.DOC_URL})
  28. }
  29. }
  30. func GetRepoArchive(ctx *middleware.Context) {
  31. repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
  32. gitRepo, err := git.OpenRepository(repoPath)
  33. if err != nil {
  34. ctx.Handle(500, "RepoAssignment Invalid repo: "+repoPath, err)
  35. return
  36. }
  37. ctx.Repo.GitRepo = gitRepo
  38. repo.Download(ctx)
  39. }