mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 04:17:23 +00:00
improve tag creating
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"net/url"
|
||||
"nysoure/server/model"
|
||||
"nysoure/server/service"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
maxTagNameLength = 20
|
||||
)
|
||||
|
||||
func handleCreateTag(c fiber.Ctx) error {
|
||||
@@ -15,6 +20,9 @@ func handleCreateTag(c fiber.Ctx) error {
|
||||
return model.NewRequestError("name is required")
|
||||
}
|
||||
tag = strings.TrimSpace(tag)
|
||||
if len([]rune(tag)) > maxTagNameLength {
|
||||
return model.NewRequestError("Tag name too long")
|
||||
}
|
||||
uid, ok := c.Locals("uid").(uint)
|
||||
if !ok {
|
||||
return model.NewUnAuthorizedError("You must be logged in to create a tag")
|
||||
@@ -159,6 +167,9 @@ func getOrCreateTags(c fiber.Ctx) error {
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
if len([]rune(name)) > maxTagNameLength {
|
||||
return model.NewRequestError("Tag name too long: " + name)
|
||||
}
|
||||
names = append(names, name)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user