diff options
| author | Fuwn <[email protected]> | 2023-07-27 11:47:07 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-07-27 11:47:07 -0700 |
| commit | 4496c6b0b29aa325304a0011dec15d8dbaff3ff0 (patch) | |
| tree | 61ee8a1e6cd7d6ea405c37937e4dcd75a6aeb929 /src | |
| parent | feat(index): warn about activity streaks (diff) | |
| download | old.due.moe-4496c6b0b29aa325304a0011dec15d8dbaff3ff0.tar.xz old.due.moe-4496c6b0b29aa325304a0011dec15d8dbaff3ff0.zip | |
feat(index): detect outdated token
Diffstat (limited to 'src')
| -rw-r--r-- | src/due/media.py | 25 | ||||
| -rw-r--r-- | src/due/routes/index.py | 10 |
2 files changed, 23 insertions, 12 deletions
diff --git a/src/due/media.py b/src/due/media.py index 8c86855..67d9e01 100644 --- a/src/due/media.py +++ b/src/due/media.py @@ -2,17 +2,20 @@ import requests def user_id(anilist): - return int( - requests.post( - "https://graphql.anilist.co", - json={"query": "{ Viewer { id } }"}, - headers={ - "Authorization": anilist["token_type"] + " " + anilist["access_token"], - "Content-Type": "application/json", - "Accept": "application/json", - }, - ).json()["data"]["Viewer"]["id"] - ) + viewer = requests.post( + "https://graphql.anilist.co", + json={"query": "{ Viewer { id } }"}, + headers={ + "Authorization": anilist["token_type"] + " " + anilist["access_token"], + "Content-Type": "application/json", + "Accept": "application/json", + }, + ).json()["data"]["Viewer"] + + if viewer is None: + return -1 + + return int(viewer["id"]) def last_activity(id): diff --git a/src/due/routes/index.py b/src/due/routes/index.py index ce8d66c..720a462 100644 --- a/src/due/routes/index.py +++ b/src/due/routes/index.py @@ -1,6 +1,6 @@ import time from due.html import anime_to_html, manga_to_html, page -from due.media import create_collection, last_activity, user_name_to_id +from due.media import create_collection, last_activity, user_id, user_name_to_id from flask import make_response, redirect, request, Blueprint import json import os @@ -49,6 +49,14 @@ def home(): if request.cookies.get("anilist"): anilist = json.loads(request.cookies.get("anilist")) + + if user_id(anilist) == -1: + response = redirect("/") + + response.delete_cookie("anilist") + + return response + start = time.time() (current_anime, name) = create_collection( anilist, "ANIME", request.args.get("username") |