Skip to content

Commit

Permalink
server: trim author/token name
Browse files Browse the repository at this point in the history
NextFire committed Aug 24, 2024

Verified

This commit was signed with the committer’s verified signature.
ekohl Ewoud Kohl van Wijngaarden
1 parent c7ea499 commit faea66f
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
@@ -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 {
4 changes: 3 additions & 1 deletion ui/src/components/AuthorEditor.tsx
Original file line number Diff line number Diff line change
@@ -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();
}
5 changes: 4 additions & 1 deletion ui/src/components/MugenImport.tsx
Original file line number Diff line number Diff line change
@@ -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) {

0 comments on commit faea66f

Please sign in to comment.