Posts have a minimum edit limit of 5 characters

This commit is contained in:
Eduard Urbach 2020-04-14 09:11:38 +09:00
parent 8258b7c544
commit 42366174e5
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
4 changed files with 18 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/aerogo/api"
"github.com/aerogo/markdown"
"github.com/animenotifier/notify.moe/arn/autocorrect"
"github.com/animenotifier/notify.moe/arn/limits"
)
// Force interface implementations
@ -83,8 +84,8 @@ func (post *Post) Create(ctx aero.Context) error {
// Post-process text
post.Text = autocorrect.PostText(post.Text)
if len(post.Text) < 5 {
return errors.New("Text too short: Should be at least 5 characters")
if len(post.Text) < limits.PostMinCharacters {
return fmt.Errorf("Text too short: Should be at least %d characters", limits.PostMinCharacters)
}
// Tags
@ -207,6 +208,17 @@ func (post *Post) Edit(ctx aero.Context, key string, value reflect.Value, newVal
post.SetParent(newParent)
consumed = true
case "Text":
newText := newValue.String()
newText = autocorrect.PostText(newText)
if len(newText) < limits.PostMinCharacters {
return false, fmt.Errorf("Text too short: Should be at least %d characters", limits.PostMinCharacters)
}
post.Text = newText
consumed = true
}
// Write log entry

View File

@ -3,4 +3,5 @@ package limits
const (
DefaultTextMaxLength = 100
DefaultTextAreaMaxLength = 20000
PostMinCharacters = 5
)

2
go.mod
View File

@ -6,7 +6,7 @@ require (
cloud.google.com/go v0.56.0 // indirect
github.com/PuerkitoBio/goquery v1.5.1 // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/aerogo/aero v1.3.52
github.com/aerogo/aero v1.3.53
github.com/aerogo/api v0.2.3
github.com/aerogo/crawler v0.2.5
github.com/aerogo/flow v0.1.5

2
go.sum
View File

@ -39,6 +39,8 @@ github.com/aerogo/aero v1.3.29/go.mod h1:nHuG9q4VrzH7ZtiE1TEIt9Lazp/w3WpC3nqAKRE
github.com/aerogo/aero v1.3.30/go.mod h1:iAzV2JRnKAFOo/c+4KIgf35JGS82qMU4tI06ocHeRrk=
github.com/aerogo/aero v1.3.52 h1:oeAZVL2QHVBxXJeLvoKgt4ihygS/XrFQCsaD7PNfRV0=
github.com/aerogo/aero v1.3.52/go.mod h1:3q0urf+LYebjm7rsfYpH0lYK2GvOeF0XVspgxKJCbqE=
github.com/aerogo/aero v1.3.53 h1:312N/1NvAAdZs65CaIYmKwflz4GFrssYFWDhVWTL4Bo=
github.com/aerogo/aero v1.3.53/go.mod h1:3q0urf+LYebjm7rsfYpH0lYK2GvOeF0XVspgxKJCbqE=
github.com/aerogo/api v0.2.3 h1:REQR3a6WXzaHpNSF9NCjj4HjvSQdcHrMWGnp/xIpCh4=
github.com/aerogo/api v0.2.3/go.mod h1:cClK+FXNc0IRGdDxAH5XmtibBxwUXCM2lLKMF7jKB+8=
github.com/aerogo/cluster v0.1.8 h1:N/jU2t7kQfKjXzQIArBQvtNkJCiaP9+jgdEid3P2Omc=