file.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package repo
  7. import (
  8. "gitote/gitote/models"
  9. "gitote/gitote/pkg/context"
  10. "gitote/gitote/routes/repo"
  11. "gitlab.com/gitote/git-module"
  12. )
  13. func GetRawFile(c *context.APIContext) {
  14. if !c.Repo.HasAccess() {
  15. c.Status(404)
  16. return
  17. }
  18. if c.Repo.Repository.IsBare {
  19. c.Status(404)
  20. return
  21. }
  22. blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
  23. if err != nil {
  24. if git.IsErrNotExist(err) {
  25. c.Status(404)
  26. } else {
  27. c.Error(500, "GetBlobByPath", err)
  28. }
  29. return
  30. }
  31. if err = repo.ServeBlob(c.Context, blob); err != nil {
  32. c.Error(500, "ServeBlob", err)
  33. }
  34. }
  35. func GetArchive(c *context.APIContext) {
  36. repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
  37. gitRepo, err := git.OpenRepository(repoPath)
  38. if err != nil {
  39. c.Error(500, "OpenRepository", err)
  40. return
  41. }
  42. c.Repo.GitRepo = gitRepo
  43. repo.Download(c.Context)
  44. }
  45. func GetEditorconfig(c *context.APIContext) {
  46. ec, err := c.Repo.GetEditorconfig()
  47. if err != nil {
  48. if git.IsErrNotExist(err) {
  49. c.Error(404, "GetEditorconfig", err)
  50. } else {
  51. c.Error(500, "GetEditorconfig", err)
  52. }
  53. return
  54. }
  55. fileName := c.Params("filename")
  56. def := ec.GetDefinitionForFilename(fileName)
  57. if def == nil {
  58. c.Error(404, "GetDefinitionForFilename", err)
  59. return
  60. }
  61. c.JSON(200, def)
  62. }