Check for is peak before connecting to gateway

This commit is contained in:
Jeremy Zhang 2018-11-17 20:33:39 +00:00
parent a9d41cdb28
commit 140083b9c8
3 changed files with 13 additions and 4 deletions

View File

@ -1,6 +1,6 @@
from flask import Blueprint, render_template, abort, redirect, url_for, session, request from flask import Blueprint, render_template, abort, redirect, url_for, session, request
from flask_babel import gettext 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.oauth import generate_guild_icon_url, generate_avatar_url
from titanembeds.database import db, Guilds, UserCSS, list_disabled_guilds from titanembeds.database import db, Guilds, UserCSS, list_disabled_guilds
from config import config from config import config
@ -61,6 +61,10 @@ def parse_url_domain(url):
return parsed.netloc return parsed.netloc
return url 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("/<int:guild_id>") @embed.route("/<int:guild_id>")
def guild_embed(guild_id): def guild_embed(guild_id):
if check_guild_existance(guild_id): if check_guild_existance(guild_id):
@ -93,7 +97,8 @@ def guild_embed(guild_id):
cssvariables=parse_css_variable(customcss), cssvariables=parse_css_variable(customcss),
same_target=request.args.get("sametarget", False) == "true", same_target=request.args.get("sametarget", False) == "true",
userscalable=request.args.get("userscalable", "True").lower().startswith("t"), 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) abort(404)

View File

@ -20,6 +20,7 @@
/* global wdtEmojiBundle */ /* global wdtEmojiBundle */
/* global EmojiConvertor */ /* global EmojiConvertor */
/* global post_timeout */ /* global post_timeout */
/* global is_peak */
(function () { (function () {
const theme_options = ["DiscordDark", "FireWyvern", "IceWyvern", "MetroEdge", "BetterTitan"]; // All the avaliable theming names const theme_options = ["DiscordDark", "FireWyvern", "IceWyvern", "MetroEdge", "BetterTitan"]; // All the avaliable theming names
@ -249,11 +250,13 @@
} }
// is not in iframe // is not in iframe
if (!inIframe() || isSameDomain()) { if ((!inIframe() || isSameDomain()) && !is_peak) {
shouldUtilizeGateway = true; shouldUtilizeGateway = true;
} else { } else {
$(document).on("click focus", enableGateway); $(document).on("click focus", enableGateway);
$("main").on("mousewheel", enableGateway); if (!is_peak) {
$("main").on("mousewheel", enableGateway);
}
} }
$('select').material_select(); $('select').material_select();

View File

@ -525,6 +525,7 @@
const post_timeout = {{ guild["post_timeout"]|tojson|safe }}; const post_timeout = {{ guild["post_timeout"]|tojson|safe }};
const visitors_enabled = {% if visitors_enabled %}true{% else %}false{% endif %}; const visitors_enabled = {% if visitors_enabled %}true{% else %}false{% endif %};
const unauth_captcha_enabled = {% if unauth_captcha_enabled %}true{% else %}false{% endif %}; const unauth_captcha_enabled = {% if unauth_captcha_enabled %}true{% else %}false{% endif %};
const is_peak = {{ is_peak|tojson|safe }};
</script> </script>
<script type="text/javascript" src="{{ url_for('static', filename='js/embed.js') }}"></script> <script type="text/javascript" src="{{ url_for('static', filename='js/embed.js') }}"></script>