retarded lives matter

This commit is contained in:
Aevann1 2022-01-21 21:55:42 +02:00
parent 1baa70ad62
commit 6b9ff48dda
9 changed files with 41 additions and 85 deletions

View file

@ -798,6 +798,3 @@ NOTIFIED_USERS = {
'dong': DONGER_ID, 'dong': DONGER_ID,
'kippy': KIPPY_ID, 'kippy': KIPPY_ID,
} }
num_banners = len(listdir('files/assets/images/Drama/banners')) + 1
num_sidebar = len(listdir('files/assets/images/Drama/sidebar')) + 1

View file

@ -1,12 +1,14 @@
from PIL import Image as IImage, ImageSequence from PIL import Image as IImage, ImageSequence
from webptools import gifwebp from webptools import gifwebp
import time
def process_image(filename=None, resize=False): def process_image(file=None, filename=None, resize=False):
i = IImage.open(filename) i = IImage.open(file)
if not filename: filename = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
if resize: if resize:
size = 100, 100 size = resize, resize
frames = ImageSequence.Iterator(i) frames = ImageSequence.Iterator(i)
def thumbnails(frames): def thumbnails(frames):
@ -21,7 +23,9 @@ def process_image(filename=None, resize=False):
om.info = i.info om.info = i.info
om.save(filename, format="WEBP", save_all=True, append_images=list(frames), loop=0, method=6, allow_mixed=True) om.save(filename, format="WEBP", save_all=True, append_images=list(frames), loop=0, method=6, allow_mixed=True)
elif i.format.lower() != "webp": elif i.format.lower() != "webp":
if i.format.lower() == "gif": gifwebp(input_image=filename, output_image=filename, option="-mixed -metadata none -f 100 -mt -m 6") if i.format.lower() == "gif":
i.save(filename)
gifwebp(input_image=filename, output_image=filename, option="-mixed -metadata none -f 100 -mt -m 6")
else: i.save(filename, format="WEBP", method=6) else: i.save(filename, format="WEBP", method=6)
return f'/static{filename}' return f'/static{filename}'

View file

@ -24,4 +24,4 @@ def post_embed(id, v):
@app.context_processor @app.context_processor
def inject_constants(): def inject_constants():
return {"num_banners":num_banners, "num_sidebar":num_sidebar, "environ":environ, "SITE_NAME":SITE_NAME, "AUTOJANNY_ID":AUTOJANNY_ID, "NOTIFICATIONS_ID":NOTIFICATIONS_ID, "PUSHER_ID":PUSHER_ID, "CC":CC, "CC_TITLE":CC_TITLE} return {"environ":environ, "SITE_NAME":SITE_NAME, "AUTOJANNY_ID":AUTOJANNY_ID, "NOTIFICATIONS_ID":NOTIFICATIONS_ID, "PUSHER_ID":PUSHER_ID, "CC":CC, "CC_TITLE":CC_TITLE, "listdir":listdir}

View file

@ -174,10 +174,7 @@ def api_comment(v):
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"] file=request.files["file"]
if file.content_type.startswith('image/'): if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' body += f"\n\n![]({process_image(file.stream)})"
file.save(name)
url = process_image(name)
body += f"\n\n![]({url})"
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
file.save("video.mp4") file.save("video.mp4")
with open("video.mp4", 'rb') as f: with open("video.mp4", 'rb') as f:
@ -640,10 +637,15 @@ def edit_comment(cid, v):
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"] file=request.files["file"]
if file.content_type.startswith('image/'): if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' body += f"\n\n![]({process_image(file.stream)})"
file.save(name) if v.admin_level == 3:
url = process_image(name) if parent_post.id == 48:
body += f"\n\n![]({url})" filename = 'files/assets/images/Drama/sidebar/' + str(len(listdir('files/assets/images/Drama/sidebar'))+1) + '.webp'
process_image(file.stream, filename, 400)
elif parent_post.id == 49:
filename = 'files/assets/images/Drama/sidebar/' + str(len(listdir('files/assets/images/Drama/banners'))+1) + '.webp'
process_image(file.stream, filename, 400)
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
file.save("video.mp4") file.save("video.mp4")
with open("video.mp4", 'rb') as f: with open("video.mp4", 'rb') as f:

