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;
}
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);

View File

@@ -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)
}