diff --git a/bootstrap/site_env b/bootstrap/site_env
index 4b4319e1c..66ffea61b 100644
--- a/bootstrap/site_env
+++ b/bootstrap/site_env
@@ -8,7 +8,6 @@ HCAPTCHA_SECRET=blahblahblah
YOUTUBE_KEY=blahblahblah
PUSHER_ID=blahblahblah
PUSHER_KEY=blahblahblah
-IMGUR_KEY=blahblahblah
SPAM_SIMILARITY_THRESHOLD=0.5
SPAM_URL_SIMILARITY_THRESHOLD=0.1
SPAM_SIMILAR_COUNT_THRESHOLD=10
diff --git a/files/classes/__init__.py b/files/classes/__init__.py
index b182c6840..2225bfd15 100644
--- a/files/classes/__init__.py
+++ b/files/classes/__init__.py
@@ -86,7 +86,7 @@ from .volunteer_janitor import VolunteerJanitorRecord
# Then the import * from files.*
from files.helpers.const import *
-from files.helpers.images import *
+from files.helpers.media import *
from files.helpers.lazy import *
from files.helpers.security import *
diff --git a/files/classes/user.py b/files/classes/user.py
index c4f2673c1..a93cc6b91 100644
--- a/files/classes/user.py
+++ b/files/classes/user.py
@@ -1,7 +1,7 @@
from sqlalchemy.orm import deferred, aliased
from secrets import token_hex
import pyotp
-from files.helpers.images import *
+from files.helpers.media import *
from files.helpers.const import *
from .alts import Alt
from .saves import *
diff --git a/files/helpers/const.py b/files/helpers/const.py
index 1628775d5..093af8a8a 100644
--- a/files/helpers/const.py
+++ b/files/helpers/const.py
@@ -50,7 +50,6 @@ SORTS_POSTS = {
SORTS_POSTS.update(SORTS_COMMON)
SORTS_COMMENTS = SORTS_COMMON
-IMGUR_KEY = environ.get("IMGUR_KEY").strip()
PUSHER_ID = environ.get("PUSHER_ID", "").strip()
PUSHER_KEY = environ.get("PUSHER_KEY", "").strip()
DEFAULT_COLOR = environ.get("DEFAULT_COLOR", "fff").strip()
diff --git a/files/helpers/images.py b/files/helpers/media.py
similarity index 94%
rename from files/helpers/images.py
rename to files/helpers/media.py
index f7d2a5369..494b49967 100644
--- a/files/helpers/images.py
+++ b/files/helpers/media.py
@@ -1,10 +1,10 @@
-from PIL import Image, ImageOps
-from PIL.ImageSequence import Iterator
-from webptools import gifwebp
import subprocess
+from flask import Request
+from PIL import Image, ImageOps
+from webptools import gifwebp
+
def process_image(filename=None, resize=0):
-
i = Image.open(filename)
if resize and i.width > resize:
diff --git a/files/routes/admin.py b/files/routes/admin.py
index 4f0e4c475..1ae32ae55 100644
--- a/files/routes/admin.py
+++ b/files/routes/admin.py
@@ -1,13 +1,11 @@
import time
-from os import remove
-from PIL import Image as IMAGE
from files.helpers.wrappers import *
from files.helpers.alerts import *
from files.helpers.sanitize import *
from files.helpers.security import *
from files.helpers.get import *
-from files.helpers.images import *
+from files.helpers.media import *
from files.helpers.const import *
from files.classes import *
from flask import *
@@ -16,7 +14,6 @@ from .front import frontlist
from files.helpers.comments import comment_on_publish, comment_on_unpublish
from datetime import datetime
import requests
-from urllib.parse import quote, urlencode
month = datetime.now().strftime('%B')
diff --git a/files/routes/comments.py b/files/routes/comments.py
index 587b7d9aa..eca4118e1 100644
--- a/files/routes/comments.py
+++ b/files/routes/comments.py
@@ -1,6 +1,6 @@
from files.helpers.wrappers import *
from files.helpers.alerts import *
-from files.helpers.images import *
+from files.helpers.media import process_image
from files.helpers.const import *
from files.helpers.comments import comment_on_publish
from files.classes import *
@@ -152,22 +152,7 @@ def api_comment(v):
body += f"\n\n"
else:
body += f'\n\n{image}'
- elif file.content_type.startswith('video/'):
- file.save("video.mp4")
- with open("video.mp4", 'rb') as f:
- try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
- except requests.Timeout: abort(500, "Video upload timed out, please try again!")
- try: url = req['link']
- except:
- error = req['error']
- if error == 'File exceeds max duration': error += ' (60 seconds)'
- abort(400, error)
- if url.endswith('.'): url += 'mp4'
- if app.config['MULTIMEDIA_EMBEDDING_ENABLED']:
- body += f"\n\n{url}"
- else:
- body += f'\n\n{url}'
- else: abort(400, "Image/Video files only")
+ else: abort(400, "Image files only")
body_html = sanitize(body, comment=True)
@@ -330,19 +315,7 @@ def edit_comment(cid, v):
file.save(name)
url = process_image(name)
body += f"\n\n"
- elif file.content_type.startswith('video/'):
- file.save("video.mp4")
- with open("video.mp4", 'rb') as f:
- try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
- except requests.Timeout: abort(500, "Video upload timed out, please try again!")
- try: url = req['link']
- except:
- error = req['error']
- if error == 'File exceeds max duration': error += ' (60 seconds)'
- abort(400, error)
- if url.endswith('.'): url += 'mp4'
- body += f"\n\n{url}"
- else: abort(400, "Image/Video files only")
+ else: abort(400, "Image files only")
body_html = sanitize(body, edit=True)
diff --git a/files/routes/posts.py b/files/routes/posts.py
index cf01ee780..2e0a83054 100644
--- a/files/routes/posts.py
+++ b/files/routes/posts.py
@@ -6,6 +6,7 @@ from files.helpers.alerts import *
from files.helpers.comments import comment_filter_moderated
from files.helpers.contentsorting import sort_objects
from files.helpers.const import *
+from files.helpers.media import process_image
from files.helpers.strings import sql_ilike_clean
from files.classes import *
from flask import *
@@ -320,22 +321,7 @@ def edit_post(pid, v):
body += f"\n\n"
else:
body += f'\n\n{url}'
- elif file.content_type.startswith('video/'):
- file.save("video.mp4")
- with open("video.mp4", 'rb') as f:
- try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
- except requests.Timeout: abort(500, "Video upload timed out, please try again!")
- try: url = req['link']
- except:
- error = req['error']
- if error == 'File exceeds max duration': error += ' (60 seconds)'
- abort(400, error)
- if url.endswith('.'): url += 'mp4'
- if app.config['MULTIMEDIA_EMBEDDING_ENABLED']:
- body += f"\n\n"
- else:
- body += f'\n\n{url}'
- else: abort(400, "Image/Video files only")
+ else: abort(400, "Image files only")
body_html = sanitize(body, edit=True)
@@ -739,23 +725,8 @@ def submit_post(v, sub=None):
body += f"\n\n"
else:
body += f'\n\n{image}'
- elif file.content_type.startswith('video/'):
- file.save("video.mp4")
- with open("video.mp4", 'rb') as f:
- try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
- except requests.Timeout: return error("Video upload timed out, please try again!")
- try: url = req['link']
- except:
- err = req['error']
- if err == 'File exceeds max duration': err += ' (60 seconds)'
- return error(err)
- if url.endswith('.'): url += 'mp4'
- if app.config['MULTIMEDIA_EMBEDDING_ENABLED']:
- body += f"\n\n"
- else:
- body += f'\n\n{url}'
else:
- return error("Image/Video files only.")
+ return error("Image files only")
body_html = sanitize(body)
@@ -809,21 +780,9 @@ def submit_post(v, sub=None):
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
- post.thumburl = process_image(name2, resize=100)
- elif file.content_type.startswith('video/'):
- file.save("video.mp4")
- with open("video.mp4", 'rb') as f:
- try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
- except requests.Timeout: return error("Video upload timed out, please try again!")
- try: url = req['link']
- except:
- err = req['error']
- if err == 'File exceeds max duration': err += ' (60 seconds)'
- return error(err)
- if url.endswith('.'): url += 'mp4'
- post.url = url
+ post.thumburl = process_image(name2, resize=100)
else:
- return error("Image/Video files only.")
+ return error("Image files only")
if not post.thumburl and post.url:
gevent.spawn(thumbnail_thread, post.id)
diff --git a/files/routes/settings.py b/files/routes/settings.py
index 627842559..b82158b61 100644
--- a/files/routes/settings.py
+++ b/files/routes/settings.py
@@ -1,4 +1,5 @@
from files.helpers.alerts import *
+from files.helpers.media import process_image
from files.helpers.sanitize import *
from files.helpers.const import *
from files.mail import *
@@ -171,21 +172,9 @@ def settings_profile_post(v):
file.save(name)
url = process_image(name)
bio += f"\n\n"
- elif file.content_type.startswith('video/'):
- file.save("video.mp4")
- with open("video.mp4", 'rb') as f:
- try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
- except requests.Timeout: abort(500, "Video upload timed out, please try again!")
- try: url = req['link']
- except:
- error = req['error']
- if error == 'File exceeds max duration': error += ' (60 seconds)'
- abort(400, error)
- if url.endswith('.'): url += 'mp4'
- bio += f"\n\n{url}"
else:
- if request.headers.get("Authorization") or request.headers.get("xhr"): abort(400, "Image/Video files only")
- return render_template("settings_profile.html", v=v, error="Image/Video files only."), 400
+ if request.headers.get("Authorization") or request.headers.get("xhr"): abort(400, "Image files only")
+ return render_template("settings_profile.html", v=v, error="Image files only"), 400
bio_html = sanitize(bio)
diff --git a/files/routes/static.py b/files/routes/static.py
index 40b816b2d..d07562576 100644
--- a/files/routes/static.py
+++ b/files/routes/static.py
@@ -1,3 +1,4 @@
+from files.helpers.media import process_image
from files.mail import *
from files.__main__ import app, limiter, mail
from files.helpers.alerts import *
@@ -311,19 +312,7 @@ def submit_contact(v: Optional[User]):
file.save(name)
url = process_image(name)
html += f''
- elif file.content_type.startswith('video/'):
- file.save("video.mp4")
- with open("video.mp4", 'rb') as f:
- try: req = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)], timeout=5).json()['data']
- except requests.Timeout: abort(500, "Video upload timed out, please try again!")
- try: url = req['link']
- except:
- error = req['error']
- if error == 'File exceeds max duration': error += ' (60 seconds)'
- abort(400, error)
- if url.endswith('.'): url += 'mp4'
- html += f"
{url}
" - else: abort(400, "Image/Video files only") + else: abort(400, "Image files only") new_comment = Comment(author_id=v.id if v else NOTIFICATIONS_ID, parent_submission=None, diff --git a/files/routes/users.py b/files/routes/users.py index f2fecf9ea..459b78257 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -4,6 +4,7 @@ import time import math from files.classes.views import ViewerRelationship from files.helpers.alerts import * +from files.helpers.media import process_image from files.helpers.sanitize import * from files.helpers.strings import sql_ilike_clean from files.helpers.const import * @@ -602,19 +603,7 @@ def messagereply(v): file.save(name) url = process_image(name) body_html += f'{url}
" - else: abort(400, "Image/Video files only") + else: abort(400, "Image files only") c = Comment(author_id=v.id, diff --git a/files/templates/comments.html b/files/templates/comments.html index f9784b70d..0335f04a3 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -521,7 +521,7 @@ Comment @@ -559,7 +559,7 @@ {% if c.sentto == MODMAIL_ID %} {% endif %} diff --git a/files/templates/contact.html b/files/templates/contact.html index 8ce463847..e149b61ef 100644 --- a/files/templates/contact.html +++ b/files/templates/contact.html @@ -28,7 +28,7 @@ {% if not v and hcaptcha %} diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index 2a8b13cba..bfe98536d 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -384,7 +384,7 @@ diff --git a/files/templates/submission.html b/files/templates/submission.html index 7061e929b..1acc356f8 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -294,7 +294,7 @@ GIF @@ -455,7 +455,7 @@ Comment diff --git a/files/templates/submit.html b/files/templates/submit.html index 3f981700f..7ee6d20f3 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -72,7 +72,7 @@