View file

@ -16,8 +16,6 @@ from .front import frontlist, changeloglist
from urllib.parse import ParseResult, urlunparse, urlparse, quote, unquote from urllib.parse import ParseResult, urlunparse, urlparse, quote, unquote
from os import path from os import path
import requests import requests
from shutil import copyfile
from psutil import cpu_percent
IMGUR_KEY = environ.get("IMGUR_KEY").strip() IMGUR_KEY = environ.get("IMGUR_KEY").strip()
@ -421,10 +419,7 @@ def edit_post(pid, v):
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"] file=request.files["file"]
if file.content_type.startswith('image/'): if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' body += f"\n\n![]({process_image(file.stream)})"
file.save(name)
url = process_image(name)
body += f"\n\n![]({url})"
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
file.save("video.mp4") file.save("video.mp4")
with open("video.mp4", 'rb') as f: with open("video.mp4", 'rb') as f:
@ -530,29 +525,6 @@ def thumbnail_thread(pid):
db = db_session() db = db_session()
# cpu = cpu_percent()
# time.sleep(0.1)
# cpu = cpu_percent()
# if cpu > 70:
# print(f'Cpu usage at {cpu}%, Enabling under attack mode!', flush=True)
# with open('under_attack', 'r') as f: content = f.read()
# with open('under_attack', 'w') as f:
# if content == "no":
# f.write("yes")
# ma = ModAction(
# kind="enable_under_attack",
# user_id=AUTOJANNY_ID,
# )
# db.add(ma)
# db.commit()
# data='{"value":"under_attack"}'
# response = requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data=data)
# print(response.text, flush=True)
def expand_url(post_url, fragment_url): def expand_url(post_url, fragment_url):
if fragment_url.startswith("https://"): if fragment_url.startswith("https://"):
@ -646,8 +618,9 @@ def thumbnail_thread(pid):
if image_req.headers.get("Content-Type","").startswith("image/svg"): if image_req.headers.get("Content-Type","").startswith("image/svg"):
continue continue
image = PILimage.open(BytesIO(image_req.content)) image = BytesIO(image_req.content)
if image.width < 30 or image.height < 30: image2 = PILimage.open(image)
if image2.width < 30 or image2.height < 30:
continue continue
break break
@ -660,7 +633,7 @@ def thumbnail_thread(pid):
elif x.headers.get("Content-Type","").startswith("image/"): elif x.headers.get("Content-Type","").startswith("image/"):
image_req=x image_req=x
image = PILimage.open(BytesIO(x.content)) image = BytesIO(x.content)
else: else:
db.close() db.close()
@ -668,11 +641,7 @@ def thumbnail_thread(pid):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
with open(name, "wb") as file: post.thumburl = process_image(image, resize=100)
for chunk in image_req.iter_content(1024):
file.write(chunk)
post.thumburl = process_image(name, resize=True)
db.add(post) db.add(post)
db.commit() db.commit()
db.close() db.close()
@ -879,9 +848,7 @@ def submit_post(v):
if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1": if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file2"] file=request.files["file2"]
if file.content_type.startswith('image/'): if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' body += f"\n\n![]({process_image(file.stream)})"
file.save(name)
body += f"\n\n![]({process_image(name)})"
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
file.save("video.mp4") file.save("video.mp4")
with open("video.mp4", 'rb') as f: with open("video.mp4", 'rb') as f:
@ -968,13 +935,8 @@ def submit_post(v):
file = request.files['file'] file = request.files['file']
if file.content_type.startswith('image/'): if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' new_post.url = process_image(file.stream)
file.save(name) new_post.thumburl = process_image(file.stream, resize=100)
new_post.url = process_image(name)
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
new_post.thumburl = process_image(name2, resize=True)
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
file.save("video.mp4") file.save("video.mp4")
with open("video.mp4", 'rb') as f: with open("video.mp4", 'rb') as f:

View file

