Merge branch 'frost' of github.com:Aevann1/rDrama into frost

remotes/1693176582716663532/tmp_refs/heads/watchparty
Outrun Colors 2022-09-26 20:28:44 -05:00
commit c6fe563dfc
6 changed files with 41 additions and 8 deletions

View File

@ -1,4 +1,4 @@
from os import environ, listdir
from os import environ
import re
from copy import deepcopy
from json import loads
@ -1098,4 +1098,4 @@ forced_hats = {
"marsify": ("Marsified", "I can't pick my own Marseys, help!"),
"is_suspended": ("Behind Bars", "This user is banned and needs to do better!"),
"agendaposter": ("Egg_irl", "This user is getting in touch with xir identity!")
}
}

View File

@ -8,7 +8,7 @@ import requests
import time
from .const import *
import gevent
import imagehash
def process_files():
body = ''
@ -103,8 +103,36 @@ def process_image(filename=None, resize=0, trim=False):
i = ImageOps.exif_transpose(i)
i.save(filename, format="WEBP", method=6, quality=88)
if resize in (400,1200) and os.stat(filename).st_size > 1 * 1024 * 1024:
os.remove(filename)
abort(413)
if resize in (300,400,1200):
if os.stat(filename).st_size > 1 * 1024 * 1024:
os.remove(filename)
abort(413)
if resize == 1200:
path = f'files/assets/images/{SITE_NAME}/banners'
elif resize == 400:
path = f'files/assets/images/{SITE_NAME}/sidebar'
else:
path = f'files/assets/images/badges'
hashes = {}
for img in os.listdir(path):
if resize == 400 and img in ('256.webp','585.webp'): continue
img_path = f'{path}/{img}'
if img_path == filename: continue
img = Image.open(img_path)
i_hash = str(imagehash.phash(img))
if i_hash in hashes.keys():
print(hashes[i_hash], flush=True)
print(img_path, flush=True)
else: hashes[i_hash] = img_path
i = Image.open(filename)
i_hash = str(imagehash.phash(i))
if i_hash in hashes.keys():
os.remove(filename)
abort(417)
return filename

View File

@ -1,5 +1,5 @@
from shutil import move, copyfile
from os import listdir, rename, path
from os import rename, path
from files.__main__ import app, limiter
from files.helpers.const import *

View File

@ -222,7 +222,7 @@ def comment(v):
g.db.flush()
filename = f'files/assets/images/badges/{badge.id}.webp'
copyfile(oldname, filename)
process_image(filename, resize=400)
process_image(filename, resize=300)
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS,
data=f'{{"files": ["https://{SITE}/assets/images/badges/{badge.id}.webp"]}}', timeout=5)
except Exception as e:

View File

@ -64,6 +64,10 @@ 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
else: return render_template('errors/415.html', err=True), 415
@app.errorhandler(417)
def error_417(e):
return {"error": "Image already exists!"}, 417
@app.errorhandler(418)
def error_418(e):
if request.headers.get("Authorization") or request.headers.get("xhr"):

View File

@ -11,6 +11,7 @@ gevent
gevent-websocket
greenlet
gunicorn
imagehash
lxml
mistletoe
matplotlib