improve tag creating

This commit is contained in:
2025-09-05 16:22:43 +08:00
parent 8f240823ef
commit b8acd97c11
2 changed files with 17 additions and 2 deletions

View File

@@ -203,7 +203,11 @@ export function QuickAddTagDialog({
return; return;
} }
setError(null); 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); setLoading(true);
const res = await network.getOrCreateTags(names, type); const res = await network.getOrCreateTags(names, type);
setLoading(false); setLoading(false);

View File

@@ -1,12 +1,17 @@
package api package api
import ( import (
"github.com/gofiber/fiber/v3"
"net/url" "net/url"
"nysoure/server/model" "nysoure/server/model"
"nysoure/server/service" "nysoure/server/service"
"strconv" "strconv"
"strings" "strings"
"github.com/gofiber/fiber/v3"
)
const (
maxTagNameLength = 20
) )
func handleCreateTag(c fiber.Ctx) error { func handleCreateTag(c fiber.Ctx) error {
@@ -15,6 +20,9 @@ func handleCreateTag(c fiber.Ctx) error {
return model.NewRequestError("name is required") return model.NewRequestError("name is required")
} }
tag = strings.TrimSpace(tag) tag = strings.TrimSpace(tag)
if len([]rune(tag)) > maxTagNameLength {
return model.NewRequestError("Tag name too long")
}
uid, ok := c.Locals("uid").(uint) uid, ok := c.Locals("uid").(uint)
if !ok { if !ok {
return model.NewUnAuthorizedError("You must be logged in to create a tag") return model.NewUnAuthorizedError("You must be logged in to create a tag")
@@ -159,6 +167,9 @@ func getOrCreateTags(c fiber.Ctx) error {
if name == "" { if name == "" {
continue continue
} }
if len([]rune(name)) > maxTagNameLength {
return model.NewRequestError("Tag name too long: " + name)
}
names = append(names, name) names = append(names, name)
} }