From b8acd97c1108b33dfd29bfda4a313935551c3abf Mon Sep 17 00:00:00 2001 From: nyne Date: Fri, 5 Sep 2025 16:22:43 +0800 Subject: [PATCH] improve tag creating --- frontend/src/components/tag_input.tsx | 6 +++++- server/api/tag.go | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/tag_input.tsx b/frontend/src/components/tag_input.tsx index fc50661..c7c7651 100644 --- a/frontend/src/components/tag_input.tsx +++ b/frontend/src/components/tag_input.tsx @@ -203,7 +203,11 @@ export function QuickAddTagDialog({ return; } setError(null); - const names = text.split(separator).filter((n) => n.length > 0); + let sep: string | RegExp = separator; + if (sep === " ") { + sep = /\s+/; + } + const names = text.split(sep).filter((n) => n.length > 0); setLoading(true); const res = await network.getOrCreateTags(names, type); setLoading(false); diff --git a/server/api/tag.go b/server/api/tag.go index eb709f9..c019bf5 100644 --- a/server/api/tag.go +++ b/server/api/tag.go @@ -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) }