Skip to content

Commit

Permalink
Merge pull request #1959 from googlefonts/query-url
Browse files Browse the repository at this point in the history
Use ?project= instead of /-/
  • Loading branch information
justvanrossum authored Jan 17, 2025
2 parents 3a4921a + 06756b6 commit 69e2eca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/fontra/client/core/view-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
Expand Down
21 changes: 14 additions & 7 deletions src/fontra/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,12 @@ 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(
f"/{viewName}/{{path:.*}}",
partial(self.staticContentHandler, viewPackage),
partial(self.viewPathHandler, viewName),
)
)
routes.append(
Expand Down Expand Up @@ -280,8 +277,15 @@ 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 project is None or not await self.projectManager.projectAvailable(
project, authToken
):
raise web.HTTPNotFound()

try:
Expand All @@ -295,6 +299,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
Expand Down
2 changes: 1 addition & 1 deletion src/fontra/filesystem/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 69e2eca

Please sign in to comment.