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.

attachments.go 1.8 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package repo
  2. import (
  3. "net/http"
  4. "code.gitea.io/gitea/modules/log"
  5. "code.gitea.io/gitea/models"
  6. "code.gitea.io/gitea/modules/context"
  7. routeRepo "code.gitea.io/gitea/routers/repo"
  8. )
  9. func GetSuccessChunks(ctx *context.APIContext) {
  10. if errStr := checkDatasetPermission(ctx); errStr != "" {
  11. ctx.JSON(http.StatusForbidden, ctx.Tr(errStr))
  12. }
  13. routeRepo.GetSuccessChunks(ctx.Context)
  14. }
  15. func checkDatasetPermission(ctx *context.APIContext) string {
  16. datasetId := ctx.QueryInt64("dataset_id")
  17. dataset, err := models.GetDatasetByID(datasetId)
  18. if err != nil {
  19. log.Warn("can not find dataset", err)
  20. return "dataset.query_dataset_fail"
  21. }
  22. repo, err := models.GetRepositoryByID(dataset.RepoID)
  23. if err != nil {
  24. log.Warn("can not find repo", err)
  25. return "dataset.query_dataset_fail"
  26. }
  27. permission, err := models.GetUserRepoPermission(repo, ctx.User)
  28. if err != nil {
  29. log.Warn("can not find repo permission for user", err)
  30. return "dataset.query_dataset_fail"
  31. }
  32. if !permission.CanWrite(models.UnitTypeDatasets) {
  33. return "error.no_right"
  34. }
  35. return ""
  36. }
  37. func NewMultipart(ctx *context.APIContext) {
  38. if errStr := checkDatasetPermission(ctx); errStr != "" {
  39. ctx.JSON(http.StatusForbidden, ctx.Tr(errStr))
  40. }
  41. routeRepo.NewMultipart(ctx.Context)
  42. }
  43. func GetMultipartUploadUrl(ctx *context.APIContext) {
  44. if errStr := checkDatasetPermission(ctx); errStr != "" {
  45. ctx.JSON(http.StatusForbidden, ctx.Tr(errStr))
  46. }
  47. routeRepo.GetMultipartUploadUrl(ctx.Context)
  48. }
  49. func CompleteMultipart(ctx *context.APIContext) {
  50. if errStr := checkDatasetPermission(ctx); errStr != "" {
  51. ctx.JSON(http.StatusForbidden, ctx.Tr(errStr))
  52. }
  53. routeRepo.CompleteMultipart(ctx.Context)
  54. }
  55. func GetAttachment(ctx *context.APIContext) {
  56. routeRepo.GetAttachment(ctx.Context)
  57. }