From 140083b9c8464a7d5454aa3725e16c9d1ed1d654 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sat, 17 Nov 2018 20:33:39 +0000 Subject: [PATCH] Check for is peak before connecting to gateway --- webapp/titanembeds/blueprints/embed/embed.py | 9 +++++++-- webapp/titanembeds/static/js/embed.js | 7 +++++-- webapp/titanembeds/templates/embed.html.j2 | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/webapp/titanembeds/blueprints/embed/embed.py b/webapp/titanembeds/blueprints/embed/embed.py index 870f921..02258b7 100644 --- a/webapp/titanembeds/blueprints/embed/embed.py +++ b/webapp/titanembeds/blueprints/embed/embed.py @@ -1,6 +1,6 @@ from flask import Blueprint, render_template, abort, redirect, url_for, session, request from flask_babel import gettext -from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, guild_accepts_visitors, guild_unauthcaptcha_enabled, is_int, redisqueue +from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, guild_accepts_visitors, guild_unauthcaptcha_enabled, is_int, redisqueue, get_online_embed_user_keys from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url from titanembeds.database import db, Guilds, UserCSS, list_disabled_guilds from config import config @@ -60,6 +60,10 @@ def parse_url_domain(url): if parsed.netloc != "": return parsed.netloc return url + +def is_peak(guild_id): + usrs = get_online_embed_user_keys(guild_id) + return (len(usrs["AuthenticatedUsers"]) + len(usrs["UnauthenticatedUsers"])) > 10 @embed.route("/") def guild_embed(guild_id): @@ -93,7 +97,8 @@ def guild_embed(guild_id): cssvariables=parse_css_variable(customcss), same_target=request.args.get("sametarget", False) == "true", userscalable=request.args.get("userscalable", "True").lower().startswith("t"), - fixed_sidenav=request.args.get("fixedsidenav", "False").lower().startswith("t") + fixed_sidenav=request.args.get("fixedsidenav", "False").lower().startswith("t"), + is_peak=is_peak(guild_id) ) abort(404) diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 68c5ca5..07a8917 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -20,6 +20,7 @@ /* global wdtEmojiBundle */ /* global EmojiConvertor */ /* global post_timeout */ +/* global is_peak */ (function () { const theme_options = ["DiscordDark", "FireWyvern", "IceWyvern", "MetroEdge", "BetterTitan"]; // All the avaliable theming names @@ -249,11 +250,13 @@ } // is not in iframe - if (!inIframe() || isSameDomain()) { + if ((!inIframe() || isSameDomain()) && !is_peak) { shouldUtilizeGateway = true; } else { $(document).on("click focus", enableGateway); - $("main").on("mousewheel", enableGateway); + if (!is_peak) { + $("main").on("mousewheel", enableGateway); + } } $('select').material_select(); diff --git a/webapp/titanembeds/templates/embed.html.j2 b/webapp/titanembeds/templates/embed.html.j2 index 5be9b0a..7b2b05f 100644 --- a/webapp/titanembeds/templates/embed.html.j2 +++ b/webapp/titanembeds/templates/embed.html.j2 @@ -525,6 +525,7 @@ const post_timeout = {{ guild["post_timeout"]|tojson|safe }}; const visitors_enabled = {% if visitors_enabled %}true{% else %}false{% endif %}; const unauth_captcha_enabled = {% if unauth_captcha_enabled %}true{% else %}false{% endif %}; + const is_peak = {{ is_peak|tojson|safe }};