From b0b7b771f3b410c5a9031b2ae8e17d9634cdbb65 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 15 Nov 2025 20:30:39 -0500 Subject: Add backward compatibility redirect for legacy episode URLs Maintain compatibility with old sequential integer episode URLs by redirecting them to the new sqid-based URLs with a 301 permanent redirect. - Add /episode/{episode_id:int} route for legacy integer IDs - Redirect with 301 status to indicate permanent move to new URL - Add test to verify redirect behavior - Mark route as deprecated in documentation This allows existing shared links to continue working while encouraging adoption of the new non-sequential URLs. The legacy route can be removed after a deprecation period. Amp-Thread-ID: https://ampcode.com/threads/T-cc5d29f0-454e-4864-8d7e-1ad69a42afa9 Co-authored-by: Amp --- Biz/PodcastItLater/Web.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'Biz/PodcastItLater') diff --git a/Biz/PodcastItLater/Web.py b/Biz/PodcastItLater/Web.py index 12c45c4..1a94007 100644 --- a/Biz/PodcastItLater/Web.py +++ b/Biz/PodcastItLater/Web.py @@ -1284,6 +1284,23 @@ def rss_feed(request: Request, token: str) -> Response: # noqa: ARG001 return Response(f"Error generating feed: {e}", status_code=500) +@app.get("/episode/{episode_id:int}") +def episode_detail_legacy( + request: Request, # noqa: ARG001 + episode_id: int, +) -> RedirectResponse: + """Redirect legacy integer episode IDs to sqid URLs. + + Deprecated: This route exists for backward compatibility. + Will be removed in a future version. + """ + episode_sqid = encode_episode_id(episode_id) + return RedirectResponse( + url=f"/episode/{episode_sqid}", + status_code=301, # Permanent redirect + ) + + @app.get("/episode/{episode_sqid}") def episode_detail( request: Request, @@ -2124,6 +2141,19 @@ class TestEpisodeDetailPage(BaseWebTest): self.assertIn(f'href="/episode/{self.episode_sqid}"', response.text) self.assertIn("Test Episode", response.text) + def test_legacy_integer_id_redirects(self) -> None: + """Legacy integer episode IDs should redirect to sqid URLs.""" + response = self.client.get( + f"/episode/{self.episode_id}", + follow_redirects=False, + ) + + self.assertEqual(response.status_code, 301) + self.assertEqual( + response.headers["location"], + f"/episode/{self.episode_sqid}", + ) + def test() -> None: """Run all tests for the web module.""" -- cgit v1.2.3