From ce1e340f43f4486fc1e4fd0be37d9333fb915bb5 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Thu, 9 Sep 2021 13:02:06 +0200 Subject: [PATCH 1/3] dg --- .gitignore | 1 + files/routes/admin.py | 30 ++++++++++++++++++++++++++ files/routes/static.py | 18 ++++++++++++++++ files/templates/admin/admin_home.html | 30 +++++++++++++++++++------- files/templates/admin/rules.html | 31 +++++++++++++++++++++++++++ files/templates/header.html | 8 +++---- files/templates/norules.html | 26 ++++++++++++++++++++++ files/templates/rules.html | 18 ++++++++++++++++ 8 files changed, 150 insertions(+), 12 deletions(-) create mode 100644 files/templates/admin/rules.html create mode 100644 files/templates/norules.html create mode 100644 files/templates/rules.html diff --git a/.gitignore b/.gitignore index 50afe338a..47076b486 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,4 @@ local.txt *.scssc .idea/* disablesignups +/rules.md diff --git a/files/routes/admin.py b/files/routes/admin.py index e8e253d1b..3d489977d 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -3,6 +3,7 @@ import calendar from sqlalchemy.orm import lazyload import imagehash from os import remove +from os.path import exists from PIL import Image as IMAGE from files.helpers.wrappers import * @@ -52,6 +53,35 @@ def remove_admin(v, username): return {"message": "Admin removed!"} +@app.get('/admin/rules') +@admin_level_required(6) +def get_rules(v): + + try: + with open('./rules.md', 'r') as f: + rules = f.read() + except Exception: + rules = None + + return render_template('admin/rules.html', v=v, rules=rules) + + +@app.post('/admin/rules') +@admin_level_required(6) +@validate_formkey +def post_rules(v): + + text = request.form.get('rules', '') + + with open('./rules.md', 'w+') as f: + f.write(text) + + with open('./rules.md', 'r') as f: + rules = f.read() + + return render_template('admin/rules.html', v=v, rules=rules) + + @app.get("/admin/shadowbanned") @auth_required def shadowbanned(v): diff --git a/files/routes/static.py b/files/routes/static.py index 225965b80..213a9a783 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -3,10 +3,28 @@ from files.__main__ import app, limiter from files.helpers.alerts import * from files.classes.award import AWARDS from sqlalchemy import func +from os import path site = environ.get("DOMAIN").strip() site_name = environ.get("SITE_NAME").strip() + +@app.get('/rules') +@auth_desired +def static_rules(v): + + if not path.exists('./rules.md'): + if v and v.admin_level == 6: + return render_template('norules.html', v=v) + else: + abort(404) + + with open('./rules.md', 'r') as f: + rules = f.read() + + return render_template('rules.html', rules=rules, v=v) + + @app.get("/stats") @auth_desired def participation_stats(v): diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index 502b4ccba..bedb6484a 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -8,24 +8,38 @@ {% block content %}

 

-

 Admin Tools

+

 Admin Tools

{% filter markdown %} -* [Grant User Award](/admin/user_award) -* [Advanced Stats](/admin/user_stat_data) -* [Banned Domains](/admin/banned_domains) -* [Shadowbanned Users](/admin/shadowbanned) -* [Users with Agendaposter Theme](/admin/agendaposters) +#### Content * [Flagged Posts](/admin/flagged/posts) * [Flagged Comments](/admin/flagged/comments) * [Image Posts](/admin/image_posts) * [Removed Posts](/admin/removed) + +#### Users +* [Shadowbanned Users](/admin/shadowbanned) +* [Users with Agendaposter Theme](/admin/agendaposters) * [Users Feed](/admin/users) + +#### Safety +* [Banned Domains](/admin/banned_domains) * [Remove image from imgur and from cloudflare cache](/admin/image_purge) * [Perceptive Hash Image Ban](/admin/image_ban) * [Multi Vote Analysis](/admin/alt_votes) -* [Apps](/admin/apps) + +#### Grant +* [Give User Award](/admin/user_award) * [Badges](/admin/badge_grant) -* [Content Stats](/admin/content_stats) + +#### API Access Control +* [Apps](/admin/apps) + +#### Statistics +* [Content Stats](/stats) +* [Advanced Stats](/admin/user_stat_data) + +#### Configuration +* [Site Rules](/admin/rules) {% endfilter %} diff --git a/files/templates/admin/rules.html b/files/templates/admin/rules.html new file mode 100644 index 000000000..398770e05 --- /dev/null +++ b/files/templates/admin/rules.html @@ -0,0 +1,31 @@ +{% extends "default.html" %} + +{% block pagetitle %}Edit {{'SITE_NAME' | app_config}} rules{% endblock %} + +{% block content %} + +
+
+
+
+

Edit rules

+

Your rules page will be publicly visible at {{'/rules'|full_link}}.

+

Supports markdown syntax.

+
+
+
+
+ + + +
+ +
+
+
+
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/files/templates/header.html b/files/templates/header.html index 9fc072a0c..6955dd13b 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -117,8 +117,8 @@ {% if "rdrama" in request.host %} Rules - {% elif "pcm" in request.host %} - Rules + {% else %} + Rules {% endif %} Changelog @@ -179,8 +179,8 @@ {% if "rdrama" in request.host %} - {% elif "pcm" in request.host %} - + {% else %} + {% endif %} diff --git a/files/templates/norules.html b/files/templates/norules.html new file mode 100644 index 000000000..d0d91e20c --- /dev/null +++ b/files/templates/norules.html @@ -0,0 +1,26 @@ +{% extends "default.html" %} + +{% block title %} +not configured +{% endblock %} + +{% block pagetype %}message{% endblock %} + +{% block customPadding %}{% endblock %} + +{% block content %} +
+
+
+ +
+ +
+ +

You haven't set up your rules page yet

+
Your rules will be publicly available here.
+ Set up rules +
+
+
+{% endblock %} \ No newline at end of file diff --git a/files/templates/rules.html b/files/templates/rules.html new file mode 100644 index 000000000..be4bd3aa8 --- /dev/null +++ b/files/templates/rules.html @@ -0,0 +1,18 @@ +{% extends "default.html" %} + +{% block title %} +{{'SITE_NAME' | app_config}} Rules + +{% endblock %} + +{% block content %} +
+
+
+
+

{{'SITE_NAME'|app_config}} Rules{% if v and v.admin_level == 6 %} Edit rules{% endif %}

+ +
+ {{ rules|markdown }} +
+{% endblock %} \ No newline at end of file From 4fabbc342379ab1175925ffe87c3066f4c38bfa7 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Thu, 9 Sep 2021 13:15:01 +0200 Subject: [PATCH 2/3] dg --- files/routes/posts.py | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/files/routes/posts.py b/files/routes/posts.py index 233f6519f..0ee45c785 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -533,40 +533,40 @@ def filter_title(title): IMGUR_KEY = environ.get("IMGUR_KEY", "").strip() -# def check_processing_thread(v, post, link, db): +def check_processing_thread(v, post, link, db): -# image_id = link.split('/')[-1].rstrip('.mp4') -# headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} + image_id = link.split('/')[-1].rstrip('.mp4') + headers = {"Authorization": f"Client-ID {IMGUR_KEY}"} -# while True: -# # break on error to prevent zombie threads -# try: -# time.sleep(15) + while True: + # 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() -# break -# # just in case -# elif status == 'failed': -# print(f"video upload for post {post.id} failed") -# break -# except Exception as e: -# traceback.print_exc() -# print("retard. aborting thread") -# break + db.commit() + break + # just in case + elif status == 'failed': + print(f"video upload for post {post.id} failed") + break + except Exception as e: + traceback.print_exc() + print("retard. aborting thread") + break @app.post("/submit") From a200e013f779655e8a2c283e30904b030138a416 Mon Sep 17 00:00:00 2001 From: fireworks88 Date: Thu, 9 Sep 2021 14:49:17 +0200 Subject: [PATCH 3/3] dg --- files/templates/rules.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/files/templates/rules.html b/files/templates/rules.html index be4bd3aa8..68b378e80 100644 --- a/files/templates/rules.html +++ b/files/templates/rules.html @@ -10,9 +10,11 @@ -

{{'SITE_NAME'|app_config}} Rules{% if v and v.admin_level == 6 %} Edit rules{% endif %}

+
+
{{'SITE_NAME'|app_config}} Rules{% if v and v.admin_level == 6 %} Edit rules{% endif %}
-
- {{ rules|markdown }} +
+ {{ rules|markdown }} +
{% endblock %} \ No newline at end of file