Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ?project= instead of /-/ #1959

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading