From c69484a1038fa53c6849fffcfff132e8c7aeaac9 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 18:50:17 +0200 Subject: [PATCH 01/46] jdiuehfur --- files/__main__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files/__main__.py b/files/__main__.py index d59cdd0f52..de05558046 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -76,6 +76,9 @@ app.config["SPAM_URL_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_URL_SIMILA app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"] = float(environ.get("COMMENT_SPAM_SIMILAR_THRESHOLD", 0.5)) app.config["COMMENT_SPAM_COUNT_THRESHOLD"] = int(environ.get("COMMENT_SPAM_COUNT_THRESHOLD", 0.5)) +# how many coins are required to upload videos +app.config["VIDEO_COIN_REQUIREMENT"] = int(environ.get("VIDEO_COIN_REQUIREMENT", 0)) + app.config["CACHE_REDIS_URL"] = environ.get("REDIS_URL").strip() app.config["CACHE_DEFAULT_TIMEOUT"] = 60 app.config["CACHE_KEY_PREFIX"] = "flask_caching_" From e36678eaf702655b2bd01fd2a49a8a1bdc4524ff Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 18:53:01 +0200 Subject: [PATCH 02/46] jdiuehfur --- files/helpers/images.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index 37c1914be8..0eb0a5dd66 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -1,9 +1,10 @@ import requests -from os import environ +from os import environ, path, remove from PIL import Image as IImage, ImageSequence import base64 from files.classes.images import * from flask import g +from werkzeug.utils import secure_filename CF_KEY = environ.get("CLOUDFLARE_KEY", "").strip() CF_ZONE = environ.get("CLOUDFLARE_ZONE", "").strip() @@ -86,4 +87,30 @@ def upload_imgur(file=None, resize=False, png=False): new_image = Image(text=url, deletehash=resp["deletehash"]) g.db.add(new_image) - return(url) \ No newline at end of file + return(url) + + +class UploadException(Exception): + """Custom exception to raise if upload goes wrong""" + pass + + +def upload_video(file): + + file_path = path.join("temp", secure_filename(file.filename)) + + headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} + with open(file_path, 'rb') as f: + try: + r = requests.post('https://api.imgur.com/3/upload', headers=headers, data={"video": f}) + r.raise_for_status() + + resp = r.json()['data'] + except requests.HTTPError as e: + raise UploadException(f"Status code {e.response.status_code} not in range 2**") + except Exception: + raise UploadException("Error, please try again later.") + finally: + remove(file_path) + + return resp['link'] From f3dbe87357716cba0bad58914921c364a49673c6 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 18:53:10 +0200 Subject: [PATCH 03/46] jdiuehfur --- files/templates/submit.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/templates/submit.html b/files/templates/submit.html index 09e7710eb8..3736b66e2a 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -330,13 +330,13 @@
-
+
Images uploaded will be public. Optional if you have text. From 564b0096c19cf44e19f8168bb33a6eaa804791e3 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 18:53:18 +0200 Subject: [PATCH 04/46] jdiuehfur --- files/routes/posts.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index c6da808d23..81417a911d 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -826,13 +826,38 @@ def submit_post(v): abort(413) file = request.files['file'] - if not file.content_type.startswith('image/'): - if request.headers.get("Authorization"): return {"error": f"Image files only"}, 400 - else: return render_template("submit.html", v=v, error=f"Image files only.", title=title, body=request.form.get("body", "")), 400 + #if not file.content_type.startswith('image/'): + # if request.headers.get("Authorization"): return {"error": f"Image files only"}, 400 + # else: return render_template("submit.html", v=v, error=f"Image files only.", title=title, body=request.form.get("body", "")), 400 + if not file.content_type.startswith(('image/', 'video/')): + if request.headers.get("Authorization"): return {"error": f"File type not allowed"}, 400 + else: return render_template("submit.html", v=v, error=f"File type not allowed.", title=title, body=request.form.get("body", "")), 400 - if 'pcm' in request.host: new_post.url = upload_ibb(file) - else: new_post.url = upload_imgur(file) + if file.content_type.startswith('video/') and v.coins < app.config["VIDEO_COIN_REQUIREMENT"] and v.admin_level < 1: + if request.headers.get("Authorization"): + return { + "error": f"You need at least {app.config['VIDEO_COIN_REQUIREMENT']} coins to upload videos" + }, 400 + else: + return render_template( + "submit.html", + v=v, + error=f"You need at least {app.config['VIDEO_COIN_REQUIREMENT']} coins to upload videos.", + title=title, + body=request.form.get("body", "") + ), 400 + + if 'pcm' in request.host: + if file.content_type.startswith('image/'): + new_post.url = upload_ibb(file) + else: + new_post.url = upload_video(file) + else: + if file.content_type.startswith('image/'): + new_post.url = upload_imgur(file) + else: + new_post.url = upload_video(file) g.db.add(new_post) g.db.add(new_post.submission_aux) From 4684f822c090bca4abaaba226a52043ec52eafbe Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 19:14:52 +0200 Subject: [PATCH 05/46] really nigga --- files/helpers/images.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/helpers/images.py b/files/helpers/images.py index 0eb0a5dd66..2f137691c4 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -98,6 +98,7 @@ class UploadException(Exception): def upload_video(file): file_path = path.join("temp", secure_filename(file.filename)) + file.save(file_path) headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} with open(file_path, 'rb') as f: From 9cb02e284b8fa8fbd56f12b88b766b53c6d2ab62 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 19:17:42 +0200 Subject: [PATCH 06/46] form encoding --- files/helpers/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index 2f137691c4..dc96e8f800 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -103,7 +103,7 @@ def upload_video(file): headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} with open(file_path, 'rb') as f: try: - r = requests.post('https://api.imgur.com/3/upload', headers=headers, data={"video": f}) + r = requests.post('https://api.imgur.com/3/upload', headers=headers, files=[], data={"video": f}) r.raise_for_status() resp = r.json()['data'] From de2f1315c90a74bdb15d9d8bae3dbd9591e08652 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 19:19:56 +0200 Subject: [PATCH 07/46] iojsjufu --- files/helpers/images.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/helpers/images.py b/files/helpers/images.py index dc96e8f800..dd867d03da 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -108,6 +108,7 @@ def upload_video(file): resp = r.json()['data'] except requests.HTTPError as e: + if r: print(r.json()) raise UploadException(f"Status code {e.response.status_code} not in range 2**") except Exception: raise UploadException("Error, please try again later.") From 99966991885fb80e45a76f3d80fbe15ded1028ca Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 19:22:18 +0200 Subject: [PATCH 08/46] jdijefjoirw --- files/helpers/images.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index dd867d03da..c228d3000b 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -104,7 +104,8 @@ def upload_video(file): with open(file_path, 'rb') as f: try: r = requests.post('https://api.imgur.com/3/upload', headers=headers, files=[], data={"video": f}) - r.raise_for_status() + print(r.text) + #r.raise_for_status() resp = r.json()['data'] except requests.HTTPError as e: From d2fd82114b307006df6f58333280f7b746d139fb Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 19:24:56 +0200 Subject: [PATCH 09/46] undo this --- files/helpers/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index c228d3000b..9ae1e4d8f7 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -103,7 +103,7 @@ def upload_video(file): headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} with open(file_path, 'rb') as f: try: - r = requests.post('https://api.imgur.com/3/upload', headers=headers, files=[], data={"video": f}) + r = requests.post('https://api.imgur.com/3/upload', headers=headers, data={"video": f}) print(r.text) #r.raise_for_status() From ecae04bc64f2dd05b6d73a39ec5abb5c83747277 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 19:52:40 +0200 Subject: [PATCH 10/46] jdjufrw --- files/helpers/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index 9ae1e4d8f7..bd6d9e50ab 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -103,7 +103,7 @@ def upload_video(file): headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} with open(file_path, 'rb') as f: try: - r = requests.post('https://api.imgur.com/3/upload', headers=headers, data={"video": f}) + r = requests.post('https://api.imgur.com/3/upload', headers=headers, files={"video": f}) print(r.text) #r.raise_for_status() From a3d090dfbdd765e7eff07b7149b5b4e7b3a614be Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 19:54:02 +0200 Subject: [PATCH 11/46] jdjufrw --- files/helpers/images.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/helpers/images.py b/files/helpers/images.py index bd6d9e50ab..1de94252cc 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -104,6 +104,7 @@ def upload_video(file): with open(file_path, 'rb') as f: try: r = requests.post('https://api.imgur.com/3/upload', headers=headers, files={"video": f}) + print(r.text) #r.raise_for_status() From fbab4ff6dada8208f88a975ea796cacbf72f0b65 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 20:14:44 +0200 Subject: [PATCH 12/46] jdjufrw --- files/helpers/images.py | 6 ++---- files/routes/posts.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index 1de94252cc..d79e5b8095 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -105,13 +105,11 @@ def upload_video(file): try: r = requests.post('https://api.imgur.com/3/upload', headers=headers, files={"video": f}) - print(r.text) - #r.raise_for_status() + r.raise_for_status() resp = r.json()['data'] except requests.HTTPError as e: - if r: print(r.json()) - raise UploadException(f"Status code {e.response.status_code} not in range 2**") + raise UploadException("Invalid video. Make sure it's 1 minute long or shorter.") except Exception: raise UploadException("Error, please try again later.") finally: diff --git a/files/routes/posts.py b/files/routes/posts.py index 81417a911d..29d8e94ecc 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -857,7 +857,21 @@ def submit_post(v): if file.content_type.startswith('image/'): new_post.url = upload_imgur(file) else: - new_post.url = upload_video(file) + try: + new_post.url = upload_video(file) + except UploadException as e: + if request.headers.get("Authorization"): + return { + "error": str(e), + }, 400 + else: + return render_template( + "submit.html", + v=v, + error=str(e), + title=title, + body=request.form.get("body", "") + ), 400 g.db.add(new_post) g.db.add(new_post.submission_aux) From b5985ef4c0f72f59b1072f8bb1a748d8e6623367 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 21:09:58 +0200 Subject: [PATCH 13/46] pcm --- files/routes/posts.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 29d8e94ecc..9be4aa31d2 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -852,7 +852,21 @@ def submit_post(v): if file.content_type.startswith('image/'): new_post.url = upload_ibb(file) else: - new_post.url = upload_video(file) + try: + new_post.url = upload_video(file) + except UploadException as e: + if request.headers.get("Authorization"): + return { + "error": str(e), + }, 400 + else: + return render_template( + "submit.html", + v=v, + error=str(e), + title=title, + body=request.form.get("body", "") + ), 400 else: if file.content_type.startswith('image/'): new_post.url = upload_imgur(file) From 9cc44ce7774baf801398ff2fd15a4f49c194418f Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 21:10:33 +0200 Subject: [PATCH 14/46] pcm --- files/routes/posts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 9be4aa31d2..66e1f82460 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -857,8 +857,8 @@ def submit_post(v): except UploadException as e: if request.headers.get("Authorization"): return { - "error": str(e), - }, 400 + "error": str(e), + }, 400 else: return render_template( "submit.html", From 2fc8faae147f0b3c36d59d7f0fb7a8a50567300d Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 21:19:48 +0200 Subject: [PATCH 15/46] ijdjoiefjrje --- files/classes/submission.py | 7 +++++++ files/templates/submission.html | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 83147990c3..ff88b44635 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -400,6 +400,13 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): if self.url: return self.url.lower().endswith('.jpg') or self.url.lower().endswith('.png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('.jpeg') or self.url.lower().endswith('?maxwidth=9999') else: return False + @property + def is_video(self) -> bool: + if self.url: + return self.url.startswith("https://i.imgur.com") and self.url.lower().endswith('.mp4') + else: + return False + @property @lazy def active_flags(self): return self.flags.count() diff --git a/files/templates/submission.html b/files/templates/submission.html index 1db0dcaada..2c286675b1 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -301,7 +301,7 @@

 
-							{% elif not p.embed_url and not p.is_image %}
+							{% elif not p.embed_url and not p.is_image and not p.is_video %}
 							
 								
{{p.domain|truncate(30, True)}} @@ -321,6 +321,15 @@

