From 5850bb26fa51a5a088f32569d409b5dc44a05a11 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 5 Dec 2022 00:02:29 +0000 Subject: [PATCH] add custom backgrounds paypig feature to compensate for profile views (#44) Co-authored-by: Aevann1 Reviewed-on: https://fsdfsd.net/rDrama/rDrama/pulls/44 Co-authored-by: Aevann Co-committed-by: Aevann --- files/assets/css/main.css | 1 + files/routes/settings.py | 30 ++++++++++++++++++++++- files/templates/settings/common.html | 2 +- files/templates/settings/personal.html | 19 ++++++++++++-- files/templates/util/html_head.html | 6 ++--- migrations/20221204-custom-background.sql | 2 ++ 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 migrations/20221204-custom-background.sql diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 3a039d56e..5a5ecb02f 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -6074,6 +6074,7 @@ g { .fa-coffin-cross:before{content:"\e051"} .fa-face-sleeping:before{content:"\e38d"} .fa-block-question:before{content:"\e3dd"} +.fa-image-slash:before{content:"\e1b7"} .pronouns { font-size: 9px; diff --git a/files/routes/settings.py b/files/routes/settings.py index 8cfaf6ce3..d491645f7 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -40,11 +40,39 @@ def settings_personal(v:User): @ratelimit_user() def remove_background(v): if v.background: + if v.background.startswith('/images/'): + fpath = '/images/' + v.background.split('/images/')[1] + if path.isfile(fpath): os.remove(fpath) v.background = None if v.theme == 'transparent': v.theme = 'midnight' g.db.add(v) return {"message": "Background removed!"} +@app.post('/settings/custom_background') +@limiter.limit(DEFAULT_RATELIMIT_SLOWER) +@auth_required +@ratelimit_user() +def upload_custom_background(v): + if g.is_tor: abort(403, "Image uploads are not allowed through TOR.") + + if not v.patron: + abort(403, f"This feature is only available to {patron}s!") + + file = request.files["file"] + + name = f'/images/{time.time()}'.replace('.','') + '.webp' + file.save(name) + background = process_image(name, v) + + if background: + if v.background and v.background.startswith('/images/'): + fpath = '/images/' + v.background.split('/images/')[1] + if path.isfile(fpath): os.remove(fpath) + v.background = background + g.db.add(v) + + return redirect('/settings/personal') + @app.post("/settings/personal") @limiter.limit(DEFAULT_RATELIMIT_SLOWER) @auth_required @@ -92,7 +120,7 @@ def settings_personal_post(v): background = request.values.get("background", v.background) if background != v.background and background.endswith(".webp") and len(background) <= 20: - v.background = request.values.get("background").replace('.webp', '') + v.background = '/i/backgrounds/' + request.values.get("background") updated = True elif request.values.get("reddit", v.reddit) != v.reddit: reddit = request.values.get("reddit") diff --git a/files/templates/settings/common.html b/files/templates/settings/common.html index f58a1fd61..75b3fb54c 100644 --- a/files/templates/settings/common.html +++ b/files/templates/settings/common.html @@ -85,7 +85,7 @@     - {% if show_file_upload and request.headers.get('cf-ipcountry') != "T1" %} + {% if show_file_upload %}