file.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/G-Node/git-module"
  7. "github.com/G-Node/gogs/models"
  8. "github.com/G-Node/gogs/pkg/context"
  9. "github.com/G-Node/gogs/routes/repo"
  10. "github.com/go-macaron/captcha"
  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.GetBlobByPath(c.Repo.TreePath)
  22. if err != nil {
  23. c.NotFoundOrServerError("GetBlobByPath", git.IsErrNotExist, err)
  24. return
  25. }
  26. cp := captcha.NewCaptcha(captcha.Options{})
  27. if err = repo.ServeBlob(c.Context, blob, cp); err != nil {
  28. c.ServerError("ServeBlob", err)
  29. }
  30. }
  31. func GetArchive(c *context.APIContext) {
  32. repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
  33. gitRepo, err := git.OpenRepository(repoPath)
  34. if err != nil {
  35. c.ServerError("OpenRepository", err)
  36. return
  37. }
  38. c.Repo.GitRepo = gitRepo
  39. repo.Download(c.Context)
  40. }
  41. func GetEditorconfig(c *context.APIContext) {
  42. ec, err := c.Repo.GetEditorconfig()
  43. if err != nil {
  44. c.NotFoundOrServerError("GetEditorconfig", git.IsErrNotExist, err)
  45. return
  46. }
  47. fileName := c.Params("filename")
  48. def := ec.GetDefinitionForFilename(fileName)
  49. if def == nil {
  50. c.NotFound()
  51. return
  52. }
  53. c.JSONSuccess(def)
  54. }