You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

file.go 1.8 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. "code.gitea.io/git"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/context"
  9. "code.gitea.io/gitea/routers/repo"
  10. )
  11. // GetRawFile get a file by path on a repository
  12. // see https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
  13. func GetRawFile(ctx *context.APIContext) {
  14. if !ctx.Repo.HasAccess() {
  15. ctx.Status(404)
  16. return
  17. }
  18. if ctx.Repo.Repository.IsBare {
  19. ctx.Status(404)
  20. return
  21. }
  22. blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
  23. if err != nil {
  24. if git.IsErrNotExist(err) {
  25. ctx.Status(404)
  26. } else {
  27. ctx.Error(500, "GetBlobByPath", err)
  28. }
  29. return
  30. }
  31. if err = repo.ServeBlob(ctx.Context, blob); err != nil {
  32. ctx.Error(500, "ServeBlob", err)
  33. }
  34. }
  35. // GetArchive get archive of a repository
  36. // see https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
  37. func GetArchive(ctx *context.APIContext) {
  38. repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
  39. gitRepo, err := git.OpenRepository(repoPath)
  40. if err != nil {
  41. ctx.Error(500, "OpenRepository", err)
  42. return
  43. }
  44. ctx.Repo.GitRepo = gitRepo
  45. repo.Download(ctx.Context)
  46. }
  47. // GetEditorconfig get editor config of a repository
  48. func GetEditorconfig(ctx *context.APIContext) {
  49. ec, err := ctx.Repo.GetEditorconfig()
  50. if err != nil {
  51. if git.IsErrNotExist(err) {
  52. ctx.Error(404, "GetEditorconfig", err)
  53. } else {
  54. ctx.Error(500, "GetEditorconfig", err)
  55. }
  56. return
  57. }
  58. fileName := ctx.Params("filename")
  59. def := ec.GetDefinitionForFilename(fileName)
  60. if def == nil {
  61. ctx.Error(404, "GetDefinitionForFilename", err)
  62. return
  63. }
  64. ctx.JSON(200, def)
  65. }