stop using lain.la

master
Aevann1 2022-10-06 06:31:08 +02:00
parent 3c261f19cd
commit 0c8ead2e7d
4 changed files with 39 additions and 14 deletions

View File

@ -39,11 +39,10 @@ def process_audio(file):
file.save(name) file.save(name)
if os.stat(name).st_size > 8 * 1024 * 1024: size = os.stat(name).st_size
with open(name, 'rb') as f: if size > 16 * 1024 * 1024 or not g.v.patron and size > 8 * 1024 * 1024:
os.remove(name) os.remove(name)
req = requests.post("https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() abort(413)
return req['files'][0]['url']
return f'{SITE_FULL}{name}' return f'{SITE_FULL}{name}'
@ -52,6 +51,11 @@ def process_video(file):
old = f'/videos/{time.time()}'.replace('.','') old = f'/videos/{time.time()}'.replace('.','')
file.save(old) 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() extension = file.filename.split('.')[-1].lower()
if extension not in ['avi', 'mp4', 'webm', 'm4v', 'mov', 'mkv']: if extension not in ['avi', 'mp4', 'webm', 'm4v', 'mov', 'mkv']:
extension = 'mp4' 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) subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True)
os.remove(old) 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}' return f'{SITE_FULL}{new}'
@ -71,7 +70,7 @@ def process_video(file):
def process_image(filename=None, resize=0, trim=False): def process_image(filename=None, resize=0, trim=False):
size = os.stat(filename).st_size 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) os.remove(filename)
abort(413) abort(413)

View File

@ -59,6 +59,12 @@ def error_413(e):
return {"error": "Max image/audio size is 8 MB (16 MB for paypigs)"}, 413 return {"error": "Max image/audio size is 8 MB (16 MB for paypigs)"}, 413
else: return render_template('errors/413.html', err=True), 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) @app.errorhandler(415)
def error_415(e): 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 if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Please upload only Image, Video, or Audio files!"}, 415

View File

@ -1,7 +1,7 @@
{% extends "default.html" %} {% extends "default.html" %}
{% block title %} {% block title %}
<title>Max file size is 8 MB (16 MB for paypigs)</title> <title>Max image/audio size is 8 MB (16 MB for paypigs)</title>
{% endblock %} {% endblock %}
{% block pagetype %}error-413{% endblock %} {% block pagetype %}error-413{% endblock %}
@ -12,9 +12,9 @@
<div class="text-center px-3 my-8"> <div class="text-center px-3 my-8">
<img alt=":#marseyretard:" loading="lazy" src="/e/marseychonker2.webp"> <img alt=":#marseyretard:" loading="lazy" src="/e/marseychonker2.webp">
<pre></pre> <pre></pre>
<h1 class="h5">Max file size is 8 MB (16 MB for paypigs)</h1> <h1 class="h5">Max image/audio size is 8 MB (16 MB for paypigs)</h1>
<div><a href="/" class="btn btn-primary">Go to frontpage</a></div> <div><a href="/" class="btn btn-primary">Go to frontpage</a></div>
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,20 @@
{% extends "default.html" %}
{% block title %}
<title>Max video size is 32 MB (64 MB for paypigs)</title>
{% endblock %}
{% block pagetype %}error-414{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-10 col-md-5">
<div class="text-center px-3 my-8">
<img alt=":#marseyretard:" loading="lazy" src="/e/marseychonker2.webp">
<pre></pre>
<h1 class="h5">Max video size is 32 MB (64 MB for paypigs)</h1>
<div><a href="/" class="btn btn-primary">Go to frontpage</a></div>
</div>
</div>
</div>
{% endblock %}