Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2018 The Gitea 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. "net/http"
  7. "strings"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/log"
  11. )
  12. // TopicsPost response for creating repository
  13. func TopicsPost(ctx *context.Context) {
  14. if ctx.User == nil {
  15. ctx.JSON(http.StatusForbidden, map[string]interface{}{
  16. "message": "Only owners could change the topics.",
  17. })
  18. return
  19. }
  20. var topics = make([]string, 0)
  21. var topicsStr = strings.TrimSpace(ctx.Query("topics"))
  22. if len(topicsStr) > 0 {
  23. topics = strings.Split(topicsStr, ",")
  24. }
  25. validTopics, invalidTopics := models.SanitizeAndValidateTopics(topics)
  26. if len(validTopics) > 25 {
  27. ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{
  28. "invalidTopics": nil,
  29. "message": ctx.Tr("repo.topic.count_prompt"),
  30. })
  31. return
  32. }
  33. if len(invalidTopics) > 0 {
  34. ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{
  35. "invalidTopics": invalidTopics,
  36. "message": ctx.Tr("repo.topic.format_prompt"),
  37. })
  38. return
  39. }
  40. err := models.SaveTopics(ctx.Repo.Repository.ID, validTopics...)
  41. if err != nil {
  42. log.Error("SaveTopics failed: %v", err)
  43. ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
  44. "message": "Save topics failed.",
  45. })
  46. return
  47. }
  48. ctx.JSON(http.StatusOK, map[string]interface{}{
  49. "status": "ok",
  50. })
  51. }