Commit 3592c605 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Replace Upload's download link with add-to-playlist/play

The result card now plays the tagged track directly through the shared
player and offers "Add to playlist" (reusing AddToPlaylistModal, whose
song prop is narrowed to {id, title} since that's all it actually
reads - lets Upload's TagMetadata-shaped result satisfy it without
fabricating a fake LibrarySong). download_url is gone from the backend
response too (see stax_backend_api), closing an unauthenticated-file
access gap that had no remaining caller once this landed. Adds
Upload.tsx's first test coverage.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 36c09de9
Pipeline #1157 failed with stage
in 22 minutes and 15 seconds
......@@ -14,7 +14,6 @@ export interface TagMetadata {
export interface TagResponse {
status: string
download_url: string
metadata: TagMetadata
}
......
import { useCallback, useEffect, useRef, useState } from 'react'
import { Check, ListMusic, Plus, X } from 'lucide-react'
import { addToPlaylist, createPlaylist, getPlaylists, type LibrarySong, type Playlist } from '../api/library'
import { addToPlaylist, createPlaylist, getPlaylists, type Playlist } from '../api/library'
import { ApiError } from '../api/client'
import { Button } from './ui/Button'
import { Input } from './ui/Input'
......@@ -10,7 +10,11 @@ import { useMountTransition } from '../hooks/useMountTransition'
const ANIMATION_MS = 300
interface AddToPlaylistModalProps {
song: LibrarySong
// Only id/title are actually used below - a full LibrarySong works fine (it has both, plus
// more), but requiring only what's needed means callers that don't have a full LibrarySong on
// hand (e.g. Upload.tsx's freshly-tagged result, which is shaped like TagMetadata instead)
// don't have to fabricate fake user_id/file_path/added_at values just to satisfy this prop.
song: { id: number; title: string }
onClose: () => void
}
......
......@@ -85,6 +85,7 @@ const BACKEND_DONE: DoneGroup[] = [
'Universal search: songs + albums (a derived (album, artist) grouping of the caller\'s own songs, not a separate table) matching title/artist/genre or album/artist respectively',
'Playlists: create, list, detail with ordered tracks, add track',
'Delete: songs (+ file on disk), playlists (+ their tracks), single playlist tracks - all owner-scoped',
'/music/tag and /music/upload no longer return a download_url (2026-09-01) - same access-control gap as the old remix one below: the URL pointed at the unauthenticated /downloads static mount with no ownership check, so anyone who saw or guessed a path could pull another user\'s file. Nothing served it any more once the frontend switched the Upload result card to "add to playlist" instead of a download link, so it was removed rather than patched; playback goes through the already-auth-scoped /library/stream/{id}.',
],
},
{
......@@ -190,6 +191,7 @@ const FRONTEND_DONE: DoneGroup[] = [
'Playlists page: list, create, view tracks, playback',
'Add-to-playlist modal from the Library page (add existing or create-and-add)',
'Delete-from-library (2026-08-31): swipe a Library row left past a threshold to reveal and trigger delete (right instead adds to queue) - confirms via the same window.confirm pattern already used for soundmark delete, then removes the file on disk and reconciles the song out of every local list it could be showing in (the full library, the current search\'s Songs section, and any album groupings within it)',
'Upload\'s result card swaps its download link for "Add to playlist" (2026-09-01), reusing AddToPlaylistModal (narrowed its song prop to just {id, title} rather than the full LibrarySong shape, since Upload\'s freshly-tagged result isn\'t one) - the card itself is now tappable to play the track immediately via the shared player instead of only offering a file to save locally',
],
},
{
......@@ -235,11 +237,6 @@ const FRONTEND_TODO: WorkItem[] = [
status: 'ready',
note: 'Backend endpoints already exist and work - zero UI.',
},
{
item: 'Test coverage for the Upload page',
status: 'ready',
note: 'Discovery and Remix both got their first tests 2026-08-22. Upload is the last page still at zero - no blockers, just needs writing.',
},
{ item: 'Volume control in the player', status: 'ready' },
{
item: 'Global error boundary',
......
......@@ -13,7 +13,6 @@ const CHAT = { id: 1, title: 'Music Sharing', type: 'group' }
const MUSIC = { message_id: 1, title: 'Invisible', artist: 'Duran Duran', duration: 200, file_name: 'invisible.mp3' }
const TAG_RESPONSE = {
status: 'success',
download_url: '/files/invisible-tagged.mp3',
metadata: {
library_song_id: 42,
title: 'Invisible (Remastered)',
......
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { Upload } from './Upload'
import { AuthProvider } from '../context/AuthContext'
import { PlayerProvider } from '../context/PlayerContext'
import * as musicApi from '../api/music'
import * as libraryApi from '../api/library'
const TAG_RESPONSE = {
status: 'success',
metadata: {
library_song_id: 42,
title: 'Invisible (Remastered)',
artist: 'Duran Duran',
album: 'Notorious',
genre: 'Pop',
year: '1986',
has_lyrics: true,
lyrics: null,
cover_art: null,
},
}
function renderPage() {
return render(
<MemoryRouter>
<AuthProvider>
<PlayerProvider>
<Upload />
</PlayerProvider>
</AuthProvider>
</MemoryRouter>,
)
}
async function uploadAndWaitForResult() {
vi.spyOn(musicApi, 'uploadDirect').mockImplementation(async (_file, onProgress) => {
onProgress?.(100)
return TAG_RESPONSE
})
renderPage()
const file = new File([new Uint8Array([1, 2, 3])], 'test.mp3', { type: 'audio/mpeg' })
const input = document.querySelector('input[type="file"]') as HTMLInputElement
await userEvent.upload(input, file)
await userEvent.click(screen.getByRole('button', { name: /Upload/ }))
expect(await screen.findByText('Invisible (Remastered)')).toBeInTheDocument()
}
describe('Upload', () => {
beforeEach(() => {
vi.stubEnv('VITE_DEV_ACCESS_TOKEN', '')
vi.stubEnv('VITE_DEV_REFRESH_TOKEN', '')
})
afterEach(() => {
vi.unstubAllEnvs()
vi.restoreAllMocks()
})
it('does not offer a download link for a tagged result', async () => {
await uploadAndWaitForResult()
expect(screen.queryByText(/download/i)).not.toBeInTheDocument()
})
it('opens the add-to-playlist modal from the result card', async () => {
await uploadAndWaitForResult()
vi.spyOn(libraryApi, 'getPlaylists').mockResolvedValue({ status: 'success', playlists: [] })
await userEvent.click(screen.getByRole('button', { name: 'Add to playlist' }))
expect(await screen.findByRole('dialog')).toBeInTheDocument()
expect(screen.getByText('Add "Invisible (Remastered)" to playlist')).toBeInTheDocument()
})
it('adds the tagged song to a playlist', async () => {
await uploadAndWaitForResult()
vi.spyOn(libraryApi, 'getPlaylists').mockResolvedValue({
status: 'success',
playlists: [{ id: 10, user_id: 1, name: 'Chill', created_at: '2026-01-01T00:00:00Z' }],
})
const addToPlaylist = vi.spyOn(libraryApi, 'addToPlaylist').mockResolvedValue({ status: 'success', message: 'ok' })
await userEvent.click(screen.getByRole('button', { name: 'Add to playlist' }))
await userEvent.click(await screen.findByText('Chill'))
expect(addToPlaylist).toHaveBeenCalledWith(10, 42)
})
it('closes the modal on backdrop click', async () => {
await uploadAndWaitForResult()
vi.spyOn(libraryApi, 'getPlaylists').mockResolvedValue({ status: 'success', playlists: [] })
await userEvent.click(screen.getByRole('button', { name: 'Add to playlist' }))
const dialog = await screen.findByRole('dialog')
await userEvent.click(dialog)
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
})
})
import { useState } from 'react'
import { Pause, Play, UploadCloud } from 'lucide-react'
import { ListPlus, Pause, Play, UploadCloud } from 'lucide-react'
import { Layout } from '../components/Layout'
import { Button } from '../components/ui/Button'
import { ProgressBar } from '../components/ui/ProgressBar'
import { AddToPlaylistModal } from '../components/AddToPlaylistModal'
import { uploadDirect, type TagResponse } from '../api/music'
import { usePlayer } from '../context/PlayerContext'
......@@ -14,6 +15,7 @@ export function Upload() {
const [uploadPercent, setUploadPercent] = useState(0)
const [result, setResult] = useState<TagResponse | null>(null)
const [error, setError] = useState<string | null>(null)
const [addingToPlaylist, setAddingToPlaylist] = useState(false)
async function handleUpload() {
if (!file) return
......@@ -80,8 +82,8 @@ export function Upload() {
{result && (
<div className="mt-6 rounded-xl border border-outline-variant bg-surface-container p-3">
{/* Tapping anywhere on the card plays it, not just a small button - the icon on the
right is a status indicator rendered inside this same button. Download stays a
separate control below since it's a genuinely different action. */}
right is a status indicator rendered inside this same button. Add to playlist
stays a separate control below since it's a genuinely different action. */}
<button
onClick={() =>
toggle({
......@@ -120,16 +122,22 @@ export function Upload() {
)}
</span>
</button>
<a
href={result.download_url}
target="_blank"
rel="noreferrer"
className="mt-1 block px-1 text-sm text-on-surface-variant hover:text-on-surface hover:underline"
<button
onClick={() => setAddingToPlaylist(true)}
className="mt-1 flex items-center gap-1.5 px-1 py-1 text-sm text-on-surface-variant transition-colors hover:text-on-surface focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
>
Download tagged file
</a>
<ListPlus size={15} strokeWidth={1.75} />
Add to playlist
</button>
</div>
)}
{result && addingToPlaylist && (
<AddToPlaylistModal
song={{ id: result.metadata.library_song_id, title: result.metadata.title }}
onClose={() => setAddingToPlaylist(false)}
/>
)}
</Layout>
)
}
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