diff --git a/files/helpers/media.py b/files/helpers/media.py index 4ca2c3356..5a5af305f 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -39,11 +39,10 @@ def process_audio(file): file.save(name) - if os.stat(name).st_size > 8 * 1024 * 1024: - with open(name, 'rb') as f: - os.remove(name) - req = requests.post("https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() - return req['files'][0]['url'] + size = os.stat(name).st_size + if size > 16 * 1024 * 1024 or not g.v.patron and size > 8 * 1024 * 1024: + os.remove(name) + abort(413) return f'{SITE_FULL}{name}' @@ -52,6 +51,11 @@ def process_video(file): old = f'/videos/{time.time()}'.replace('.','') file.save(old) + size = os.stat(old).st_size + if SITE_NAME != 'WPD' and (size > 32 * 1024 * 1024 or not g.v.patron and size > 64 * 1024 * 1024): + os.remove(old) + abort(414) + extension = file.filename.split('.')[-1].lower() if extension not in ['avi', 'mp4', 'webm', 'm4v', 'mov', 'mkv']: extension = 'mp4' @@ -59,11 +63,6 @@ def process_video(file): subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True) os.remove(old) - if os.stat(new).st_size > 8 * 1024 * 1024: - with open(new, 'rb') as f: - os.remove(new) - req = requests.post("https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() - return req['files'][0]['url'] return f'{SITE_FULL}{new}' @@ -71,7 +70,7 @@ def process_video(file): def process_image(filename=None, resize=0, trim=False): size = os.stat(filename).st_size - if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024: + if size > 16 * 1024 * 1024 or not g.v.patron and size > 8 * 1024 * 1024: os.remove(filename) abort(413) diff --git a/files/routes/errors.py b/files/routes/errors.py index 6012b7673..484b89871 100644 --- a/files/routes/errors.py +++ b/files/routes/errors.py @@ -59,6 +59,12 @@ def error_413(e): return {"error": "Max image/audio size is 8 MB (16 MB for paypigs)"}, 413 else: return render_template('errors/413.html', err=True), 413 +@app.errorhandler(414) +def error_414(e): + if request.headers.get("Authorization") or request.headers.get("xhr"): + return {"error": "Max video size is 32 MB (64 MB for paypigs)"}, 414 + else: return render_template('errors/414.html', err=True), 414 + @app.errorhandler(415) def error_415(e): if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Please upload only Image, Video, or Audio files!"}, 415 diff --git a/files/templates/errors/413.html b/files/templates/errors/413.html index 86f3b9806..3dae7f9b8 100644 --- a/files/templates/errors/413.html +++ b/files/templates/errors/413.html @@ -1,7 +1,7 @@ {% extends "default.html" %} {% block title %} -