gitea源码

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "encoding/base64"
  6. "net/http"
  7. api "code.gitea.io/gitea/modules/structs"
  8. "code.gitea.io/gitea/modules/web"
  9. "code.gitea.io/gitea/services/context"
  10. repo_service "code.gitea.io/gitea/services/repository"
  11. )
  12. // UpdateVatar updates the Avatar of an Repo
  13. func UpdateAvatar(ctx *context.APIContext) {
  14. // swagger:operation POST /repos/{owner}/{repo}/avatar repository repoUpdateAvatar
  15. // ---
  16. // summary: Update avatar
  17. // produces:
  18. // - application/json
  19. // parameters:
  20. // - name: owner
  21. // in: path
  22. // description: owner of the repo
  23. // type: string
  24. // required: true
  25. // - name: repo
  26. // in: path
  27. // description: name of the repo
  28. // type: string
  29. // required: true
  30. // - name: body
  31. // in: body
  32. // schema:
  33. // "$ref": "#/definitions/UpdateRepoAvatarOption"
  34. // responses:
  35. // "204":
  36. // "$ref": "#/responses/empty"
  37. // "404":
  38. // "$ref": "#/responses/notFound"
  39. form := web.GetForm(ctx).(*api.UpdateRepoAvatarOption)
  40. content, err := base64.StdEncoding.DecodeString(form.Image)
  41. if err != nil {
  42. ctx.APIError(http.StatusBadRequest, err)
  43. return
  44. }
  45. err = repo_service.UploadAvatar(ctx, ctx.Repo.Repository, content)
  46. if err != nil {
  47. ctx.APIErrorInternal(err)
  48. }
  49. ctx.Status(http.StatusNoContent)
  50. }
  51. // UpdateAvatar deletes the Avatar of an Repo
  52. func DeleteAvatar(ctx *context.APIContext) {
  53. // swagger:operation DELETE /repos/{owner}/{repo}/avatar repository repoDeleteAvatar
  54. // ---
  55. // summary: Delete avatar
  56. // produces:
  57. // - application/json
  58. // parameters:
  59. // - name: owner
  60. // in: path
  61. // description: owner of the repo
  62. // type: string
  63. // required: true
  64. // - name: repo
  65. // in: path
  66. // description: name of the repo
  67. // type: string
  68. // required: true
  69. // responses:
  70. // "204":
  71. // "$ref": "#/responses/empty"
  72. // "404":
  73. // "$ref": "#/responses/notFound"
  74. err := repo_service.DeleteAvatar(ctx, ctx.Repo.Repository)
  75. if err != nil {
  76. ctx.APIErrorInternal(err)
  77. }
  78. ctx.Status(http.StatusNoContent)
  79. }