file.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/route/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 := db.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, err := ec.GetDefinitionForFilename(fileName)
  47. if err != nil {
  48. c.ServerError("GetDefinitionForFilename", err)
  49. return
  50. }
  51. if def == nil {
  52. c.NotFound()
  53. return
  54. }
  55. c.JSONSuccess(def)
  56. }