@ -11,7 +11,6 @@ from .front import frontlist
import os import os
from files.helpers.sanitize import filter_emojis_only from files.helpers.sanitize import filter_emojis_only
from files.helpers.discord import add_role from files.helpers.discord import add_role
from shutil import copyfile
import requests import requests
valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$") valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$")
@ -256,10 +255,7 @@ def settings_profile_post(v):
if request.files.get('file'): if request.files.get('file'):
file = request.files['file'] file = request.files['file']
if file.content_type.startswith('image/'): if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' bio += f"\n\n![]({process_image(file.stream)})"
file.save(name)
url = process_image(name)
bio += f"\n\n![]({url})"
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
file.save("video.mp4") file.save("video.mp4")
with open("video.mp4", 'rb') as f: with open("video.mp4", 'rb') as f:
@ -625,15 +621,11 @@ def settings_images_profile(v):
file = request.files["profile"] file = request.files["profile"]
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' highres = process_image(file.stream)
file.save(name)
highres = process_image(name)
if not highres: abort(400) if not highres: abort(400)
name2 = name.replace('.webp', 'r.webp') imageurl = process_image(file.stream, resize=100)
copyfile(name, name2)
imageurl = process_image(name2, resize=True)
if not imageurl: abort(400) if not imageurl: abort(400)
@ -660,9 +652,7 @@ def settings_images_banner(v):
file = request.files["banner"] file = request.files["banner"]
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' bannerurl = process_image(file.stream)
file.save(name)
bannerurl = process_image(name)
if bannerurl: if bannerurl:
if v.bannerurl and '/images/' in v.bannerurl : os.remove('/images/' + v.bannerurl.split('/images/')[1]) if v.bannerurl and '/images/' in v.bannerurl : os.remove('/images/' + v.bannerurl.split('/images/')[1])

View file

@ -271,10 +271,7 @@ def submit_contact(v):
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"] file=request.files["file"]
if file.content_type.startswith('image/'): if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="in-comment-image" src="{process_image(file.stream)}" loading="lazy">'
file.save(name)
url = process_image(name)
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="in-comment-image" src="{url}" loading="lazy">'
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
file.save("video.mp4") file.save("video.mp4")
with open("video.mp4", 'rb') as f: with open("video.mp4", 'rb') as f:

View file

@ -217,8 +217,11 @@
{% if v %} {% if v %}
{% if SITE_NAME == 'Drama' %} {% if SITE_NAME == 'Drama' %}
{% set path = "assets/images/" + SITE_NAME + "/banners" %}
{% set image = "/static/" + path + "/" + listdir('files/' + path)|random() %}
<a href="https://secure.transequality.org/site/Donation2?df_id=1480"> <a href="https://secure.transequality.org/site/Donation2?df_id=1480">
<img alt="site banner" src="/static/assets/images/{{SITE_NAME}}/banners/{{range(1,num_banners)|random()}}.webp?a=18" width="100%"> <img alt="site banner" src="{{image}}" width="100%">
</a> </a>
{% else %} {% else %}
<a href="/"> <a href="/">

View file

@ -1,6 +1,7 @@
<div class="col sidebar text-left d-none d-lg-block pt-3 bg-white" style="max-width:300px"> <div class="col sidebar text-left d-none d-lg-block pt-3 bg-white" style="max-width:300px">
{% set image = "/static/assets/images/" + SITE_NAME + "/sidebar/" + range(1,num_sidebar)|random()|string + ".webp?a=16" %} {% set path = "assets/images/" + SITE_NAME + "/sidebar" %}
{% set image = "/static/" + path + "/" + listdir('files/' + path)|random() %}
<a role="button" data-bs-toggle="modal" data-bs-target="#expandImageModal" data-bs-url="{{image}}" onclick="expandDesktopImage('{{image}}')"> <a role="button" data-bs-toggle="modal" data-bs-target="#expandImageModal" data-bs-url="{{image}}" onclick="expandDesktopImage('{{image}}')">
<img loading="lazy" src="{{image}}" width=100%> <img loading="lazy" src="{{image}}" width=100%>