retarded lives matter

remotes/1693045480750635534/spooky-22
Aevann1 2022-01-21 21:55:42 +02:00
parent 54b389213f
commit 4106c26f06
9 changed files with 41 additions and 85 deletions

View File

@ -797,7 +797,4 @@ NOTIFIED_USERS = {
'landlet': LLM_ID,
'dong': DONGER_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 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:
size = 100, 100
size = resize, resize
frames = ImageSequence.Iterator(i)
def thumbnails(frames):
@ -21,7 +23,9 @@ def process_image(filename=None, resize=False):
om.info = i.info
om.save(filename, format="WEBP", save_all=True, append_images=list(frames), loop=0, method=6, allow_mixed=True)
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)
return f'/static{filename}'

View File

@ -24,4 +24,4 @@ def post_embed(id, v):
@app.context_processor
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":
file=request.files["file"]
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = process_image(name)
body += f"\n\n![]({url})"
body += f"\n\n![]({process_image(file.stream)})"
elif file.content_type.startswith('video/'):
file.save("video.mp4")
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":
file=request.files["file"]
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = process_image(name)
body += f"\n\n![]({url})"
body += f"\n\n![]({process_image(file.stream)})"
if v.admin_level == 3:
if parent_post.id == 48:
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/'):
file.save("video.mp4")
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 os import path
import requests
from shutil import copyfile
from psutil import cpu_percent
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":
file=request.files["file"]
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = process_image(name)
body += f"\n\n![]({url})"
body += f"\n\n![]({process_image(file.stream)})"
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
@ -530,29 +525,6 @@ def thumbnail_thread(pid):
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):
if fragment_url.startswith("https://"):
@ -646,10 +618,11 @@ def thumbnail_thread(pid):
if image_req.headers.get("Content-Type","").startswith("image/svg"):
continue
image = PILimage.open(BytesIO(image_req.content))
if image.width < 30 or image.height < 30:
image = BytesIO(image_req.content)
image2 = PILimage.open(image)
if image2.width < 30 or image2.height < 30:
continue
break
else:
@ -660,7 +633,7 @@ def thumbnail_thread(pid):
elif x.headers.get("Content-Type","").startswith("image/"):
image_req=x
image = PILimage.open(BytesIO(x.content))
image = BytesIO(x.content)
else:
db.close()
@ -668,11 +641,7 @@ def thumbnail_thread(pid):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
with open(name, "wb") as file:
for chunk in image_req.iter_content(1024):
file.write(chunk)
post.thumburl = process_image(name, resize=True)
post.thumburl = process_image(image, resize=100)
db.add(post)
db.commit()
db.close()
@ -879,9 +848,7 @@ def submit_post(v):
if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file2"]
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
body += f"\n\n![]({process_image(name)})"
body += f"\n\n![]({process_image(file.stream)})"
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
@ -968,13 +935,8 @@ def submit_post(v):
file = request.files['file']
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
new_post.url = process_image(name)
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
new_post.thumburl = process_image(name2, resize=True)
new_post.url = process_image(file.stream)
new_post.thumburl = process_image(file.stream, resize=100)
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:

View File

@ -11,7 +11,6 @@ from .front import frontlist
import os
from files.helpers.sanitize import filter_emojis_only
from files.helpers.discord import add_role
from shutil import copyfile
import requests
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'):
file = request.files['file']
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = process_image(name)
bio += f"\n\n![]({url})"
bio += f"\n\n![]({process_image(file.stream)})"
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
@ -625,15 +621,11 @@ def settings_images_profile(v):
file = request.files["profile"]
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
highres = process_image(name)
highres = process_image(file.stream)
if not highres: abort(400)
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
imageurl = process_image(name2, resize=True)
imageurl = process_image(file.stream, resize=100)
if not imageurl: abort(400)
@ -660,9 +652,7 @@ def settings_images_banner(v):
file = request.files["banner"]
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
bannerurl = process_image(name)
bannerurl = process_image(file.stream)
if bannerurl:
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":
file=request.files["file"]
if file.content_type.startswith('image/'):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
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">'
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">'
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:

View File

@ -217,8 +217,11 @@
{% if v %}
{% 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">
<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>
{% else %}
<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">
{% 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}}')">
<img loading="lazy" src="{{image}}" width=100%>