vid refactor
parent
fca3249706
commit
969d1898b5
|
@ -10,7 +10,7 @@ COPY requirements.txt /etc/requirements.txt
|
||||||
|
|
||||||
RUN pip3 install -r /etc/requirements.txt
|
RUN pip3 install -r /etc/requirements.txt
|
||||||
|
|
||||||
RUN mkdir /images && mkdir /songs
|
RUN mkdir /images && mkdir /songs && mkdir /videos
|
||||||
|
|
||||||
EXPOSE 80/tcp
|
EXPOSE 80/tcp
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ from sqlalchemy.orm import deferred, aliased
|
||||||
from secrets import token_hex
|
from secrets import token_hex
|
||||||
import pyotp
|
import pyotp
|
||||||
from files.helpers.discord import remove_user
|
from files.helpers.discord import remove_user
|
||||||
from files.helpers.images import *
|
from files.helpers.media import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from .alts import Alt
|
from .alts import Alt
|
||||||
from .saves import *
|
from .saves import *
|
||||||
|
|
|
@ -4,6 +4,27 @@ from webptools import gifwebp
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
from flask import abort
|
from flask import abort
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
from .const import *
|
||||||
|
|
||||||
|
def process_video(file):
|
||||||
|
name = f'/videos/{time.time()}'.replace('.','')
|
||||||
|
file.save(name)
|
||||||
|
os.system(f'ffmpeg -y -loglevel warning -i {name} -map_metadata -1 {name}.mp4')
|
||||||
|
os.remove(name)
|
||||||
|
|
||||||
|
size = os.stat(f'{name}.mp4').st_size
|
||||||
|
|
||||||
|
with open(f"{name}.mp4", 'rb') as f:
|
||||||
|
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json()
|
||||||
|
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
||||||
|
try: url = req['files'][0]['url']
|
||||||
|
except: return {"error": req['description']}
|
||||||
|
return url
|
||||||
|
|
||||||
|
if SITE_NAME != 'rDrama' or size > 8 * 1024 * 1024: os.remove(f"{name}.mp4")
|
||||||
|
|
||||||
|
|
||||||
def process_image(patron, filename=None, resize=0):
|
def process_image(patron, filename=None, resize=0):
|
||||||
size = os.stat(filename).st_size
|
size = os.stat(filename).st_size
|
|
@ -8,7 +8,7 @@ from files.helpers.alerts import *
|
||||||
from files.helpers.sanitize import *
|
from files.helpers.sanitize import *
|
||||||
from files.helpers.security import *
|
from files.helpers.security import *
|
||||||
from files.helpers.get import *
|
from files.helpers.get import *
|
||||||
from files.helpers.images import *
|
from files.helpers.media import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.classes import *
|
from files.classes import *
|
||||||
from flask import *
|
from flask import *
|
||||||
|
|
|
@ -27,7 +27,6 @@ def chat( v):
|
||||||
|
|
||||||
|
|
||||||
@app.get('/chat.js')
|
@app.get('/chat.js')
|
||||||
@limiter.exempt
|
|
||||||
def chatjs():
|
def chatjs():
|
||||||
resp = make_response(send_from_directory('assets', 'js/chat.js'))
|
resp = make_response(send_from_directory('assets', 'js/chat.js'))
|
||||||
return resp
|
return resp
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from files.helpers.wrappers import *
|
from files.helpers.wrappers import *
|
||||||
from files.helpers.alerts import *
|
from files.helpers.alerts import *
|
||||||
from files.helpers.images import *
|
from files.helpers.media import *
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.helpers.slots import *
|
from files.helpers.slots import *
|
||||||
from files.helpers.blackjack import *
|
from files.helpers.blackjack import *
|
||||||
|
@ -307,17 +307,9 @@ def api_comment(v):
|
||||||
return {"error": str(e)}, 400
|
return {"error": str(e)}, 400
|
||||||
body += f"\n\n![]({image})"
|
body += f"\n\n![]({image})"
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: body += f"\n\n{value}"
|
||||||
else:
|
else: return value
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
body += f"\n\n{url}"
|
|
||||||
else: return {"error": "Image/Video files only"}, 400
|
else: return {"error": "Image/Video files only"}, 400
|
||||||
|
|
||||||
body = body.strip()
|
body = body.strip()
|
||||||
|
@ -773,17 +765,9 @@ def edit_comment(cid, v):
|
||||||
url = process_image(v.patron, name)
|
url = process_image(v.patron, name)
|
||||||
body += f"\n\n![]({url})"
|
body += f"\n\n![]({url})"
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: body += f"\n\n{value}"
|
||||||
else:
|
else: return value
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
body += f"\n\n{url}"
|
|
||||||
else: return {"error": "Image/Video files only"}, 400
|
else: return {"error": "Image/Video files only"}, 400
|
||||||
|
|
||||||
body = body.strip()
|
body = body.strip()
|
||||||
|
|
|
@ -464,17 +464,9 @@ def edit_post(pid, v):
|
||||||
url = process_image(v.patron, name)
|
url = process_image(v.patron, name)
|
||||||
body += f"\n\n![]({url})"
|
body += f"\n\n![]({url})"
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: body += f"\n\n{value}"
|
||||||
else:
|
else: return value
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
body += f"\n\n{url}"
|
|
||||||
else: return {"error": "Image/Video files only"}, 400
|
else: return {"error": "Image/Video files only"}, 400
|
||||||
|
|
||||||
body = body.strip()
|
body = body.strip()
|
||||||
|
@ -1083,17 +1075,9 @@ def submit_post(v, sub=None):
|
||||||
file.save(name)
|
file.save(name)
|
||||||
body += f"\n\n![]({process_image(v.patron, name)})"
|
body += f"\n\n![]({process_image(v.patron, name)})"
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: body += f"\n\n{value}"
|
||||||
else:
|
else: return error(value['error'])
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
body += f"\n\n{url}"
|
|
||||||
else:
|
else:
|
||||||
return error("Image/Video files only.")
|
return error("Image/Video files only.")
|
||||||
|
|
||||||
|
@ -1194,17 +1178,9 @@ def submit_post(v, sub=None):
|
||||||
copyfile(name, name2)
|
copyfile(name, name2)
|
||||||
post.thumburl = process_image(v.patron, name2, resize=100)
|
post.thumburl = process_image(v.patron, name2, resize=100)
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: post.url = value
|
||||||
else:
|
else: return error(value['error'])
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
post.url = url
|
|
||||||
else:
|
else:
|
||||||
return error("Image/Video files only.")
|
return error("Image/Video files only.")
|
||||||
|
|
||||||
|
|
|
@ -217,17 +217,9 @@ def settings_profile_post(v):
|
||||||
url = process_image(v.patron, name)
|
url = process_image(v.patron, name)
|
||||||
bio += f"\n\n![]({url})"
|
bio += f"\n\n![]({url})"
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: bio += f"\n\n{value}"
|
||||||
else:
|
else: return value
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
bio += f"\n\n{url}"
|
|
||||||
else:
|
else:
|
||||||
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Image/Video files only"}, 400
|
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Image/Video files only"}, 400
|
||||||
return render_template("settings_profile.html", v=v, error="Image/Video files only."), 400
|
return render_template("settings_profile.html", v=v, error="Image/Video files only."), 400
|
||||||
|
|
|
@ -373,9 +373,9 @@ def log_item(id, v):
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api")
|
@app.get("/api")
|
||||||
@auth_required
|
@limiter.limit("1/day")
|
||||||
def api(v):
|
def api():
|
||||||
return render_template("api.html", v=v)
|
return render_template("api.html")
|
||||||
|
|
||||||
@app.get("/contact")
|
@app.get("/contact")
|
||||||
@app.get("/press")
|
@app.get("/press")
|
||||||
|
@ -404,17 +404,9 @@ def submit_contact(v):
|
||||||
url = process_image(v.patron, name)
|
url = process_image(v.patron, name)
|
||||||
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
|
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: body_html += f"<p>{value}</p>"
|
||||||
else:
|
else: return value
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.Timeout: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
body_html += f"<p>{url}</p>"
|
|
||||||
else: return {"error": "Image/Video files only"}, 400
|
else: return {"error": "Image/Video files only"}, 400
|
||||||
|
|
||||||
|
|
||||||
|
@ -449,7 +441,6 @@ def archives(path):
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@app.get('/e/<emoji>')
|
@app.get('/e/<emoji>')
|
||||||
@limiter.exempt
|
|
||||||
def emoji(emoji):
|
def emoji(emoji):
|
||||||
if not emoji.endswith('.webp'): abort(404)
|
if not emoji.endswith('.webp'): abort(404)
|
||||||
resp = make_response(send_from_directory('assets/images/emojis', emoji))
|
resp = make_response(send_from_directory('assets/images/emojis', emoji))
|
||||||
|
@ -461,7 +452,6 @@ def emoji(emoji):
|
||||||
|
|
||||||
@app.get('/assets/<path:path>')
|
@app.get('/assets/<path:path>')
|
||||||
@app.get('/static/assets/<path:path>')
|
@app.get('/static/assets/<path:path>')
|
||||||
@limiter.exempt
|
|
||||||
def static_service(path):
|
def static_service(path):
|
||||||
resp = make_response(send_from_directory('assets', path))
|
resp = make_response(send_from_directory('assets', path))
|
||||||
if request.path.endswith('.webp') or request.path.endswith('.gif') or request.path.endswith('.ttf') or request.path.endswith('.woff2'):
|
if request.path.endswith('.webp') or request.path.endswith('.gif') or request.path.endswith('.ttf') or request.path.endswith('.woff2'):
|
||||||
|
@ -477,14 +467,21 @@ def static_service(path):
|
||||||
@app.get('/images/<path>')
|
@app.get('/images/<path>')
|
||||||
@app.get('/hostedimages/<path>')
|
@app.get('/hostedimages/<path>')
|
||||||
@app.get("/static/images/<path>")
|
@app.get("/static/images/<path>")
|
||||||
@limiter.exempt
|
|
||||||
def images(path):
|
def images(path):
|
||||||
resp = make_response(send_from_directory('/images', path.replace('.WEBP','.webp')))
|
resp = make_response(send_from_directory('/images', path.replace('.WEBP','.webp')))
|
||||||
resp.headers.remove("Cache-Control")
|
resp.headers.remove("Cache-Control")
|
||||||
resp.headers.add("Cache-Control", "public, max-age=3153600")
|
resp.headers.add("Cache-Control", "public, max-age=3153600")
|
||||||
if request.path.endswith('.webp'):
|
resp.headers.remove("Content-Type")
|
||||||
resp.headers.remove("Content-Type")
|
resp.headers.add("Content-Type" ,"image/webp")
|
||||||
resp.headers.add("Content-Type", "image/webp")
|
return resp
|
||||||
|
|
||||||
|
@app.get('/videos/<path>')
|
||||||
|
def videos(path):
|
||||||
|
resp = make_response(send_from_directory('/videos', path.replace('.MP4','.mp4')))
|
||||||
|
resp.headers.remove("Cache-Control")
|
||||||
|
resp.headers.add("Cache-Control", "public, max-age=3153600")
|
||||||
|
resp.headers.remove("Content-Type")
|
||||||
|
resp.headers.add("Content-Type", "video/mp4")
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
@app.get("/robots.txt")
|
@app.get("/robots.txt")
|
||||||
|
|
|
@ -701,17 +701,9 @@ def messagereply(v):
|
||||||
url = process_image(v.patron, name)
|
url = process_image(v.patron, name)
|
||||||
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
|
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="img" src="{url}" loading="lazy">'
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
if file.content_type == 'video/webm':
|
value = process_video(file)
|
||||||
file.save("video.mp4")
|
if type(value) is str: body_html += f"<p>{value}</p>"
|
||||||
else:
|
else: return value
|
||||||
file.save("unsanitized.mp4")
|
|
||||||
os.system(f'ffmpeg -y -loglevel warning -i unsanitized.mp4 -map_metadata -1 -c:v copy -c:a copy video.mp4')
|
|
||||||
with open("video.mp4", 'rb') as f:
|
|
||||||
try: req = requests.request("POST", "https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=5).json()
|
|
||||||
except requests.exceptions.ConnectionError: return {"error": "Video upload timed out, please try again!"}
|
|
||||||
try: url = req['files'][0]['url']
|
|
||||||
except: return {"error": req['description']}, 400
|
|
||||||
body_html += f"<p>{url}</p>"
|
|
||||||
else: return {"error": "Image/Video files only"}, 400
|
else: return {"error": "Image/Video files only"}, 400
|
||||||
|
|
||||||
|
|
||||||
|
@ -1149,7 +1141,6 @@ def remove_follow(username, v):
|
||||||
@app.get("/logged_out/pp/<id>")
|
@app.get("/logged_out/pp/<id>")
|
||||||
@app.get("/logged_out/uid/<id>/pic")
|
@app.get("/logged_out/uid/<id>/pic")
|
||||||
@app.get("/logged_out/uid/<id>/pic/profile")
|
@app.get("/logged_out/uid/<id>/pic/profile")
|
||||||
@limiter.exempt
|
|
||||||
@auth_desired
|
@auth_desired
|
||||||
def user_profile_uid(v, id):
|
def user_profile_uid(v, id):
|
||||||
if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}")
|
if not v and not request.path.startswith('/logged_out'): return redirect(f"/logged_out{request.full_path}")
|
||||||
|
@ -1164,7 +1155,6 @@ def user_profile_uid(v, id):
|
||||||
return redirect(x.profile_url)
|
return redirect(x.profile_url)
|
||||||
|
|
||||||
@app.get("/@<username>/pic")
|
@app.get("/@<username>/pic")
|
||||||
@limiter.exempt
|
|
||||||
@auth_required
|
@auth_required
|
||||||
def user_profile_name(v, username):
|
def user_profile_name(v, username):
|
||||||
x = get_user(username)
|
x = get_user(username)
|
||||||
|
|
|
@ -11,6 +11,7 @@ service postgresql restart
|
||||||
pip3 install -r requirements.txt
|
pip3 install -r requirements.txt
|
||||||
mkdir /songs
|
mkdir /songs
|
||||||
mkdir /images
|
mkdir /images
|
||||||
|
mkdir /videos
|
||||||
snap install opera-proxy
|
snap install opera-proxy
|
||||||
ufw allow ssh
|
ufw allow ssh
|
||||||
ufw allow from 173.245.48.0/20
|
ufw allow from 173.245.48.0/20
|
||||||
|
|
Loading…
Reference in New Issue