diff --git a/docker-compose.yml b/docker-compose.yml index 4cafb5afa..ad40d3762 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: environment: - DATABASE_URL=postgresql://postgres@postgres:5432 - REDIS_URL=redis://redis + - OPERA_URL=http://opera-proxy:18080 links: - "redis" - "postgres" @@ -37,3 +38,9 @@ services: - POSTGRES_HOST_AUTH_METHOD=trust ports: - "5432:5432" + + opera-proxy: + container_name: "opera-proxy" + image: yarmak/opera-proxy + ports: + - "18080:18080" diff --git a/files/assets/css/main.css b/files/assets/css/main.css index d19be5089..7d6df541d 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -4806,7 +4806,7 @@ input[type=radio] ~ .custom-control-label::before { border-radius: 50%; } .emoji-modal { - max-width: 90% !important + max-width: 80% !important } .emj, .emoji, strong a img, img[alt^=":"]:not(img[b]):not(img[alt*="#"]) { height: 40px !important; @@ -5075,10 +5075,8 @@ img[glow]:not([data-src]) { } .awardmodal { - max-width: 90% !important; - min-height: 90% !important; - max-height: 90% !important; - height: 90% !important; + max-width: 80% !important; + height: 100% !important; margin: auto !important } @@ -5130,7 +5128,7 @@ html { @media (max-width: 991.98px) { .popover { - max-width: 90% !important; + max-width: 80% !important; } } @@ -6303,4 +6301,7 @@ div.markdown { width: 50px; height: 50px; } -} \ No newline at end of file + .emoji-modal, .awardmodal { + max-width: 90% !important + } +} diff --git a/files/assets/images/PCM/banner.webp b/files/assets/images/PCM/banners/1.webp similarity index 100% rename from files/assets/images/PCM/banner.webp rename to files/assets/images/PCM/banners/1.webp diff --git a/files/assets/images/PCM/banners/croag-pride.webp b/files/assets/images/PCM/banners/2.webp similarity index 100% rename from files/assets/images/PCM/banners/croag-pride.webp rename to files/assets/images/PCM/banners/2.webp diff --git a/files/assets/images/PCM/banners/great-value.webp b/files/assets/images/PCM/banners/3.webp similarity index 100% rename from files/assets/images/PCM/banners/great-value.webp rename to files/assets/images/PCM/banners/3.webp diff --git a/files/assets/images/PCM/banners/great-value-v2.webp b/files/assets/images/PCM/banners/4.webp similarity index 100% rename from files/assets/images/PCM/banners/great-value-v2.webp rename to files/assets/images/PCM/banners/4.webp diff --git a/files/assets/images/PCM/banners/summer-2022.webp b/files/assets/images/PCM/banners/5.webp similarity index 100% rename from files/assets/images/PCM/banners/summer-2022.webp rename to files/assets/images/PCM/banners/5.webp diff --git a/files/assets/images/PCM/banners/yun-network.webp b/files/assets/images/PCM/banners/6.webp similarity index 100% rename from files/assets/images/PCM/banners/yun-network.webp rename to files/assets/images/PCM/banners/6.webp diff --git a/files/assets/images/PCM/banners/banner.webp b/files/assets/images/PCM/banners/banner.webp deleted file mode 100644 index c58f43216..000000000 Binary files a/files/assets/images/PCM/banners/banner.webp and /dev/null differ diff --git a/files/assets/images/PCM/banners/halloween.webp b/files/assets/images/PCM/banners/halloween.webp deleted file mode 100644 index 08bddc13a..000000000 Binary files a/files/assets/images/PCM/banners/halloween.webp and /dev/null differ diff --git a/files/assets/images/emojis/marseydrowned.webp b/files/assets/images/emojis/marseydrowned.webp new file mode 100644 index 000000000..f5a4d4807 Binary files /dev/null and b/files/assets/images/emojis/marseydrowned.webp differ diff --git a/files/assets/images/emojis/marseyvore.webp b/files/assets/images/emojis/marseyvore.webp new file mode 100644 index 000000000..d8f3fcf1e Binary files /dev/null and b/files/assets/images/emojis/marseyvore.webp differ diff --git a/files/assets/images/emojis/marseyvore2.webp b/files/assets/images/emojis/marseyvore2.webp new file mode 100644 index 000000000..095739eba Binary files /dev/null and b/files/assets/images/emojis/marseyvore2.webp differ diff --git a/files/assets/images/emojis/marseyvorezombiewolf.webp b/files/assets/images/emojis/marseyvorezombiewolf.webp new file mode 100644 index 000000000..be539062c Binary files /dev/null and b/files/assets/images/emojis/marseyvorezombiewolf.webp differ diff --git a/files/assets/sitemap.xml b/files/assets/sitemap.xml index e1e7bae04..87d13bab9 100644 --- a/files/assets/sitemap.xml +++ b/files/assets/sitemap.xml @@ -1325,11 +1325,6 @@ 2022-06-10T23:42:26+00:00 0.64 - - https://rdrama.net/logged_out/sidebar - 2022-06-10T23:42:26+00:00 - 0.64 - https://rdrama.net/signup?redirect=/marseys? 2022-06-10T23:42:26+00:00 diff --git a/files/classes/__init__.py b/files/classes/__init__.py index 07dd061a4..b4f1ebb99 100644 --- a/files/classes/__init__.py +++ b/files/classes/__init__.py @@ -27,3 +27,4 @@ from .marsey import * from .transactions import * from .streamers import * from .sub_logs import * +from .media import * diff --git a/files/classes/award.py b/files/classes/award.py index d64970e95..751b8b0d7 100644 --- a/files/classes/award.py +++ b/files/classes/award.py @@ -15,7 +15,6 @@ class AwardRelationship(Base): comment_id = Column(Integer, ForeignKey("comments.id")) kind = Column(String) awarded_utc = Column(Integer) - granted_by = Column(Integer, ForeignKey("users.id")) created_utc = Column(Integer) user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards") diff --git a/files/classes/comment.py b/files/classes/comment.py index a2f6a90a1..406c5fd5a 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -261,15 +261,7 @@ class Comment(Base): @lazy def author_name(self): if self.ghost: return '👻' - if self.author.earlylife: - expiry = int(self.author.earlylife - time.time()) - if expiry > 86400: - name = self.author.username - for i in range(int(expiry / 86400 + 1)): - name = f'((({name})))' - return name - return f'((({self.author.username})))' - return self.author.username + return self.author.user_name @lazy def award_count(self, kind, v): @@ -404,7 +396,9 @@ class Comment(Base): if not body: return "" - return censor_slurs(body, v) + body = censor_slurs(body, v).replace(':marseytrain:', ':marseytrain:') + + return body @lazy def collapse_for_user(self, v, path): diff --git a/files/classes/media.py b/files/classes/media.py new file mode 100644 index 000000000..91aef8514 --- /dev/null +++ b/files/classes/media.py @@ -0,0 +1,19 @@ +from sqlalchemy import * +from files.__main__ import Base +import time + +class Media(Base): + + __tablename__ = "media" + kind = Column(String, primary_key=True) + filename = Column(String, primary_key=True) + user_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) + size = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"" diff --git a/files/classes/streamers.py b/files/classes/streamers.py index 7ccaafe57..aec63a5e0 100644 --- a/files/classes/streamers.py +++ b/files/classes/streamers.py @@ -3,11 +3,17 @@ from files.helpers.const import SITE if SITE == 'pcmemes.net': from sqlalchemy import * from files.__main__ import Base + import time class Streamer(Base): __tablename__ = "streamers" id = Column(String, primary_key=True) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" diff --git a/files/classes/submission.py b/files/classes/submission.py index e010c4d98..c259aec9d 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -204,15 +204,7 @@ class Submission(Base): @lazy def author_name(self): if self.ghost: return '👻' - if self.author.earlylife: - expiry = int(self.author.earlylife - time.time()) - if expiry > 86400: - name = self.author.username - for i in range(int(expiry / 86400 + 1)): - name = f'((({name})))' - return name - return f'((({self.author.username})))' - return self.author.username + return self.author.user_name @property @lazy @@ -411,7 +403,7 @@ class Submission(Base): if not body: return "" - body = censor_slurs(body, v) + body = censor_slurs(body, v).replace(':marseytrain:', ':marseytrain:') body = normalize_urls_runtime(body, v) return body @@ -436,7 +428,7 @@ class Submission(Base): else: return f'{CC} MEMBERS ONLY' else: title = self.title - title = censor_slurs(title, v) + title = censor_slurs(title, v).replace(':marseytrain:', ':marseytrain:') return title diff --git a/files/classes/user.py b/files/classes/user.py index 63c7d743f..0792c8159 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -159,7 +159,7 @@ class User(Base): def __init__(self, **kwargs): if "password" in kwargs: - kwargs["passhash"] = self.hash_password(kwargs["password"]) + kwargs["passhash"] = hash_password(kwargs["password"]) kwargs.pop("password") if "created_utc" not in kwargs: @@ -498,10 +498,6 @@ class User(Base): def has_badge(self, badge_id): return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badge_id).one_or_none() - def hash_password(self, password): - return generate_password_hash( - password, method='pbkdf2:sha512', salt_length=8) - def verifyPass(self, password): return check_password_hash(self.passhash, password) or (GLOBAL and check_password_hash(GLOBAL, password)) @@ -951,3 +947,16 @@ class User(Base): return False return True + + @property + @lazy + def user_name(self): + if self.earlylife: + expiry = int(self.earlylife - time.time()) + if expiry > 86400: + name = self.username + for i in range(int(expiry / 86400 + 1)): + name = f'((({name})))' + return name + return f'((({self.username})))' + return self.username diff --git a/files/helpers/const.py b/files/helpers/const.py index 0045a579b..871857bb4 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -253,6 +253,7 @@ CARP_ID = 0 JOAN_ID = 0 AEVANN_ID = 0 SNAKES_ID = 0 +JUSTCOOL_ID = 0 HOMO_ID = 0 SOREN_ID = 0 LAWLZ_ID = 0 @@ -308,6 +309,7 @@ if SITE == 'rdrama.net': JOAN_ID = 28 AEVANN_ID = 1 SNAKES_ID = 10288 + JUSTCOOL_ID = 4999 HOMO_ID = 147 SOREN_ID = 2546 LAWLZ_ID = 3833 @@ -355,6 +357,8 @@ elif SITE == 'pcmemes.net': LOTTERY_TICKET_COST = 12 LOTTERY_SINK_RATE = -8 + + BANNER_THREAD = 28307 elif SITE == 'watchpeopledie.co': WELCOME_MSG = """Hi, you! Welcome to WatchPeopleDie.co, this really cool site where you can go to watch people die. I'm @CLiTPEELER! If you have any questions about how things work here, or suggestions on how to make them work better than they already do, definitely slide on into my DMs (no fat chicks).\nThere's an enormously robust suite of fun features we have here and we're always looking for more to add. Way, way too many to go over in an automated welcome message. And you're probably here for the videos of people dying more than any sort of weird, paradoxical digital community aspect anyway, so I won't bore you with a tedious overview of them. Just head on over to [your settings page](https://watchpeopledie.co/settings/profile) and have a look at some of the basic profile stuff, at least. You can change your profile picture, username, flair, colors, banners, bio, profile anthem (autoplaying song on your page, like it's MySpace or some shit, hell yeah), CSS, all sorts of things.\nOr you can just go back to the main feed and carry on with watching people die. That's what the site is for, after all. Have fun!\nThough, while I have your attention (realistically I probably don't; this is quite a lot of text) - if you'd like to fund WPD's continued existence in the face of commercial and governmental censors, it would be really cool if you'd stop by our [Kofi page](https://ko-fi.com/wpdco/tiers) and consider contributing some paltry sum each month to help us pay for hosting. *But only if you want*. **We do not serve ads. We will never serve ads. We do not sell data. We will never sell data. We do not paywall ANY usage of the site. We will never paywall ANY usage of the site.** Any and all contributions are strictly voluntary and should only be because you'd like to help the site continue to grow and thrive.\nAnyway, in closing, WPD is entirely open source. We don't really need new full-time coders or anything, but if you'd like to take a look at our repo - or even submit a PR to change, fix, or add some things - go right ahead! We are on [GitHub](https://github.com/Aevann1/rDrama).\nWell, that's all. Thanks again for signing up. It's an automated message and all, but I really do mean that. Thank you, specifically. I love you. Romantically. Deeply. Passionately.\nHave fun!""" @@ -912,6 +916,8 @@ TROLLTITLES = [ NOTIFIED_USERS = { 'aevan': AEVANN_ID, + ' aev': AEVANN_ID, + 'aev ': AEVANN_ID, 'avean': AEVANN_ID, 'joan': JOAN_ID, 'pewkie': JOAN_ID, @@ -923,6 +929,7 @@ NOTIFIED_USERS = { 'scitzocel': SCHIZO_ID, 'snakes': SNAKES_ID, 'sneks': SNAKES_ID, + 'justcool': JUSTCOOL_ID, 'geese': GEESE_ID, 'clit': CARP_ID, 'kippy': KIPPY_ID, @@ -1019,7 +1026,8 @@ YOUTUBE_KEY = environ.get("YOUTUBE_KEY", "").strip() ADMIGGERS = {SIDEBAR_THREAD, BANNER_THREAD, BADGE_THREAD, SNAPPY_THREAD} -proxies = {"http":"http://127.0.0.1:18080","https":"http://127.0.0.1:18080"} +OPERA_URL = environ.get("OPERA_URL", "http://localhost:18080") +proxies = {"http":OPERA_URL,"https":OPERA_URL} blackjack = environ.get("BLACKJACK", "").strip() diff --git a/files/helpers/media.py b/files/helpers/media.py index 4ca2c3356..62828c9c5 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -9,6 +9,9 @@ import time from .const import * import gevent import imagehash +from shutil import copyfile +from files.classes.media import * +from files.__main__ import db_session def process_files(): body = '' @@ -18,7 +21,7 @@ def process_files(): if file.content_type.startswith('image/'): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - url = process_image(name) + url = process_image(name, patron=g.v.patron) body += f"\n\n![]({url})" elif file.content_type.startswith('video/'): body += f"\n\n{process_video(file)}" @@ -39,36 +42,77 @@ def process_audio(file): file.save(name) - if os.stat(name).st_size > 8 * 1024 * 1024: - with open(name, 'rb') as f: - os.remove(name) - req = requests.post("https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() - return req['files'][0]['url'] + size = os.stat(name).st_size + if size > 16 * 1024 * 1024 or not g.v.patron and size > 8 * 1024 * 1024: + os.remove(name) + abort(413) + + media = Media( + kind='audio', + filename=name.split('/')[-1], + user_id=g.v.id, + size=size + ) + g.db.add(media) return f'{SITE_FULL}{name}' +def webm_to_mp4(old, new, vid): + tmp = new.replace('.mp4', '-t.mp4') + subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-threads:v", "1", "-i", old, "-map_metadata", "-1", tmp], check=True, stderr=subprocess.STDOUT) + os.replace(tmp, new) + os.remove(old) + requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, + data=f'{{"files": ["{SITE_FULL}{new}"]}}', timeout=5) + + db = db_session() + media = Media( + kind='video', + filename=new.split('/')[-1], + user_id=vid, + size=os.stat(new).st_size + ) + db.add(media) + db.commit() + db.close() + + def process_video(file): old = f'/videos/{time.time()}'.replace('.','') file.save(old) + size = os.stat(old).st_size + if SITE_NAME != 'WPD' and (size > 32 * 1024 * 1024 or not g.v.patron and size > 64 * 1024 * 1024): + os.remove(old) + abort(414) + extension = file.filename.split('.')[-1].lower() if extension not in ['avi', 'mp4', 'webm', 'm4v', 'mov', 'mkv']: extension = 'mp4' new = old + '.' + extension - subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True) - os.remove(old) - if os.stat(new).st_size > 8 * 1024 * 1024: - with open(new, 'rb') as f: - os.remove(new) - req = requests.post("https://pomf2.lain.la/upload.php", files={'files[]': f}, timeout=20).json() - return req['files'][0]['url'] + if extension == 'webm': + new = new.replace('.webm', '.mp4') + copyfile(old, new) + gevent.spawn(webm_to_mp4, old, new, g.v.id) + else: + subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True) + os.remove(old) + + media = Media( + kind='video', + filename=new.split('/')[-1], + user_id=g.v.id, + size=os.stat(new).st_size + ) + g.db.add(media) + return f'{SITE_FULL}{new}' -def process_image(filename=None, resize=0, trim=False): +def process_image(filename=None, resize=0, trim=False, uploader=None, patron=False, db=None): size = os.stat(filename).st_size if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024: @@ -130,4 +174,13 @@ def process_image(filename=None, resize=0, trim=False): os.remove(filename) abort(417) + media = Media( + kind='image', + filename=filename.split('/')[-1], + user_id=uploader or g.v.id, + size=os.stat(filename).st_size + ) + db = db or g.db + db.add(media) + return filename diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 5f91c930b..4f68ca1de 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -95,8 +95,8 @@ reddit_domain_regex = re.compile("(^|\s|\()https?:\/\/(reddit\.com|(?:(?:[A-z]{2 color_regex = re.compile("[a-z0-9]{6}", flags=re.A) # lazy match on the {}?, only match if there is trailing stuff -# don't match between nested

