From 42366174e5dd4ca2026116e8a6c52a31dbbe5097 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 14 Apr 2020 09:11:38 +0900 Subject: [PATCH] Posts have a minimum edit limit of 5 characters --- arn/PostAPI.go | 16 ++++++++++++++-- arn/limits/limits.go | 1 + go.mod | 2 +- go.sum | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/arn/PostAPI.go b/arn/PostAPI.go index 21ace424..86c6c086 100644 --- a/arn/PostAPI.go +++ b/arn/PostAPI.go @@ -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 diff --git a/arn/limits/limits.go b/arn/limits/limits.go index e6049392..1faa9f2a 100644 --- a/arn/limits/limits.go +++ b/arn/limits/limits.go @@ -3,4 +3,5 @@ package limits const ( DefaultTextMaxLength = 100 DefaultTextAreaMaxLength = 20000 + PostMinCharacters = 5 ) diff --git a/go.mod b/go.mod index 5c09a1fc..45d315bc 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 3fdc64f5..4f6a5b76 100644 --- a/go.sum +++ b/go.sum @@ -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=