file.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package repo
  2. import (
  3. "gitote/gitote/models"
  4. "gitote/gitote/pkg/context"
  5. "gitote/gitote/routes/repo"
  6. "gitlab.com/gitote/git-module"
  7. )
  8. func GetRawFile(c *context.APIContext) {
  9. if !c.Repo.HasAccess() {
  10. c.Status(404)
  11. return
  12. }
  13. if c.Repo.Repository.IsBare {
  14. c.Status(404)
  15. return
  16. }
  17. blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
  18. if err != nil {
  19. if git.IsErrNotExist(err) {
  20. c.Status(404)
  21. } else {
  22. c.Error(500, "GetBlobByPath", err)
  23. }
  24. return
  25. }
  26. if err = repo.ServeBlob(c.Context, blob); err != nil {
  27. c.Error(500, "ServeBlob", err)
  28. }
  29. }
  30. func GetArchive(c *context.APIContext) {
  31. repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
  32. gitRepo, err := git.OpenRepository(repoPath)
  33. if err != nil {
  34. c.Error(500, "OpenRepository", err)
  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.GetEditorconfig()
  42. if err != nil {
  43. if git.IsErrNotExist(err) {
  44. c.Error(404, "GetEditorconfig", err)
  45. } else {
  46. c.Error(500, "GetEditorconfig", err)
  47. }
  48. return
  49. }
  50. fileName := c.Params("filename")
  51. def := ec.GetDefinitionForFilename(fileName)
  52. if def == nil {
  53. c.Error(404, "GetDefinitionForFilename", err)
  54. return
  55. }
  56. c.JSON(200, def)
  57. }