mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-22 07:51:00 +00:00
Improve banned forgiveness logic
This commit is contained in:
parent
cda2d3ed96
commit
3a7527c418
1 changed files with 12 additions and 3 deletions
15
app/flood.py
15
app/flood.py
|
@ -7,10 +7,19 @@ active = False
|
|||
threshold = -1
|
||||
|
||||
|
||||
def clear_banned():
|
||||
def forgive_banned():
|
||||
global banned
|
||||
banned = {}
|
||||
|
||||
clear_list = []
|
||||
|
||||
for ip in banned:
|
||||
if banned[ip] <= 0:
|
||||
clear_list.append(ip)
|
||||
else:
|
||||
banned[ip] -= 1
|
||||
|
||||
for ip in clear_list:
|
||||
del banned[ip]
|
||||
|
||||
def setup(violations_threshold=100):
|
||||
global active
|
||||
|
@ -20,7 +29,7 @@ def setup(violations_threshold=100):
|
|||
threshold = violations_threshold
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
scheduler.add_job(func=clear_banned, trigger="interval", weeks=4)
|
||||
scheduler.add_job(func=forgive_banned, trigger="interval", minutes=5)
|
||||
scheduler.start()
|
||||
|
||||
# Shut down the scheduler when exiting the app
|
||||
|
|
Loading…
Reference in a new issue