1818from django .conf .urls .static import static
1919from django .contrib import admin
2020from django .urls import path , include
21+ from drf_spectacular .views import SpectacularAPIView , SpectacularSwaggerView , SpectacularRedocView
2122
22- import kirovy .views . map_upload_views
23- from kirovy .views import test , cnc_map_views , permission_views , admin_views
24- from kirovy import typing as t
23+ from kirovy .models import CncGame
24+ from kirovy .views import test , cnc_map_views , permission_views , admin_views , map_upload_views
25+ from kirovy import typing as t , constants
2526
2627
2728def _get_url_patterns () -> list [path ]:
@@ -30,17 +31,37 @@ def _get_url_patterns() -> list[path]:
3031 I added this because I wanted to have the root URLs at the top of the file,
3132 but I didn't want to have other url files.
3233 """
34+ dev_urls = []
35+ if settings .RUN_ENVIRONMENT == "dev" :
36+ dev_urls = [
37+ path ("api/schema/" , SpectacularAPIView .as_view (), name = "schema" ),
38+ # Optional UI:
39+ path ("api/schema/swagger-ui/" , SpectacularSwaggerView .as_view (url_name = "schema" ), name = "swagger-ui" ),
40+ path ("api/schema/redoc/" , SpectacularRedocView .as_view (url_name = "schema" ), name = "redoc" ),
41+ ]
42+
43+ backwards_compatible_urls = [
44+ path ("upload" , map_upload_views .CncNetBackwardsCompatibleUploadView .as_view ()),
45+ * (
46+ # Make e.g. /yr/map_hash, /ra2/map_hash, etc
47+ path (f"{ g .slug } /<str:sha1_hash>" , cnc_map_views .BackwardsCompatibleMapView .as_view (), {"game_id" : g .id })
48+ for g in CncGame .objects .filter (slug__in = constants .BACKWARDS_COMPATIBLE_GAMES )
49+ ),
50+ ]
51+
3352 return (
3453 [
3554 path ("admin/" , include (admin_patterns )),
3655 path ("test/jwt" , test .TestJwt .as_view ()),
3756 path ("ui-permissions/" , permission_views .ListPermissionForAuthUser .as_view ()),
3857 path ("maps/" , include (map_patterns )),
3958 # path("users/<uuid:cnc_user_id>/", ...), # will show which files a user has uploaded.
40- # path("games/", ...), # get games.
59+ # path("games/", ...), # get games.,
4160 ]
42- + static (settings .STATIC_URL , document_root = settings .STATIC_ROOT )
43- + static (settings .MEDIA_URL , document_root = settings .MEDIA_ROOT )
61+ + backwards_compatible_urls
62+ + static (settings .STATIC_URL , document_root = settings .STATIC_ROOT ) # static assets
63+ + static (settings .MEDIA_URL , document_root = settings .MEDIA_ROOT ) # user uploads
64+ + dev_urls
4465 )
4566
4667
@@ -49,8 +70,8 @@ def _get_url_patterns() -> list[path]:
4970 # path("categories/", ...), # return all categories
5071 # path("categories/game/<uuid:cnc_game_id>/", ...),
5172 path ("categories/" , cnc_map_views .MapCategoryListCreateView .as_view ()),
52- path ("upload/" , kirovy . views . map_upload_views .MapFileUploadView .as_view ()),
53- path ("client/upload/" , kirovy . views . map_upload_views .CncnetClientMapUploadView .as_view ()),
73+ path ("upload/" , map_upload_views .MapFileUploadView .as_view ()),
74+ path ("client/upload/" , map_upload_views .CncnetClientMapUploadView .as_view ()),
5475 path ("<uuid:pk>/" , cnc_map_views .MapRetrieveUpdateView .as_view ()),
5576 path ("delete/<uuid:pk>/" , cnc_map_views .MapDeleteView .as_view ()),
5677 path ("search/" , cnc_map_views .MapListCreateView .as_view ()),
@@ -67,5 +88,4 @@ def _get_url_patterns() -> list[path]:
6788# /admin/
6889admin_patterns = [path ("ban/" , admin_views .BanView .as_view ())]
6990
70-
7191urlpatterns = _get_url_patterns ()
0 commit comments