From e72e4a28d3c2249687f252ab3ae8b5e474f35dcd Mon Sep 17 00:00:00 2001 From: "hikari.ftg" Date: Thu, 24 Mar 2022 18:47:17 +0000 Subject: [PATCH] Attempt to fix web --- hikka/main.py | 25 ++++++++++++++++++------- web-resources/root.jinja2 | 3 ++- web-resources/static/root.js | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hikka/main.py b/hikka/main.py index b7014d1..d1d607e 100755 --- a/hikka/main.py +++ b/hikka/main.py @@ -145,7 +145,7 @@ def parse_arguments(): parser.add_argument("--no-nickname", "-nn", dest="no_nickname", action="store_true") parser.add_argument("--hosting", "-lh", dest="hosting", action="store_true") parser.add_argument("--web-only", dest="web_only", action="store_true") - parser.add_argument("--no-web", dest="web", action="store_false") + parser.add_argument("--no-web", dest="disable_web", action="store_false") parser.add_argument( "--data-root", dest="data_root", @@ -279,9 +279,7 @@ class Hikka: lambda f: f.startswith("hikka-") and f.endswith(".session"), os.listdir( self.arguments.data_root - or os.path.dirname( - utils.get_base_dir() - ), + or os.path.dirname(utils.get_base_dir()), ), ), ) @@ -289,7 +287,10 @@ class Hikka: phones.update( **( - {phone.split(":", maxsplit=1)[0]: phone for phone in self.arguments.phone} + { + phone.split(":", maxsplit=1)[0]: phone + for phone in self.arguments.phone + } if self.arguments.phone else {} ) @@ -315,7 +316,9 @@ class Hikka: from . import api_token except ImportError: try: - api_token = api_token_type(os.environ["api_id"], os.environ["api_hash"]) + api_token = api_token_type( + os.environ["api_id"], os.environ["api_hash"] + ) except KeyError: api_token = None @@ -423,7 +426,15 @@ class Hikka: connection_retries=None, ) - client.start(phone=raise_auth if web_available else lambda: input("Phone: ")) + client.start( + phone=raise_auth + if self.web + and ( + not hasattr(self.arguments, "web") + or self.arguments.web is not False + ) + else lambda: input("Phone: ") + ) client.phone = phone self.clients.append(client) diff --git a/web-resources/root.jinja2 b/web-resources/root.jinja2 index 8242d62..1ab07c1 100755 --- a/web-resources/root.jinja2 +++ b/web-resources/root.jinja2 @@ -160,7 +160,8 @@ var skip_creds = "{{ skip_creds }}" == "True"; var auth_required = true; fetch("/check_session", { - method: "POST" + method: "POST", + credentials: "include" }) .then(response => response.text()) .then((response) => { diff --git a/web-resources/static/root.js b/web-resources/static/root.js index cedb3d2..d69f81c 100644 --- a/web-resources/static/root.js +++ b/web-resources/static/root.js @@ -13,6 +13,7 @@ function auth(callback) { }); fetch("/web_auth", { method: "POST", + credentials: "include", timeout: 5000 }) .then(response => response.text())