diff --git a/front/alias.go b/front/alias.go index d04b27d0..ca1c327b 100644 --- a/front/alias.go +++ b/front/alias.go @@ -32,9 +32,13 @@ func (h *Handler) alias(w text.Writer, r *Request, args ...string) { now := time.Now() - if (r.User.Updated != nil && now.Sub(r.User.Updated.Time) < h.Config.MinActorEditInterval) || (r.User.Updated == nil && now.Sub(r.User.Published.Time) < h.Config.MinActorEditInterval) { - r.Log.Warn("Throttled request to set alias") - w.Status(40, "Please try again later") + can := r.User.Published.Time.Add(h.Config.MinActorEditInterval) + if r.User.Updated != nil { + can = r.User.Updated.Time.Add(h.Config.MinActorEditInterval) + } + if now.Before(can) { + r.Log.Warn("Throttled request to set alias", "can", can) + w.Statusf(40, "Please wait for %s", time.Until(can).Truncate(time.Second).String()) return } diff --git a/front/avatar.go b/front/avatar.go index b31fee1c..0d195611 100644 --- a/front/avatar.go +++ b/front/avatar.go @@ -78,9 +78,13 @@ func (h *Handler) uploadAvatar(w text.Writer, r *Request, args ...string) { now := time.Now() - if (r.User.Updated != nil && now.Sub(r.User.Updated.Time) < h.Config.MinActorEditInterval) || (r.User.Updated == nil && now.Sub(r.User.Published.Time) < h.Config.MinActorEditInterval) { - r.Log.Warn("Throttled request to set avatar") - w.Status(40, "Please try again later") + can := r.User.Published.Time.Add(h.Config.MinActorEditInterval) + if r.User.Updated != nil { + can = r.User.Updated.Time.Add(h.Config.MinActorEditInterval) + } + if now.Before(can) { + r.Log.Warn("Throttled request to set avatar", "can", can) + w.Statusf(40, "Please wait for %s", time.Until(can).Truncate(time.Second).String()) return } diff --git a/front/bio.go b/front/bio.go index 4aef6019..7fb793c8 100644 --- a/front/bio.go +++ b/front/bio.go @@ -33,9 +33,13 @@ func (h *Handler) doBio(w text.Writer, r *Request, readInput func(text.Writer, * now := time.Now() - if (r.User.Updated != nil && now.Sub(r.User.Updated.Time) < h.Config.MinActorEditInterval) || (r.User.Updated == nil && now.Sub(r.User.Published.Time) < h.Config.MinActorEditInterval) { - r.Log.Warn("Throttled request to set summary") - w.Status(40, "Please try again later") + can := r.User.Published.Time.Add(h.Config.MinActorEditInterval) + if r.User.Updated != nil { + can = r.User.Updated.Time.Add(h.Config.MinActorEditInterval) + } + if now.Before(can) { + r.Log.Warn("Throttled request to set summary", "can", can) + w.Statusf(40, "Please wait for %s", time.Until(can).Truncate(time.Second).String()) return } diff --git a/front/move.go b/front/move.go index a51153b2..5922a409 100644 --- a/front/move.go +++ b/front/move.go @@ -38,9 +38,13 @@ func (h *Handler) move(w text.Writer, r *Request, args ...string) { now := time.Now() - if (r.User.Updated != nil && now.Sub(r.User.Updated.Time) < h.Config.MinActorEditInterval) || (r.User.Updated == nil && now.Sub(r.User.Published.Time) < h.Config.MinActorEditInterval) { - r.Log.Warn("Throttled request to move account") - w.Status(40, "Please try again later") + can := r.User.Published.Time.Add(h.Config.MinActorEditInterval) + if r.User.Updated != nil { + can = r.User.Updated.Time.Add(h.Config.MinActorEditInterval) + } + if now.Before(can) { + r.Log.Warn("Throttled request to move account", "can", can) + w.Statusf(40, "Please wait for %s", time.Until(can).Truncate(time.Second).String()) return } diff --git a/front/name.go b/front/name.go index 296d7563..61ca39cc 100644 --- a/front/name.go +++ b/front/name.go @@ -34,9 +34,13 @@ func (h *Handler) name(w text.Writer, r *Request, args ...string) { now := time.Now() - if (r.User.Updated != nil && now.Sub(r.User.Updated.Time) < h.Config.MinActorEditInterval) || (r.User.Updated == nil && now.Sub(r.User.Published.Time) < h.Config.MinActorEditInterval) { - r.Log.Warn("Throttled request to set name") - w.Status(40, "Please try again later") + can := r.User.Published.Time.Add(h.Config.MinActorEditInterval) + if r.User.Updated != nil { + can = r.User.Updated.Time.Add(h.Config.MinActorEditInterval) + } + if now.Before(can) { + r.Log.Warn("Throttled request to set name", "can", can) + w.Statusf(40, "Please wait for %s", time.Until(can).Truncate(time.Second).String()) return }