From c36e6ec046015ab401ae2bf60830d0fae66be2a8 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Thu, 16 Jan 2025 21:24:11 +0000 Subject: [PATCH 1/5] Redirect any old URLs to the new query-based format --- src/fontra/core/server.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fontra/core/server.py b/src/fontra/core/server.py index 18c276f82..896f19881 100644 --- a/src/fontra/core/server.py +++ b/src/fontra/core/server.py @@ -78,10 +78,7 @@ def setup(self) -> None: ) for viewName, viewPackage in self.viewEntryPoints.items(): routes.append( - web.get( - f"/{viewName}/-/{{path:.*}}", - partial(self.viewPathHandler, viewName), - ) + web.get(f"/{viewName}/-/{{path:.*}}", self.viewRedirectHandler) ) routes.append( web.get( @@ -295,6 +292,9 @@ async def viewPathHandler( return web.Response(body=html, content_type="text/html") + async def viewRedirectHandler(self, request: web.Request) -> web.Response: + raise web.HTTPFound(request.path.replace("/-/", "/?project=")) + def _addVersionTokenToReferences(self, data: bytes, contentType: str) -> bytes: if self.versionToken is None: return data From f464df83f18615e9d65e4d8778c46f60c32bc7e0 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Thu, 16 Jan 2025 21:24:45 +0000 Subject: [PATCH 2/5] Send all view URLs to the view handler, serve static if they have no query string --- src/fontra/core/server.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/fontra/core/server.py b/src/fontra/core/server.py index 896f19881..42b2c0f9b 100644 --- a/src/fontra/core/server.py +++ b/src/fontra/core/server.py @@ -83,7 +83,7 @@ def setup(self) -> None: routes.append( web.get( f"/{viewName}/{{path:.*}}", - partial(self.staticContentHandler, viewPackage), + partial(self.viewPathHandler, viewName), ) ) routes.append( @@ -277,8 +277,13 @@ async def viewPathHandler( qs = quote(request.path_qs, safe="") raise web.HTTPFound(f"/?ref={qs}") - path = request.match_info["path"] - if not await self.projectManager.projectAvailable(path, authToken): + if not request.query: + return await self.staticContentHandler( + self.viewEntryPoints[viewName], request + ) + + project = request.query.get("project") + if not await self.projectManager.projectAvailable(project, authToken): raise web.HTTPNotFound() try: From 03601a76ca03c5ed71e6269ab669e63b75d13663 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Thu, 16 Jan 2025 21:25:01 +0000 Subject: [PATCH 3/5] Parse, and produce, new-style query URLs --- src/fontra/client/core/view-controller.js | 2 +- src/fontra/filesystem/landing.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fontra/client/core/view-controller.js b/src/fontra/client/core/view-controller.js index acf592dae..ab407c27f 100644 --- a/src/fontra/client/core/view-controller.js +++ b/src/fontra/client/core/view-controller.js @@ -11,7 +11,7 @@ export class ViewController { return `Fontra — ${decodeURI(displayPath)}`; } static async fromBackend() { - const pathItems = window.location.pathname.split("/").slice(3); + const pathItems = new URL(window.location).searchParams.get("project").split("/"); const displayPath = makeDisplayPath(pathItems); document.title = this.titlePattern(displayPath); const projectPath = pathItems.join("/"); diff --git a/src/fontra/filesystem/landing.js b/src/fontra/filesystem/landing.js index cf4bd6262..2f17eeca5 100644 --- a/src/fontra/filesystem/landing.js +++ b/src/fontra/filesystem/landing.js @@ -13,7 +13,7 @@ export async function startupLandingPage(authenticateFunc) { for (const project of projectList) { const projectElement = document.createElement("a"); - projectElement.href = "/fontoverview/-/" + project; + projectElement.href = "/fontoverview/?project=" + project; projectElement.className = "project-item"; projectElement.append(project); projectListContainer.appendChild(projectElement); From 6dc97112335a2f44a2cc7cff9ceb81ca80ffd057 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 17 Jan 2025 03:16:19 +0000 Subject: [PATCH 4/5] Type happiness --- src/fontra/core/server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fontra/core/server.py b/src/fontra/core/server.py index 42b2c0f9b..7be4e2fd6 100644 --- a/src/fontra/core/server.py +++ b/src/fontra/core/server.py @@ -283,7 +283,9 @@ async def viewPathHandler( ) project = request.query.get("project") - if not await self.projectManager.projectAvailable(project, authToken): + if project and not await self.projectManager.projectAvailable( + project, authToken + ): raise web.HTTPNotFound() try: From 06756b6635b1cde80fbf233d1d052344b1aee90a Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 17 Jan 2025 11:51:55 +0000 Subject: [PATCH 5/5] Update src/fontra/core/server.py Co-authored-by: Just van Rossum --- src/fontra/core/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fontra/core/server.py b/src/fontra/core/server.py index 7be4e2fd6..ff97b1cd7 100644 --- a/src/fontra/core/server.py +++ b/src/fontra/core/server.py @@ -283,7 +283,7 @@ async def viewPathHandler( ) project = request.query.get("project") - if project and not await self.projectManager.projectAvailable( + if project is None or not await self.projectManager.projectAvailable( project, authToken ): raise web.HTTPNotFound()