diff options
| author | Bobby <[email protected]> | 2024-09-05 05:18:09 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-09-05 05:18:09 -0400 |
| commit | 5bfdb6ef76df1d0af7b93e0a03ed917e10fc5fb9 (patch) | |
| tree | 5a5079296b9d89fbfd3f6557f1d2b694ebef1680 | |
| parent | df00dbdef3178aeceb2b36debdce851339fa3f91 (diff) | |
| download | yugen-5bfdb6ef76df1d0af7b93e0a03ed917e10fc5fb9.tar.xz yugen-5bfdb6ef76df1d0af7b93e0a03ed917e10fc5fb9.zip | |
fix url and watch sub dub
| -rw-r--r-- | authentication/urls.py | 9 | ||||
| -rw-r--r-- | authentication/views.py | 5 | ||||
| -rw-r--r-- | detail/urls.py | 3 | ||||
| -rw-r--r-- | detail/views.py | 6 | ||||
| -rw-r--r-- | middleware/remove_slash.py | 6 | ||||
| -rw-r--r-- | templates/watch/watch.html | 4 | ||||
| -rw-r--r-- | user_profile/urls.py | 4 | ||||
| -rw-r--r-- | watch/urls.py | 11 | ||||
| -rw-r--r-- | watch/views.py | 3 | ||||
| -rw-r--r-- | yugen/urls.py | 6 |
10 files changed, 39 insertions, 18 deletions
diff --git a/authentication/urls.py b/authentication/urls.py index 0a84fab..33aaebf 100644 --- a/authentication/urls.py +++ b/authentication/urls.py @@ -4,8 +4,9 @@ from . import views app_name = "auth" urlpatterns = [ - path("callback", views.callback, name="callback"), - path("MALSync", views.MALSync, name="MALSync"), - path("logout", views.logout_user, name="logout"), - path("unauthorized", views.unauthorized, name="unauthorized"), + path("", views.index, name="index"), + path("/callback", views.callback, name="callback"), + path("/MALSync", views.MALSync, name="MALSync"), + path("/logout", views.logout_user, name="logout"), + path("/unauthorized", views.unauthorized, name="unauthorized"), ] diff --git a/authentication/views.py b/authentication/views.py index 89bf466..4c672a5 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -5,6 +5,11 @@ from django.urls import reverse from authentication.utils import exchange_code, authenticate_user, exchange_mal_code, get_redirect_uri from django.shortcuts import redirect, render +def index(request): + if request.user.is_authenticated: + return redirect("home:index") + + return redirect(get_redirect_uri()) def callback(request): if request.user.is_authenticated: diff --git a/detail/urls.py b/detail/urls.py index 6bb7829..7f172ad 100644 --- a/detail/urls.py +++ b/detail/urls.py @@ -4,5 +4,6 @@ from . import views app_name = "detail" urlpatterns = [ - path('<int:anime_id>', views.detail, name='detail'), + path('', views.index, name='index'), + path('/<int:anime_id>', views.detail, name='detail'), ] diff --git a/detail/views.py b/detail/views.py index d62c9e0..f9fbd9c 100644 --- a/detail/views.py +++ b/detail/views.py @@ -1,11 +1,15 @@ import json import os -from django.shortcuts import render +from django.shortcuts import redirect, render import requests from functools import lru_cache from authentication.utils import get_single_anime_mal from watch.utils import get_all_episode_metadata, get_from_redis_cache, store_in_redis_cache + +def index(request): + return redirect("home:index") + def detail(request, anime_id): anime_data = get_anime_data(anime_id) if not anime_data: diff --git a/middleware/remove_slash.py b/middleware/remove_slash.py index 15be769..0fde6c0 100644 --- a/middleware/remove_slash.py +++ b/middleware/remove_slash.py @@ -5,6 +5,10 @@ class RemoveSlashMiddleware: self.get_response = get_response def __call__(self, request): - if request.path != '/' and request.path.endswith('/'): + if '/admin' in request.path and not request.path.endswith('/'): + return HttpResponsePermanentRedirect(request.path + '/') + + if request.path != '/' and request.path.endswith('/') and "/admin/" not in request.path: return HttpResponsePermanentRedirect(request.path[:-1]) + return self.get_response(request)
\ No newline at end of file diff --git a/templates/watch/watch.html b/templates/watch/watch.html index 050b82e..01b43a5 100644 --- a/templates/watch/watch.html +++ b/templates/watch/watch.html @@ -62,7 +62,7 @@ </a> {% else %} - <a href="{% if not viaMal %}{% url "watch:watch_episode" anime.id episode.number %}{% if request.GET.mode %}?mode={{ request.GET.mode }}{% endif %}{% else %}{% url "watch:watch_via_zid_mal_id" anime.id anime.z_anime_id %}?ep={{ episode.episode.identifier }}{% if request.GET.mode %}&mode={{ request.GET.mode }}{% endif %}{% endif %}" class="flex flex-row justify-between w-full gap-4 {% if episode.number in watched_episodes %}bg-{{ user.preferences.accent_colour }}-600 bg-opacity-20{% else %}bg-white bg-opacity-10{% endif %} p-2 rounded hover:bg-{{ user.preferences.accent_colour }}-600 hover:bg-opacity-30"> + <a href="{% if not viaMal %}{% url "watch:watch_episode" anime.id 1 %}{% if request.GET.mode %}?mode={{ request.GET.mode }}{% endif %}{% else %}{% url "watch:watch_via_zid_mal_id" anime.id anime.z_anime_id %}?ep={{ episode.episode.identifier }}{% if request.GET.mode %}&mode={{ request.GET.mode }}{% endif %}{% endif %}" class="flex flex-row justify-between w-full gap-4 {% if episode.number in watched_episodes %}bg-{{ user.preferences.accent_colour }}-600 bg-opacity-20{% else %}bg-white bg-opacity-10{% endif %} p-2 rounded hover:bg-{{ user.preferences.accent_colour }}-600 hover:bg-opacity-30"> <span class="truncate max-w-full overflow-hidden text-ellipsis whitespace-nowrap">{{ episode.number }}. {{ episode.title }}</span> <span class="flex flex-row item-center gap-2"> {% if episode.filler %} @@ -103,8 +103,10 @@ <div class="flex flex-row gap-2 items-center justify-between"> <h2 class="text-xl font-bold truncate max-w-full overflow-hidden text-ellipsis whitespace-nowrap">Episode {{ current_episode.number }} — {{ current_episode.title }}</h2> <div class="flex flex-row gap-1 items-center"> + {% if current_episode.number %} <a href="{% if not viaMal %}{% url "watch:watch_episode" anime.id current_episode.number %}?mode=sub{% else %}{% url "watch:watch_via_zid_mal_id" anime.id anime.z_anime_id %}?ep={{ current_episode.episode.identifier }}&mode=sub{% endif %}" class="{% if mode == "sub" %}bg-{{ user.preferences.accent_colour }}-600{% else %}bg-white bg-opacity-10{% endif %} text-white text-sm font-bold px-4 py-2 rounded">Sub</a> <a href="{% if not viaMal %}{% url "watch:watch_episode" anime.id current_episode.number %}?mode=dub{% else %}{% url "watch:watch_via_zid_mal_id" anime.id anime.z_anime_id %}?ep={{ current_episode.episode.identifier }}&mode=dub{% endif %}" class="{% if mode == "dub" %}bg-{{ user.preferences.accent_colour }}-600{% else %}bg-white bg-opacity-10{% endif %} text-white text-sm font-bold px-4 py-2 rounded">Dub</a> + {% endif %} </div> </div> <p class="my-4"> diff --git a/user_profile/urls.py b/user_profile/urls.py index d014c7b..1e685da 100644 --- a/user_profile/urls.py +++ b/user_profile/urls.py @@ -5,6 +5,6 @@ from . import views app_name = "user_profile" urlpatterns = [ path("", views.user_profile, name="user_profile"), - path("save_user_preferences", views.save_user_preferences, name="save_user_preferences"), - path("update_user_mal_list", views.update_user_mal_list, name="update_user_mal_list"), + path("/save_user_preferences", views.save_user_preferences, name="save_user_preferences"), + path("/update_user_mal_list", views.update_user_mal_list, name="update_user_mal_list"), ]
\ No newline at end of file diff --git a/watch/urls.py b/watch/urls.py index 8df0660..c92bba3 100644 --- a/watch/urls.py +++ b/watch/urls.py @@ -4,9 +4,10 @@ from . import views app_name = "watch" urlpatterns = [ - path('<int:anime_id>', views.watch, name='watch'), - path('<int:anime_id>/<int:episode>', views.watch, name='watch_episode'), - path('zid:<str:zid>', views.watch_via_zid, name='watch_via_zid'), - path('update_watch_history', views.update_episode_watch_time, name='update_watch_history'), - path('malId:<int:mal_id>$zid:<str:zid>', views.watch_via_zid_mal_id, name='watch_via_zid_mal_id'), # if anilist id is not available + path('', views.index, name='index'), + path('/<int:anime_id>', views.watch, name='watch'), + path('/<int:anime_id>/<int:episode>', views.watch, name='watch_episode'), + path('/zid:<str:zid>', views.watch_via_zid, name='watch_via_zid'), + path('/update_watch_history', views.update_episode_watch_time, name='update_watch_history'), + path('/malId:<int:mal_id>$zid:<str:zid>', views.watch_via_zid_mal_id, name='watch_via_zid_mal_id'), # if anilist id is not available ] diff --git a/watch/views.py b/watch/views.py index 853195e..6ffdc04 100644 --- a/watch/views.py +++ b/watch/views.py @@ -16,6 +16,9 @@ import json dotenv.load_dotenv() +def index(request): + return redirect("home:index") + def get_anime_by_id(anime_id): cache_key = f"anime_{anime_id}_anime_data" try: diff --git a/yugen/urls.py b/yugen/urls.py index cbec43c..087a745 100644 --- a/yugen/urls.py +++ b/yugen/urls.py @@ -21,10 +21,10 @@ from django.conf.urls.static import static urlpatterns = [ path("", include("homepage.urls", namespace="home")), - path("watch/", include("watch.urls", namespace="watch")), - path("detail/", include("detail.urls", namespace="detail")), + path("watch", include("watch.urls", namespace="watch")), + path("detail", include("detail.urls", namespace="detail")), path("profile", include("user_profile.urls", namespace="profile")), - path("auth/", include("authentication.urls", namespace="auth")), + path("auth", include("authentication.urls", namespace="auth")), path("admin/", admin.site.urls), ] |
