From faea66fe9151607d3dab510de1b850e1f1016618 Mon Sep 17 00:00:00 2001 From: NextFire Date: Sat, 24 Aug 2024 15:41:43 +0200 Subject: [PATCH] server: trim author/token name --- server/model.go | 12 +++++++++++- ui/src/components/AuthorEditor.tsx | 4 +++- ui/src/components/MugenImport.tsx | 5 ++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/server/model.go b/server/model.go index 737fd8fe..8e2e2684 100644 --- a/server/model.go +++ b/server/model.go @@ -86,6 +86,11 @@ type TimingAuthor struct { MugenID *uuid.UUID `gorm:"uniqueIndex:idx_timing_author_mugen_id"` } +func (name *TimingAuthor) BeforeSave(tx *gorm.DB) error { + name.Name = trimWhitespace(name.Name) + return nil +} + type Scopes struct { Kara bool `json:"kara"` KaraRO bool `json:"kara_ro"` @@ -118,6 +123,11 @@ type TokenV2 struct { Scopes Scopes `gorm:"embedded" json:"scopes"` } +func (name *TokenV2) BeforeSave(tx *gorm.DB) error { + name.Name = trimWhitespace(name.Name) + return nil +} + // Artists type Artist struct { @@ -258,7 +268,7 @@ type AdditionalName struct { } func trimWhitespace(s string) string { - return strings.Trim(s, " \n") + return strings.Trim(s, " \t\n") } func (name *AdditionalName) BeforeSave(tx *gorm.DB) error { diff --git a/ui/src/components/AuthorEditor.tsx b/ui/src/components/AuthorEditor.tsx index e22c6c6c..ee2a02c1 100644 --- a/ui/src/components/AuthorEditor.tsx +++ b/ui/src/components/AuthorEditor.tsx @@ -10,7 +10,9 @@ export default function AuthorEditor(props: { const onsubmit: JSX.EventHandler = (e) => { e.preventDefault(); - props.onSubmit({ name: getName() }); + props.onSubmit({ + name: getName(), + }); if (props.reset) { (e.target as HTMLFormElement).reset(); } diff --git a/ui/src/components/MugenImport.tsx b/ui/src/components/MugenImport.tsx index 2962a966..834c25a9 100644 --- a/ui/src/components/MugenImport.tsx +++ b/ui/src/components/MugenImport.tsx @@ -8,7 +8,10 @@ export default function MugenImport(props: { const [getInput, setInput] = createSignal(""); const [getName, setName] = createSignal(""); - const getKid = () => getInput().split("/").pop() ?? getInput(); + const getKid = () => { + const input = getInput().trim(); + return input.split("/").pop() ?? input; + }; createEffect(async () => { if (getKid().length !== 36) {