Skip to content

Conversation

syeopite
Copy link
Member

Crystal 1.16.0 fixed the parsing of some weird-looking paths meaning that //api/v1/storyboards/sb/i/... will no longer get parsed into a request target of /v1/storyboards/sb/i/... within requests.

But the fix is a bit more annoying than just changing a path. The "new" existence of the double slash means that StaticFileHandler will process and redirect the request to a normalized path with only a single slash. This redirect however does not preserve url query parameters which are needed to request storyboards from YouTube.

Then there's the fact that the status code error handlers are disabled for the API routes, meaning that there is no handler to actually process the request with.

This PR patches Kemal's StaticFileHandler to preserve query parameters when redirecting, and adds the /api/v1/storyboard/sb/* -> /sb/i/*/ redirect directly into Kemal's ExceptionHandler for now.

In the future a dedicated handler should be created to properly handle http status code conditions on the API routes.

Crystal 1.16.0 fixed the parsing of some weird-looking paths meaning
that `//api/v1/storyboards/sb/i/...` will no longer get parsed into a
request target of `/v1/storyboards/sb/i/...` within requests.

But the fix is a bit more convoluted than just changing a path. The new
presence of double slash means that `StaticFileHandler` will process and
redirect the request to a normalized path with only a single slash.
This redirect however does not preserve url query parameters which are
needed to request storyboards from YouTube.

Then there's the fact that the status code error handlers are disabled
for the API routes, meaning that there is no handler to actually process
the request with.

This PR patches Kemal's `StaticFileHandler` to preserve query parameters
when redirecting, and adds the `/api/v1/storyboard/sb/*` ->
`/sb/i/*/` redirect directly into Kemal's `ExceptionHandler` for now.

In the future a dedicated handler should be created to properly handle
http status code conditions on the API routes.
@syeopite syeopite requested a review from a team as a code owner May 18, 2025 06:30
@syeopite syeopite requested review from alexmaras and removed request for a team May 18, 2025 06:30
@syeopite syeopite added the module:player Impacts the video player of Invidious label May 18, 2025
@syeopite syeopite removed the request for review from alexmaras June 21, 2025 19:01
@syeopite
Copy link
Member Author

Note: extra care needs to be taken when merging alongside #5338 to also override the redirect_to method on the new static files handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:player Impacts the video player of Invidious
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant