add a ratelimit to media uploads

master
Aevann 2023-01-25 17:13:24 +02:00
parent 2a0e288e12
commit f8822ac14d
2 changed files with 14 additions and 1 deletions

View File

@ -20,10 +20,19 @@ from files.helpers.settings import get_setting
from .config.const import *
def media_ratelimit(v):
t = time.time() - 86400
count = g.db.query(Media).filter(Media.user_id == v.id, Media.created_utc > t).count()
if count > 50: abort(500)
def process_files(files, v):
body = ''
if g.is_tor or not files.get("file"): return body
files = files.getlist('file')[:4]
if files:
media_ratelimit(v)
for file in files:
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','') + '.webp'

View File

@ -153,6 +153,10 @@ def comment(v:User):
if request.files.get("file") and not g.is_tor:
files = request.files.getlist('file')[:4]
if files:
media_ratelimit(v)
for file in files:
if file.content_type.startswith('image/'):
oldname = f'/images/{time.time()}'.replace('.','') + '.webp'