file.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. "gogs.io/gogs/internal/context"
  8. "gogs.io/gogs/internal/db"
  9. "gogs.io/gogs/internal/gitutil"
  10. "gogs.io/gogs/internal/route/repo"
  11. )
  12. func GetRawFile(c *context.APIContext) {
  13. if !c.Repo.HasAccess() {
  14. c.NotFound()
  15. return
  16. }
  17. if c.Repo.Repository.IsBare {
  18. c.NotFound()
  19. return
  20. }
  21. blob, err := c.Repo.Commit.Blob(c.Repo.TreePath)
  22. if err != nil {
  23. c.NotFoundOrError(gitutil.NewError(err), "get blob")
  24. return
  25. }
  26. if err = repo.ServeBlob(c.Context, blob); err != nil {
  27. c.Error(err, "serve blob")
  28. }
  29. }
  30. func GetArchive(c *context.APIContext) {
  31. repoPath := db.RepoPath(c.Params(":username"), c.Params(":reponame"))
  32. gitRepo, err := git.Open(repoPath)
  33. if err != nil {
  34. c.Error(err, "open repository")
  35. return
  36. }
  37. c.Repo.GitRepo = gitRepo
  38. repo.Download(c.Context)
  39. }
  40. func GetEditorconfig(c *context.APIContext) {
  41. ec, err := c.Repo.Editorconfig()
  42. if err != nil {
  43. c.NotFoundOrError(gitutil.NewError(err), "get .editorconfig")
  44. return
  45. }
  46. fileName := c.Params("filename")
  47. def, err := ec.GetDefinitionForFilename(fileName)
  48. if err != nil {
  49. c.Error(err, "get definition for filename")
  50. return
  51. }
  52. if def == nil {
  53. c.NotFound()
  54. return
  55. }
  56. c.JSONSuccess(def)
  57. }