forked from MarseyWorld/MarseyWorld
fix 500 error
parent
dc8f230ae4
commit
eba4452d79
|
@ -3,7 +3,7 @@ from PIL.ImageSequence import Iterator
|
||||||
from webptools import gifwebp
|
from webptools import gifwebp
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
from flask import abort
|
from flask import abort, g
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
from .const import *
|
from .const import *
|
||||||
|
@ -17,7 +17,7 @@ def process_files():
|
||||||
if file.content_type.startswith('image/'):
|
if file.content_type.startswith('image/'):
|
||||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
url = process_image(v.patron, name)
|
url = process_image(name)
|
||||||
body += f"\n\n![]({url})"
|
body += f"\n\n![]({url})"
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
body += f"\n\n{process_video(file)}"
|
body += f"\n\n{process_video(file)}"
|
||||||
|
@ -69,10 +69,10 @@ def process_video(file):
|
||||||
return f'{SITE_FULL}{new}'
|
return f'{SITE_FULL}{new}'
|
||||||
|
|
||||||
|
|
||||||
def process_image(patron, filename=None, resize=0):
|
def process_image(filename=None, resize=0):
|
||||||
size = os.stat(filename).st_size
|
size = os.stat(filename).st_size
|
||||||
|
|
||||||
if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024:
|
if size > 16 * 1024 * 1024 or not g.v.patron and size > 8 * 1024 * 1024:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
abort(413)
|
abort(413)
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,7 @@ def api_comment(v):
|
||||||
if file.content_type.startswith('image/'):
|
if file.content_type.startswith('image/'):
|
||||||
oldname = f'/images/{time.time()}'.replace('.','') + '.webp'
|
oldname = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||||
file.save(oldname)
|
file.save(oldname)
|
||||||
image = process_image(v.patron, oldname)
|
image = process_image(oldname)
|
||||||
if image == "": return {"error":"Image upload failed"}
|
if image == "": return {"error":"Image upload failed"}
|
||||||
if v.admin_level > 2 and level == 1:
|
if v.admin_level > 2 and level == 1:
|
||||||
if parent_post.id == 37696:
|
if parent_post.id == 37696:
|
||||||
|
@ -228,14 +228,14 @@ def api_comment(v):
|
||||||
num = int(li.split('.webp')[0]) + 1
|
num = int(li.split('.webp')[0]) + 1
|
||||||
filename = f'files/assets/images/{SITE_NAME}/sidebar/{num}.webp'
|
filename = f'files/assets/images/{SITE_NAME}/sidebar/{num}.webp'
|
||||||
copyfile(oldname, filename)
|
copyfile(oldname, filename)
|
||||||
process_image(v.patron, filename, 400)
|
process_image(filename, 400)
|
||||||
elif parent_post.id == 37697:
|
elif parent_post.id == 37697:
|
||||||
li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/banners'),
|
li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/banners'),
|
||||||
key=lambda e: int(e.split('.webp')[0]))[-1]
|
key=lambda e: int(e.split('.webp')[0]))[-1]
|
||||||
num = int(li.split('.webp')[0]) + 1
|
num = int(li.split('.webp')[0]) + 1
|
||||||
filename = f'files/assets/images/{SITE_NAME}/banners/{num}.webp'
|
filename = f'files/assets/images/{SITE_NAME}/banners/{num}.webp'
|
||||||
copyfile(oldname, filename)
|
copyfile(oldname, filename)
|
||||||
process_image(v.patron, filename)
|
process_image(filename)
|
||||||
elif parent_post.id == 37833:
|
elif parent_post.id == 37833:
|
||||||
try:
|
try:
|
||||||
badge_def = loads(body)
|
badge_def = loads(body)
|
||||||
|
@ -249,7 +249,7 @@ def api_comment(v):
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
filename = f'files/assets/images/badges/{badge.id}.webp'
|
filename = f'files/assets/images/badges/{badge.id}.webp'
|
||||||
copyfile(oldname, filename)
|
copyfile(oldname, filename)
|
||||||
process_image(v.patron, filename, 200)
|
process_image(filename, 200)
|
||||||
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS,
|
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS,
|
||||||
data=f'{{"files": ["https://{request.host}/assets/images/badges/{badge.id}.webp"]}}', timeout=5)
|
data=f'{{"files": ["https://{request.host}/assets/images/badges/{badge.id}.webp"]}}', timeout=5)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -272,7 +272,7 @@ def api_comment(v):
|
||||||
|
|
||||||
filename = f'files/assets/images/emojis/{name}.webp'
|
filename = f'files/assets/images/emojis/{name}.webp'
|
||||||
copyfile(oldname, filename)
|
copyfile(oldname, filename)
|
||||||
process_image(v.patron, filename, 200)
|
process_image(filename, 200)
|
||||||
|
|
||||||
marsey = Marsey(name=name, author_id=user.id, tags=tags, count=0)
|
marsey = Marsey(name=name, author_id=user.id, tags=tags, count=0)
|
||||||
g.db.add(marsey)
|
g.db.add(marsey)
|
||||||
|
|
|
@ -701,7 +701,7 @@ def thumbnail_thread(pid):
|
||||||
for chunk in image_req.iter_content(1024):
|
for chunk in image_req.iter_content(1024):
|
||||||
file.write(chunk)
|
file.write(chunk)
|
||||||
|
|
||||||
post.thumburl = process_image(0, name, resize=100)
|
post.thumburl = process_image(name, resize=100)
|
||||||
db.add(post)
|
db.add(post)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
@ -1054,11 +1054,11 @@ def submit_post(v, sub=None):
|
||||||
if file.content_type.startswith('image/'):
|
if file.content_type.startswith('image/'):
|
||||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
post.url = process_image(v.patron, name)
|
post.url = process_image(name)
|
||||||
|
|
||||||
name2 = name.replace('.webp', 'r.webp')
|
name2 = name.replace('.webp', 'r.webp')
|
||||||
copyfile(name, name2)
|
copyfile(name, name2)
|
||||||
post.thumburl = process_image(v.patron, name2, resize=100)
|
post.thumburl = process_image(name2, resize=100)
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
post.url = process_video(file)
|
post.url = process_video(file)
|
||||||
elif file.content_type.startswith('audio/'):
|
elif file.content_type.startswith('audio/'):
|
||||||
|
|
|
@ -543,13 +543,13 @@ def settings_images_profile(v):
|
||||||
|
|
||||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
highres = process_image(v.patron, name)
|
highres = process_image(name)
|
||||||
|
|
||||||
if not highres: abort(400)
|
if not highres: abort(400)
|
||||||
|
|
||||||
name2 = name.replace('.webp', 'r.webp')
|
name2 = name.replace('.webp', 'r.webp')
|
||||||
copyfile(name, name2)
|
copyfile(name, name2)
|
||||||
imageurl = process_image(v.patron, name2, resize=100)
|
imageurl = process_image(name2, resize=100)
|
||||||
|
|
||||||
if not imageurl: abort(400)
|
if not imageurl: abort(400)
|
||||||
|
|
||||||
|
@ -579,7 +579,7 @@ def settings_images_banner(v):
|
||||||
|
|
||||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
bannerurl = process_image(v.patron, name)
|
bannerurl = process_image(name)
|
||||||
|
|
||||||
if bannerurl:
|
if bannerurl:
|
||||||
if v.bannerurl and '/images/' in v.bannerurl:
|
if v.bannerurl and '/images/' in v.bannerurl:
|
||||||
|
|
|
@ -403,7 +403,7 @@ def sub_banner(v, sub):
|
||||||
|
|
||||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
bannerurl = process_image(v.patron, name)
|
bannerurl = process_image(name)
|
||||||
|
|
||||||
if bannerurl:
|
if bannerurl:
|
||||||
if sub.bannerurl and '/images/' in sub.bannerurl:
|
if sub.bannerurl and '/images/' in sub.bannerurl:
|
||||||
|
@ -430,7 +430,7 @@ def sub_sidebar(v, sub):
|
||||||
file = request.files["sidebar"]
|
file = request.files["sidebar"]
|
||||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||||
file.save(name)
|
file.save(name)
|
||||||
sidebarurl = process_image(v.patron, name)
|
sidebarurl = process_image(name)
|
||||||
|
|
||||||
if sidebarurl:
|
if sidebarurl:
|
||||||
if sub.sidebarurl and '/images/' in sub.sidebarurl:
|
if sub.sidebarurl and '/images/' in sub.sidebarurl:
|
||||||
|
|
Loading…
Reference in New Issue