file.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 repo
  5. import (
  6. "github.com/gogs/git-module"
  7. "github.com/gogs/gogs/models"
  8. "github.com/gogs/gogs/pkg/context"
  9. "github.com/gogs/gogs/routes/repo"
  10. )
  11. func GetRawFile(c *context.APIContext) {
  12. if !c.Repo.HasAccess() {
  13. c.NotFound()
  14. return
  15. }
  16. if c.Repo.Repository.IsBare {
  17. c.NotFound()
  18. return
  19. }
  20. blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
  21. if err != nil {
  22. c.NotFoundOrServerError("GetBlobByPath", git.IsErrNotExist, err)
  23. return
  24. }
  25. if err = repo.ServeBlob(c.Context, blob); err != nil {
  26. c.ServerError("ServeBlob", err)
  27. }
  28. }
  29. func GetArchive(c *context.APIContext) {
  30. repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
  31. gitRepo, err := git.OpenRepository(repoPath)
  32. if err != nil {
  33. c.ServerError("OpenRepository", err)
  34. return
  35. }
  36. c.Repo.GitRepo = gitRepo
  37. repo.Download(c.Context)
  38. }
  39. func GetEditorconfig(c *context.APIContext) {
  40. ec, err := c.Repo.GetEditorconfig()
  41. if err != nil {
  42. c.NotFoundOrServerError("GetEditorconfig", git.IsErrNotExist, err)
  43. return
  44. }
  45. fileName := c.Params("filename")
  46. def := ec.GetDefinitionForFilename(fileName)
  47. if def == nil {
  48. c.NotFound()
  49. return
  50. }
  51. c.JSONSuccess(def)
  52. }