Skip to content

Commit

Permalink
be more user-friendly when profile change is throttled
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Oct 18, 2024
1 parent 60b0acb commit b7899cf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
10 changes: 7 additions & 3 deletions front/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 7 additions & 3 deletions front/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 7 additions & 3 deletions front/bio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 7 additions & 3 deletions front/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 7 additions & 3 deletions front/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit b7899cf

Please sign in to comment.