forked from MarseyWorld/MarseyWorld
Merge branch 'frost' of github.com:Aevann1/rDrama into frost
commit
c6fe563dfc
|
@ -1,4 +1,4 @@
|
|||
from os import environ, listdir
|
||||
from os import environ
|
||||
import re
|
||||
from copy import deepcopy
|
||||
from json import loads
|
||||
|
|
|
@ -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
|
|
@ -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 *
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"):
|
||||
|
|
|
@ -11,6 +11,7 @@ gevent
|
|||
gevent-websocket
|
||||
greenlet
|
||||
gunicorn
|
||||
imagehash
|
||||
lxml
|
||||
mistletoe
|
||||
matplotlib
|
||||
|
|
Loading…
Reference in New Issue