From 59a475a252b4a1f72fdb4063da9e0a44bc2fadf9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 25 Jul 2023 01:58:43 -0700 Subject: feat(due): make message hideable --- src/due/html.py | 8 +++++++- src/due/routes/index.py | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/due/html.py b/src/due/html.py index d746fef..af22e64 100644 --- a/src/due/html.py +++ b/src/due/html.py @@ -1,6 +1,7 @@ import requests import joblib from due.cache import cache +from flask import request def anime_to_html(releasing_outdated_anime): @@ -134,6 +135,11 @@ def manga_to_html(releasing_outdated_manga): def page(main_content, footer): + message = '
Slow loads? If your media hasn\'t been cached in a while, the first load will take a couple seconds longer than the rest. Subsequent requests on cached media should be faster. Hide forever
' + + if request.cookies.get("hide_message") == "1": + message = "" + return f""" @@ -160,7 +166,7 @@ def page(main_content, footer):

{footer}

-
Slow loads? If your media hasn't been cached in a while, the first load will take a couple seconds longer than the rest. Subsequent requests on cached media should be faster.
+ {message} """ diff --git a/src/due/routes/index.py b/src/due/routes/index.py index 3e3c746..d73bf31 100644 --- a/src/due/routes/index.py +++ b/src/due/routes/index.py @@ -1,7 +1,7 @@ import time from due.html import anime_to_html, manga_to_html, page from due.media import create_collection -from flask import request, Blueprint +from flask import make_response, redirect, request, Blueprint import json import os @@ -10,6 +10,13 @@ bp = Blueprint("index", __name__) @bp.route("/") def home(): + response = make_response("") + + if request.args.get("hide_message") is not None: + if request.cookies.get("hide_message") is None: + response = redirect("/") + response.set_cookie("hide_message", "1") + if request.cookies.get("anilist"): anilist = json.loads(request.cookies.get("anilist")) start = time.time() @@ -49,11 +56,12 @@ def home(): (anime_html, anime_length) = anime_to_html(releasing_outdated_anime) (manga_html, manga_length) = manga_to_html(releasing_outdated_manga) - return page( - f"""Logout from AniList ({name}) + response.set_data( + page( + f"""Logout from AniList ({name})
""", - f"""
+ f"""
Anime [{anime_length}] {round(anime_time, 2)}ms {anime_html}
@@ -65,11 +73,16 @@ def home(): {manga_html}
""", + ) ) else: - return page( - f"""Login with AniList + response.set_data( + page( + f"""Login with AniList
""", - "Please log in to view due media.", + "Please log in to view due media.", + ) ) + + return response -- cgit v1.2.3