diff options
| author | Ben Sima <ben@bsima.me> | 2025-11-15 20:30:39 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bsima.me> | 2025-11-15 20:30:39 -0500 |
| commit | b0b7b771f3b410c5a9031b2ae8e17d9634cdbb65 (patch) | |
| tree | 3655a9545bc8a7a5a8a3a169cd6ecfc523d42e4a /Biz/PodcastItLater/Web.py | |
| parent | 803f82595f307b66e5bc195a02d38effd0a60b3a (diff) | |
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 <amp@ampcode.com>
Diffstat (limited to 'Biz/PodcastItLater/Web.py')
| -rw-r--r-- | Biz/PodcastItLater/Web.py | 30 |
1 files changed, 30 insertions, 0 deletions
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.""" |