+							{% elif p.is_video %}
+								
+
+ +
+
+

 							{% endif %}
 							{{p.realbody(v) | safe}}
 						
@@ -498,7 +507,7 @@
 
 		
 
-		{% if not p.is_image %}
+		{% if not p.is_image and not p.is_video %}
 			
From 1f4cabf5d3ea8b5f88fc6f611d1398907eb9d01d Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 21:23:53 +0200 Subject: [PATCH 16/46] meta --- files/templates/submission.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files/templates/submission.html b/files/templates/submission.html index 2c286675b1..99f96eecb2 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -36,6 +36,9 @@ +{% if p.is_video %} + +{% endif %} From cb4572dedb949592b860edb38a0d8c984c01df77 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 21:26:33 +0200 Subject: [PATCH 17/46] meta --- files/templates/submission.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/files/templates/submission.html b/files/templates/submission.html index 99f96eecb2..eb20c264f6 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -65,6 +65,9 @@ +{% if p.is_video %} + +{% endif %} From 23bd579f87b622778fc76f51560361d321b9484e Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 21:30:16 +0200 Subject: [PATCH 18/46] load video metadata --- files/templates/submission.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/submission.html b/files/templates/submission.html index eb20c264f6..f6cbe3baed 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -330,7 +330,7 @@ {% elif p.is_video %}
-
From b503920699344fab6966ad1ed06d7439c2158b9e Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 21:57:50 +0200 Subject: [PATCH 19/46] ijd4iuhu --- files/templates/submission_listing.html | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 03074f41a6..1bd8bc397d 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -216,12 +216,20 @@
-{% if p.is_image and (not v or v.cardview) %} -
- - Unable to load image - -
+{% if not v or v.cardview %} + {% if p.is_image %} +
+ + Unable to load image + +
+ {% elif p.is_video %} +
+ +
+ {% endif %} {% endif %} {% if p.realbody(v) %} From 3b0094b6f58de5a701be148d3bac091a9627cb76 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 22:38:11 +0200 Subject: [PATCH 20/46] display vids in card view --- files/templates/submission_listing.html | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 1bd8bc397d..2b6cdb1f7f 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -216,20 +216,18 @@
-{% if not v or v.cardview %} - {% if p.is_image %} -
- - Unable to load image - -
- {% elif p.is_video %} -
- -
- {% endif %} +{% if p.is_image and not (v and not v.cardview) %} +
+ + Unable to load image + +
+{% elif p.is_video %} +
+ +
{% endif %} {% if p.realbody(v) %} From bc187810b853b2d02c6895a10129ce20680d6194 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 22:39:43 +0200 Subject: [PATCH 21/46] display vids in card view 2 --- files/templates/submission_listing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 2b6cdb1f7f..8b27f4ce5f 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -73,7 +73,7 @@ - {% else %} + {% elif not p.is_video %} From d5fb0c1dabfce8036d172e5ad4016044c94eacf3 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 22:42:56 +0200 Subject: [PATCH 22/46] undo --- files/templates/submission_listing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 8b27f4ce5f..2b6cdb1f7f 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -73,7 +73,7 @@ - {% elif not p.is_video %} + {% else %} From 608cfb579c25c7cbe665e788a429b3d89db071c0 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Sun, 5 Sep 2021 22:49:16 +0200 Subject: [PATCH 23/46] ikdifkrfijigtoeo --- files/templates/submission_listing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 2b6cdb1f7f..8b27f4ce5f 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -73,7 +73,7 @@ - {% else %} + {% elif not p.is_video %} From b2634df62ec38d0efcb7a06c9625feb97f9605ee Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 01:07:06 +0200 Subject: [PATCH 24/46] ikdifkrfijigtoeo --- files/templates/submission_listing.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 8b27f4ce5f..87141b6a42 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -70,7 +70,7 @@ {% elif p.is_image %} - + {% elif not p.is_video %} From 947cb8c40f47b41ac2600c8bee8890b6462ebce5 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 21:58:04 +0200 Subject: [PATCH 25/46] dijjdfrejf --- files/routes/posts.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 66e1f82460..250cd35b85 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1,3 +1,4 @@ +import time from urllib.parse import urlparse import mistletoe import urllib.parse @@ -527,6 +528,24 @@ def filter_title(title): return title + +IMGUR_KEY = environ.get("IMGUR_KEY", "").strip() + + +def check_processing_thread(post, link, db): + + print("spawn checking thread") + time.sleep(15) + + image_id = link.split('/')[-1] + + headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} + req = requests.get(f"https://api.imgur.com/image/{image_id}", headers=headers) + + print(req.text) + return + + @app.post("/submit") @limiter.limit("6/minute") @is_not_banned @@ -869,7 +888,9 @@ def submit_post(v): ), 400 else: if file.content_type.startswith('image/'): - new_post.url = upload_imgur(file) + post_url = upload_imgur(file) + new_post.url = post_url + gevent.spawn(check_processing_thread, post=new_post, link=post_url, db=g.db) else: try: new_post.url = upload_video(file) From 8d13dc3a68284d06abe2eaffad5c2c6f215046b2 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:06:11 +0200 Subject: [PATCH 26/46] df --- files/routes/posts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 250cd35b85..8574ffa594 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -890,7 +890,7 @@ def submit_post(v): if file.content_type.startswith('image/'): post_url = upload_imgur(file) new_post.url = post_url - gevent.spawn(check_processing_thread, post=new_post, link=post_url, db=g.db) + gevent.spawn(check_processing_thread, new_post, post_url, g.db) else: try: new_post.url = upload_video(file) From 3b244175c4c9c34dcb5c157f50e27aed741d8747 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:07:58 +0200 Subject: [PATCH 27/46] ijkikpooii --- files/routes/posts.py | 1 - 1 file changed, 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 8574ffa594..7140cc1e6d 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -543,7 +543,6 @@ def check_processing_thread(post, link, db): req = requests.get(f"https://api.imgur.com/image/{image_id}", headers=headers) print(req.text) - return @app.post("/submit") From 60b18901443d4dccd3418d589645fddd50ff3016 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:16:08 +0200 Subject: [PATCH 28/46] odekifr9i8ew8f --- files/routes/posts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 7140cc1e6d..689c647663 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -889,7 +889,8 @@ def submit_post(v): if file.content_type.startswith('image/'): post_url = upload_imgur(file) new_post.url = post_url - gevent.spawn(check_processing_thread, new_post, post_url, g.db) + thing = gevent.spawn(check_processing_thread, new_post, post_url, g.db) + print(thing.started) else: try: new_post.url = upload_video(file) From ee54cacaec0d6de44a216953acda131353307c95 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:18:59 +0200 Subject: [PATCH 29/46] pokkoppok --- files/routes/posts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 689c647663..51eb860041 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -871,7 +871,10 @@ def submit_post(v): new_post.url = upload_ibb(file) else: try: - new_post.url = upload_video(file) + post_url = upload_imgur(file) + new_post.url = post_url + thing = gevent.spawn(check_processing_thread, new_post, post_url, g.db) + print(thing.started) except UploadException as e: if request.headers.get("Authorization"): return { From 71ccb856ce80334bd859b3a34c4fb0e503c842a5 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:22:33 +0200 Subject: [PATCH 30/46] im going to kill myself --- files/routes/posts.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 51eb860041..83df5e0987 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -871,7 +871,7 @@ def submit_post(v): new_post.url = upload_ibb(file) else: try: - post_url = upload_imgur(file) + post_url = upload_video(file) new_post.url = post_url thing = gevent.spawn(check_processing_thread, new_post, post_url, g.db) print(thing.started) @@ -890,13 +890,13 @@ def submit_post(v): ), 400 else: if file.content_type.startswith('image/'): - post_url = upload_imgur(file) - new_post.url = post_url - thing = gevent.spawn(check_processing_thread, new_post, post_url, g.db) - print(thing.started) + new_post.url = upload_imgur(file) else: try: - new_post.url = upload_video(file) + post_url = upload_video(file) + new_post.url = post_url + thing = gevent.spawn(check_processing_thread, new_post, post_url, g.db) + print(thing.started) except UploadException as e: if request.headers.get("Authorization"): return { From e733e7aee3c95a73bd21ae8b4cdfb6e962602366 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:25:57 +0200 Subject: [PATCH 31/46] doieijfdiw --- files/routes/posts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 83df5e0987..f8a599803c 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -537,7 +537,7 @@ def check_processing_thread(post, link, db): print("spawn checking thread") time.sleep(15) - image_id = link.split('/')[-1] + image_id = link.split('/')[-1].rstrip('.mp4') headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} req = requests.get(f"https://api.imgur.com/image/{image_id}", headers=headers) From 5ddf34a48efb2a15c2e315a1d757d6eef9e75384 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:28:26 +0200 Subject: [PATCH 32/46] df --- files/routes/posts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index f8a599803c..33a0a24cf3 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -538,11 +538,12 @@ def check_processing_thread(post, link, db): time.sleep(15) image_id = link.split('/')[-1].rstrip('.mp4') + print(f"request https://api.imgur.com/image/{image_id}") headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} req = requests.get(f"https://api.imgur.com/image/{image_id}", headers=headers) - print(req.text) + #print(req.text) @app.post("/submit") From 8c8d6e68a8a253097700db3c5505985ea6a8d574 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:30:12 +0200 Subject: [PATCH 33/46] fd --- files/routes/posts.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 33a0a24cf3..91a0d78b61 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -538,12 +538,11 @@ def check_processing_thread(post, link, db): time.sleep(15) image_id = link.split('/')[-1].rstrip('.mp4') - print(f"request https://api.imgur.com/image/{image_id}") headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} - req = requests.get(f"https://api.imgur.com/image/{image_id}", headers=headers) + req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers) - #print(req.text) + print(req.text) @app.post("/submit") From 771041a0a3a219cc7f743ec4c153a4c2ddf9b057 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:56:14 +0200 Subject: [PATCH 34/46] fd --- files/helpers/alerts.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index fe8f686bde..10b50de58a 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -7,7 +7,10 @@ from .sanitize import * from .const import * -def send_notification(vid, user, text): +def send_notification(vid, user, text, db=None): + + if not db: + db = g.db text = text.replace('r/', 'r\/').replace('u/', 'u\/') text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") @@ -20,19 +23,19 @@ def send_notification(vid, user, text): parent_submission=None, distinguish_level=6, ) - g.db.add(new_comment) + db.add(new_comment) - g.db.flush() + db.flush() new_aux = CommentAux(id=new_comment.id, body=text, body_html=text_html, ) - g.db.add(new_aux) + db.add(new_aux) notif = Notification(comment_id=new_comment.id, user_id=user.id) - g.db.add(notif) + db.add(notif) def send_pm(vid, user, text): From 70d89f79bf13c289f85b785bf1b94bdd21f4a7fa Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:56:43 +0200 Subject: [PATCH 35/46] fd --- files/routes/front.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/files/routes/front.py b/files/routes/front.py index 88c76393e9..36832ea6bd 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -121,6 +121,11 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' posts = posts.filter_by(is_banned=False,stickied=False,private=False).filter(Submission.deleted_utc == 0) + if v: + posts = posts.filter(or_(Submission.processing == False, Submission.author_id == v.id)) + else: + posts = posts.filter_by(processing=False) + if v and v.admin_level == 0: blocking = g.db.query( UserBlock.target_id).filter_by( From c1f5313262a17ef8b4aaaea22cf5470dba377da3 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:56:55 +0200 Subject: [PATCH 36/46] fd --- files/routes/posts.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 91a0d78b61..4fea9fb89e 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -532,17 +532,30 @@ def filter_title(title): IMGUR_KEY = environ.get("IMGUR_KEY", "").strip() -def check_processing_thread(post, link, db): - - print("spawn checking thread") - time.sleep(15) +def check_processing_thread(v, post, link, db): image_id = link.split('/')[-1].rstrip('.mp4') - headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} - req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers) - print(req.text) + while True: + time.sleep(15) + + req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers) + + status = req.json()['data']['processing']['status'] + if status == 'completed': + post.processing = False + db.add(post) + + send_notification( + NOTIFICATIONS_ACCOUNT, + v, + f"Your video has finished processing and your [post](/post/{post.id}) is now live.", + db=db + ) + + db.commit() + break @app.post("/submit") @@ -856,7 +869,7 @@ def submit_post(v): if request.headers.get("Authorization"): return { "error": f"You need at least {app.config['VIDEO_COIN_REQUIREMENT']} coins to upload videos" - }, 400 + }, 403 else: return render_template( "submit.html", @@ -864,7 +877,7 @@ def submit_post(v): error=f"You need at least {app.config['VIDEO_COIN_REQUIREMENT']} coins to upload videos.", title=title, body=request.form.get("body", "") - ), 400 + ), 403 if 'pcm' in request.host: if file.content_type.startswith('image/'): @@ -873,8 +886,8 @@ def submit_post(v): try: post_url = upload_video(file) new_post.url = post_url - thing = gevent.spawn(check_processing_thread, new_post, post_url, g.db) - print(thing.started) + new_post.processing = True + gevent.spawn(check_processing_thread, v, new_post, post_url, g.db) except UploadException as e: if request.headers.get("Authorization"): return { @@ -895,8 +908,8 @@ def submit_post(v): try: post_url = upload_video(file) new_post.url = post_url - thing = gevent.spawn(check_processing_thread, new_post, post_url, g.db) - print(thing.started) + new_post.processing = True + gevent.spawn(check_processing_thread, v, new_post, post_url, g.db) except UploadException as e: if request.headers.get("Authorization"): return { From 464263e1e14a19d7ef4d24c3c0d96ba9d46d7097 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:57:03 +0200 Subject: [PATCH 37/46] fd --- files/templates/submission.html | 1 + 1 file changed, 1 insertion(+) diff --git a/files/templates/submission.html b/files/templates/submission.html index f6cbe3baed..0fd036ae3b 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -262,6 +262,7 @@ {% if p.is_bot %} {% endif %} {% if p.over_18 %}+18{% endif %} {% if p.private %}Draft{% endif %} + {% if p.processing %}uploading...{% endif %} {% if p.active_flags %}{{p.active_flags}} Reports{% endif %} {% if p.author.verified %} {% endif %} From cb422ba6ea86d9abe34a3e7a562327dde7d89a9d Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:57:10 +0200 Subject: [PATCH 38/46] fd --- files/classes/submission.py | 1 + 1 file changed, 1 insertion(+) diff --git a/files/classes/submission.py b/files/classes/submission.py index ff88b44635..c7bcc740b8 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -45,6 +45,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): thumburl = Column(String) is_banned = Column(Boolean, default=False) bannedfor = Column(Boolean) + processing = Column(Boolean, default=False) views = Column(Integer, default=0) deleted_utc = Column(Integer, default=0) distinguish_level = Column(Integer, default=0) From b56720b87dfd54af1abafb05f98e8faaeefd7bf2 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 22:57:17 +0200 Subject: [PATCH 39/46] fd --- files/templates/submission_listing.html | 1 + 1 file changed, 1 insertion(+) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 87141b6a42..26cfb036bd 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -105,6 +105,7 @@ {% if p.is_blocking %}{% endif %} {% if p.is_blocked %}{% endif %} {% if p.private %}Draft{% endif %} + {% if p.processing %}uploading...{% endif %} {% if p.active_flags %}{{p.active_flags}} Reports{% endif %} {% if p.author.verified %} {% endif %} From 7a4fd470e81e9329fbc5ed559932e61e3deb2bb2 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 23:04:01 +0200 Subject: [PATCH 40/46] zgdzu --- files/helpers/alerts.py | 8 +++++++- files/routes/posts.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 10b50de58a..8b55d1737e 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -9,6 +9,12 @@ from .const import * def send_notification(vid, user, text, db=None): + # for when working outside request context + if isinstance(user, int): + uid = user + else: + uid = user.id + if not db: db = g.db @@ -34,7 +40,7 @@ def send_notification(vid, user, text, db=None): db.add(new_aux) notif = Notification(comment_id=new_comment.id, - user_id=user.id) + user_id=uid) db.add(notif) diff --git a/files/routes/posts.py b/files/routes/posts.py index 4fea9fb89e..92d3a94f87 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -887,7 +887,7 @@ def submit_post(v): post_url = upload_video(file) new_post.url = post_url new_post.processing = True - gevent.spawn(check_processing_thread, v, new_post, post_url, g.db) + gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db) except UploadException as e: if request.headers.get("Authorization"): return { @@ -909,7 +909,7 @@ def submit_post(v): post_url = upload_video(file) new_post.url = post_url new_post.processing = True - gevent.spawn(check_processing_thread, v, new_post, post_url, g.db) + gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db) except UploadException as e: if request.headers.get("Authorization"): return { From fc067b342817d213986efc281fc14bc20cdffc75 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 23:20:14 +0200 Subject: [PATCH 41/46] zgdzu --- files/templates/submit.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/templates/submit.html b/files/templates/submit.html index 3736b66e2a..c83c0556e4 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -339,7 +339,8 @@ - Images uploaded will be public. Optional if you have text. + Optional if you have text. + You can upload videos up to 1 minute long if you have at least {{ 'VIDEO_COIN_REQUIREMENT' | app_config }} coins. From bccbdcd507ecf205c81cdddce19450db845890e2 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 23:23:01 +0200 Subject: [PATCH 42/46] zgdzu --- files/templates/submit.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/files/templates/submit.html b/files/templates/submit.html index c83c0556e4..a3723d681d 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -340,7 +340,8 @@ Optional if you have text. - You can upload videos up to 1 minute long if you have at least {{ 'VIDEO_COIN_REQUIREMENT' | app_config }} coins. +
+ You can upload videos up to 1 minute long if you have at least {{ 'VIDEO_COIN_REQUIREMENT' | app_config }} {{ 'COINS_NAME' | app_config }}{% if v.admin_level > 1 %} or are an admin{% endif %}. From 2c36cabcb15f3fcdcca98eab49a76c194ff8ce92 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 23:25:20 +0200 Subject: [PATCH 43/46] fd --- files/templates/submission_listing.html | 2 +- files/templates/submit.html | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 26cfb036bd..1931ae0f71 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -225,7 +225,7 @@ {% elif p.is_video %}
-
diff --git a/files/templates/submit.html b/files/templates/submit.html index a3723d681d..40c80affc8 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -340,7 +340,6 @@ Optional if you have text. -
You can upload videos up to 1 minute long if you have at least {{ 'VIDEO_COIN_REQUIREMENT' | app_config }} {{ 'COINS_NAME' | app_config }}{% if v.admin_level > 1 %} or are an admin{% endif %}. From f4322680c1f36244f4c0badd30d825cb751a0e70 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 23:29:14 +0200 Subject: [PATCH 44/46] fd --- files/templates/submission_listing.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 1931ae0f71..5da5840873 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -224,11 +224,13 @@ {% elif p.is_video %} -
- -
+ +
+ +
+
{% endif %} {% if p.realbody(v) %} From 7677f0751ff1617327b7ba1ebd330c0e277e707a Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 23:38:17 +0200 Subject: [PATCH 45/46] fd --- files/helpers/images.py | 6 +++++- files/routes/posts.py | 30 +++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index d79e5b8095..6cd522f97a 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -115,4 +115,8 @@ def upload_video(file): finally: remove(file_path) - return resp['link'] + link = resp['link'] + img = Image(text=link, deletehash=resp['deletehash']) + g.db.add(img) + + return link diff --git a/files/routes/posts.py b/files/routes/posts.py index 92d3a94f87..91e8fec69b 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -538,23 +538,27 @@ def check_processing_thread(v, post, link, db): headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} while True: - time.sleep(15) + # break on error to prevent zombie threads + try: + time.sleep(15) - req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers) + req = requests.get(f"https://api.imgur.com/3/image/{image_id}", headers=headers) - status = req.json()['data']['processing']['status'] - if status == 'completed': - post.processing = False - db.add(post) + status = req.json()['data']['processing']['status'] + if status == 'completed': + post.processing = False + db.add(post) - send_notification( - NOTIFICATIONS_ACCOUNT, - v, - f"Your video has finished processing and your [post](/post/{post.id}) is now live.", - db=db - ) + send_notification( + NOTIFICATIONS_ACCOUNT, + v, + f"Your video has finished processing and your [post](/post/{post.id}) is now live.", + db=db + ) - db.commit() + db.commit() + break + except Exception: break From b604749b2a05f880f84db42cc865f741a146ca24 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Mon, 6 Sep 2021 23:54:13 +0200 Subject: [PATCH 46/46] fd --- files/routes/posts.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/routes/posts.py b/files/routes/posts.py index 91e8fec69b..e7b62b4036 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -558,6 +558,10 @@ def check_processing_thread(v, post, link, db): db.commit() break + # just in case + elif status == 'failed': + print(f"video upload for post {post.id} failed") + break except Exception: break