Skip to content

Commit

Permalink
server: trim author/token name
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Aug 24, 2024
1 parent c7ea499 commit f9073e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 11 additions & 1 deletion server/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -258,7 +268,7 @@ type AdditionalName struct {
}

func trimWhitespace(s string) string {
return strings.Trim(s, " \n")
return strings.Trim(s, " \n\t")
}

func (name *AdditionalName) BeforeSave(tx *gorm.DB) error {
Expand Down
4 changes: 3 additions & 1 deletion ui/src/components/AuthorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default function AuthorEditor(props: {

const onsubmit: JSX.EventHandler<HTMLElement, SubmitEvent> = (e) => {
e.preventDefault();
props.onSubmit({ name: getName() });
props.onSubmit({
name: getName(),
});
if (props.reset) {
(e.target as HTMLFormElement).reset();
}
Expand Down
5 changes: 4 additions & 1 deletion ui/src/components/MugenImport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f9073e2

Please sign in to comment.