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.NotFoundOrServerError("get blob", gitutil.IsErrRevisionNotExist, err)
  24. return
  25. }
  26. if err = repo.ServeBlob(c.Context, blob); err != nil {
  27. c.ServerError("ServeBlob", err)
  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.ServerError("open repository", 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.Editorconfig()
  42. if err != nil {
  43. c.NotFoundOrServerError("get .editorconfig", gitutil.IsErrRevisionNotExist, err)
  44. return
  45. }
  46. fileName := c.Params("filename")
  47. def, err := ec.GetDefinitionForFilename(fileName)
  48. if err != nil {
  49. c.ServerError("get definition for filename", err)
  50. return
  51. }
  52. if def == nil {
  53. c.NotFound()
  54. return
  55. }
  56. c.JSONSuccess(def)
  57. }