aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-07-25 01:58:43 -0700
committerFuwn <[email protected]>2023-07-25 01:58:43 -0700
commit59a475a252b4a1f72fdb4063da9e0a44bc2fadf9 (patch)
treeb137dee057508f3145fcd270e407e2ecef76ca0e /src
parentfeat(html): close manga by default (diff)
downloadold.due.moe-59a475a252b4a1f72fdb4063da9e0a44bc2fadf9.tar.xz
old.due.moe-59a475a252b4a1f72fdb4063da9e0a44bc2fadf9.zip
feat(due): make message hideable
Diffstat (limited to 'src')
-rw-r--r--src/due/html.py8
-rw-r--r--src/due/routes/index.py27
2 files changed, 27 insertions, 8 deletions
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 = '<blockquote>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. <a href="/?hide_message">Hide <i>forever</i></a></blockquote>'
+
+ if request.cookies.get("hide_message") == "1":
+ message = ""
+
return f"""
<!DOCTYPE html>
<html>
@@ -160,7 +166,7 @@ def page(main_content, footer):
<p>{footer}</p>
- <blockquote>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.</blockquote>
+ {message}
</body>
</html>
"""
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"""<a href="/auth/logout">Logout from AniList ({name})</a>
+ response.set_data(
+ page(
+ f"""<a href="/auth/logout">Logout from AniList ({name})</a>
<br>""",
- f"""<details open>
+ f"""<details open>
<summary>Anime [{anime_length}] <small style="opacity: 50%">{round(anime_time, 2)}ms</small></summary>
{anime_html}
</details>
@@ -65,11 +73,16 @@ def home():
{manga_html}
</details>
""",
+ )
)
else:
- return page(
- f"""<a href="https://anilist.co/api/v2/oauth/authorize?client_id={os.getenv('ANILIST_CLIENT_ID')}&redirect_uri={os.getenv('ANILIST_REDIRECT_URI')}&response_type=code">Login with AniList</a>
+ response.set_data(
+ page(
+ f"""<a href="https://anilist.co/api/v2/oauth/authorize?client_id={os.getenv('ANILIST_CLIENT_ID')}&redirect_uri={os.getenv('ANILIST_REDIRECT_URI')}&response_type=code">Login with AniList</a>
<br>""",
- "Please log in to view due media.",
+ "Please log in to view due media.",
+ )
)
+
+ return response