Commit 104986d6 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Add GET /social/posts/{id}/stream for cross-user post playback

A post's song_id isn't necessarily the poster's own library song, so
playing it needed the same not-scoped-to-caller stream endpoint pattern
already used for rooms, geo-drops, and soundmarks.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 77a227a2
Pipeline #1075 passed with stage
in 4 minutes and 53 seconds
...@@ -135,6 +135,20 @@ def get_remix_tree(post_id: int, db: Session = Depends(get_db), current_user: Us ...@@ -135,6 +135,20 @@ def get_remix_tree(post_id: int, db: Session = Depends(get_db), current_user: Us
return _build_remix_tree(post_id, db) return _build_remix_tree(post_id, db)
@router.get("/posts/{post_id}/stream")
def stream_post_song(post_id: int, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
"""Streams a post's song regardless of who uploaded it - a post's song_id isn't
necessarily the poster's own library song, same not-scoped-to-caller reasoning as the
other social stream endpoints (rooms, geo-drop, soundmarks)."""
post = db.query(Post).filter(Post.id == post_id).first()
if not post:
raise HTTPException(status_code=404, detail="Post not found")
song = db.query(LibrarySong).filter(LibrarySong.id == post.song_id).first()
if not song or not song.file_path or not os.path.exists(song.file_path):
raise HTTPException(status_code=404, detail="Audio file not found")
return FileResponse(song.file_path, media_type="audio/mpeg")
@router.post("/geo-drop", status_code=status.HTTP_201_CREATED) @router.post("/geo-drop", status_code=status.HTTP_201_CREATED)
def create_geo_drop(drop: GeoDropCreate, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)): def create_geo_drop(drop: GeoDropCreate, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
song = db.query(LibrarySong).filter(LibrarySong.id == drop.song_id).first() song = db.query(LibrarySong).filter(LibrarySong.id == drop.song_id).first()
......
...@@ -233,3 +233,19 @@ def test_remix_tree_leaf_node_has_no_children(client, auth_as): ...@@ -233,3 +233,19 @@ def test_remix_tree_leaf_node_has_no_children(client, auth_as):
).json()["id"] ).json()["id"]
response = client.get(f"/social/posts/{leaf_id}/tree", headers=headers) response = client.get(f"/social/posts/{leaf_id}/tree", headers=headers)
assert response.json()["children"] == [] assert response.json()["children"] == []
def test_stream_post_song_works_regardless_of_who_uploaded_it(client, auth_as):
song_id = _make_library_song(user_id=999) # uploaded by someone else entirely
headers, _ = auth_as()
post_id = client.post("/social/posts", json={"song_id": song_id, "caption": "x"}, headers=headers).json()["id"]
response = client.get(f"/social/posts/{post_id}/stream", headers=headers)
assert response.status_code == 200
assert response.content == b"fake mp3 bytes"
def test_stream_post_song_404s_for_unknown_post(client, auth_as):
headers, _ = auth_as()
response = client.get("/social/posts/999999/stream", headers=headers)
assert response.status_code == 404
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment