本站源代码
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

61 lignes
1.4KB

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