repo_file.go 821 B

1234567891011121314151617181920212223242526272829303132
  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/modules/base"
  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.JSON(500, &base.ApiJsonErr{"GetBlobByPath: " + err.Error(), base.DOC_URL})
  22. }
  23. return
  24. }
  25. if err = repo.ServeBlob(ctx, blob); err != nil {
  26. ctx.JSON(500, &base.ApiJsonErr{"ServeBlob: " + err.Error(), base.DOC_URL})
  27. }
  28. }