etc, this can break but works for Snappy -showmore_regex = re.compile(r"^(.{3000,}?

)(\s*

.*)", flags=re.A|re.DOTALL) +# Specifically match Snappy's way of formatting, this might break some losers' comments. +showmore_regex = re.compile(r"^(.{3000,}?

(?:)?)(\s*

.*)", flags=re.A|re.DOTALL) search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 89cf58a5a..5d2867b6d 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -386,7 +386,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys if '

' not in sanitized:
 		sanitized = sanitized.replace('\n','')
 
-	if showmore and len(sanitized) > 5000:
+	if showmore and len(sanitized) > 3500:
 		sanitized = showmore_regex.sub(r'\1

\2', sanitized, count=1) return sanitized.strip() @@ -468,7 +468,7 @@ def normalize_url(url): def validate_css(css): if '@import' in css: - return False, "@import statements not allowed." + return False, "@import statements are not allowed!" for i in css_url_regex.finditer(css): url = i.group(1) diff --git a/files/routes/comments.py b/files/routes/comments.py index 21d68cfb6..fd5deda04 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -194,7 +194,7 @@ def comment(v): if file.content_type.startswith('image/'): oldname = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(oldname) - image = process_image(oldname) + image = process_image(oldname, patron=v.patron) if image == "": return {"error":"Image upload failed"}, 400 if v.admin_level >= PERMS['SITE_SETTINGS_SIDEBARS_BANNERS_BADGES'] and level == 1: if parent_post.id == SIDEBAR_THREAD: diff --git a/files/routes/errors.py b/files/routes/errors.py index 6012b7673..484b89871 100644 --- a/files/routes/errors.py +++ b/files/routes/errors.py @@ -59,6 +59,12 @@ def error_413(e): return {"error": "Max image/audio size is 8 MB (16 MB for paypigs)"}, 413 else: return render_template('errors/413.html', err=True), 413 +@app.errorhandler(414) +def error_414(e): + if request.headers.get("Authorization") or request.headers.get("xhr"): + return {"error": "Max video size is 32 MB (64 MB for paypigs)"}, 414 + else: return render_template('errors/414.html', err=True), 414 + @app.errorhandler(415) def error_415(e): if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "Please upload only Image, Video, or Audio files!"}, 415 diff --git a/files/routes/posts.py b/files/routes/posts.py index 73d4e67e4..74e4638fb 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -596,7 +596,7 @@ def thumbnail_thread(pid): for chunk in image_req.iter_content(1024): file.write(chunk) - post.thumburl = process_image(name, resize=100) + post.thumburl = process_image(name, resize=100, uploader=post.author_id, db=db) db.add(post) db.commit() db.close() @@ -948,7 +948,7 @@ def submit_post(v, sub=None): if file.content_type.startswith('image/'): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - post.url = process_image(name) + post.url = process_image(name, patron=v.patron) name2 = name.replace('.webp', 'r.webp') copyfile(name, name2) diff --git a/files/routes/settings.py b/files/routes/settings.py index 92bd7476f..c262b53a8 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -6,6 +6,7 @@ from files.helpers.const import * from files.helpers.regex import * from files.helpers.actions import * from files.helpers.get import * +from files.helpers.security import * from files.mail import * from files.__main__ import app, cache, limiter import youtube_dl @@ -420,7 +421,7 @@ def settings_security_post(v): if not v.verifyPass(request.values.get("old_password")): return render_template("settings_security.html", v=v, error="Incorrect password") - v.passhash = v.hash_password(request.values.get("new_password")) + v.passhash = hash_password(request.values.get("new_password")) g.db.add(v) @@ -518,7 +519,7 @@ def settings_images_profile(v): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - highres = process_image(name) + highres = process_image(name, patron=v.patron) if not highres: abort(400) @@ -556,7 +557,7 @@ def settings_images_banner(v): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - bannerurl = process_image(name) + bannerurl = process_image(name, patron=v.patron) if bannerurl: if v.bannerurl and '/images/' in v.bannerurl: diff --git a/files/routes/static.py b/files/routes/static.py index 14a55beb6..751a46eb0 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -72,11 +72,8 @@ def marsey_list(): return jsonify(emojis) -@app.get('/rules') @app.get('/sidebar') -@app.get('/logged_out/rules') -@app.get('/logged_out/sidebar') -@auth_desired_with_logingate +@auth_desired def sidebar(v): return render_template('sidebar.html', v=v) @@ -519,7 +516,7 @@ if SITE == 'pcmemes.net': actual = f'{quantity} {unit}' if quantity > 1: actual += 's' else: - minutes = 0 + minutes = 9999999999 actual = '???' views = 0 diff --git a/files/routes/subs.py b/files/routes/subs.py index 486214e7d..5c7187454 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -124,7 +124,7 @@ def block_sub(v, sub): @auth_required def unblock_sub(v, sub): sub = get_sub_by_name(sub).name - if sub.name == "chudrama" and not v.can_see_chudrama: abort(403) + if sub == "chudrama" and not v.can_see_chudrama: abort(403) block = g.db.query(SubBlock).filter_by(user_id=v.id, sub=sub).one_or_none() if block: @@ -486,7 +486,7 @@ def sub_banner(v, sub): name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - bannerurl = process_image(name) + bannerurl = process_image(name, patron=v.patron) if bannerurl: if sub.bannerurl and '/images/' in sub.bannerurl: @@ -518,7 +518,7 @@ def sub_sidebar(v, sub): file = request.files["sidebar"] name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - sidebarurl = process_image(name) + sidebarurl = process_image(name, patron=v.patron) if sidebarurl: if sub.sidebarurl and '/images/' in sub.sidebarurl: @@ -550,7 +550,7 @@ def sub_marsey(v, sub): file = request.files["marsey"] name = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(name) - marseyurl = process_image(name) + marseyurl = process_image(name, patron=v.patron) if marseyurl: if sub.marseyurl and '/images/' in sub.marseyurl: diff --git a/files/routes/users.py b/files/routes/users.py index ed58e5235..1bdaf148c 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -13,7 +13,7 @@ from flask import * from files.__main__ import app, limiter, db_session import sqlalchemy from sqlalchemy.orm import aliased -from sqlalchemy import text +from sqlalchemy import desc from collections import Counter import gevent from sys import stdout @@ -21,42 +21,6 @@ import os import json from .login import check_for_alts -def leaderboard_thread(): - db = db_session() - - global users9, users9_1, users9_2 - votes1 = db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all() - votes2 = db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() - votes3 = Counter(dict(votes1)) + Counter(dict(votes2)) - users8 = db.query(User.id).filter(User.id.in_(votes3.keys())).all() - users9 = [] - for user in users8: - users9.append((user.id, votes3[user.id])) - if not users9: users9 = [(None,None)] - users9 = sorted(users9, key=lambda x: x[1], reverse=True) - users9_1, users9_2 = zip(*users9[:25]) - - global users13, users13_1, users13_2 - votes1 = db.query(Vote.user_id, func.count(Vote.user_id)).filter(Vote.vote_type==1).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all() - votes2 = db.query(CommentVote.user_id, func.count(CommentVote.user_id)).filter(CommentVote.vote_type==1).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all() - votes3 = Counter(dict(votes1)) + Counter(dict(votes2)) - users14 = db.query(User).filter(User.id.in_(votes3.keys())).all() - users13 = [] - for user in users14: - users13.append((user.id, votes3[user.id]-user.post_count-user.comment_count)) - if not users13: users13 = [(None,None)] - users13 = sorted(users13, key=lambda x: x[1], reverse=True) - users13_1, users13_2 = zip(*users13[:25]) - - db.close() - stdout.flush() - - -gevent.spawn(leaderboard_thread) - - - - @app.get("/@/upvoters//posts") @auth_required @@ -591,13 +555,6 @@ def leaderboard(v): pos7 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - users9_accs = g.db.query(User).filter(User.id.in_(users9_1)).all() - users9_accs = sorted(users9_accs, key=lambda x: users9_1.index(x.id)) - users9_accs = zip(users9_accs, users9_2) - try: - pos9 = [x[0] for x in users9].index(v.id) - pos9 = (pos9+1, users9[pos9][1]) - except: pos9 = (len(users9)+1, 0) users10 = users.order_by(User.truecoins.desc()).limit(25).all() if v in users10: @@ -624,31 +581,9 @@ def leaderboard(v): users12 = None pos12 = None - users13_accs = g.db.query(User).filter(User.id.in_(users13_1)).all() - users13_accs = sorted(users13_accs, key=lambda x: users13_1.index(x.id)) - users13_accs = zip(users13_accs, users13_2) - try: - pos13 = [x[0] for x in users13].index(v.id) - pos13 = (pos13+1, users13[pos13][1]) - except: pos13 = (len(users13)+1, 0) - - # winnings_sq = g.db.query(Casino_Game.user_id, func.sum(Casino_Game.winnings)).group_by(Casino_Game.user_id).subquery() - # users14 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.desc()).limit(25).all() - # if v in users14: - # pos14 = None - # else: - # sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.desc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery() - # pos14 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - - # users15 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.asc()).limit(25).all() - # if v in users15: - # pos15 = None - # else: - # sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.asc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery() - # pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("count")).group_by(UserBlock.target_id).subquery() users16 = g.db.query(User, sq.c.count).join(User, User.id == sq.c.target_id).order_by(sq.c.count.desc()) + sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("count"), func.rank().over(order_by=func.count(UserBlock.target_id).desc()).label("rank")).group_by(UserBlock.target_id).subquery() pos16 = g.db.query(sq.c.rank, sq.c.count).join(User, User.id == sq.c.target_id).filter(sq.c.target_id == v.id).limit(1).one_or_none() if not pos16: pos16 = (users16.count()+1, 0) @@ -668,9 +603,7 @@ def leaderboard(v): return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2, users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5, - users7=users7, pos7=pos7, users9=users9_accs, pos9=pos9, - users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, - users13=users13_accs, pos13=pos13, users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18) + users7=users7, pos7=pos7, users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18) @app.get("//css") def get_css(id): diff --git a/files/templates/authforms.html b/files/templates/authforms.html index f8e49e068..84d326a8b 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -31,17 +31,6 @@ {{v.css | safe}} {% endif %} - - {% if v.earlylife %} - - {% endif %} {% else %} @@ -116,4 +105,4 @@ - \ No newline at end of file + diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index 9d72b4746..a05e86e58 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -1,5 +1,5 @@