Files
navidrome/ui/src/playlist/PlaylistList.jsx
T
adrbn d004f99f8f feat(playlist): add custom playlist cover art upload (#5110)
* feat(playlist): add custom playlist cover art upload - #406

Allow users to upload, view, and remove custom cover images for playlists.
Custom images take priority over the auto-generated tiled artwork.

Backend:
- Add `image_path` column to playlist table (migration with proper rollback)
- Add `SetImage`/`RemoveImage` methods to playlist service
- Add `POST/DELETE /api/playlist/{id}/image` endpoints
- Prioritize custom image in artwork reader pipeline
- Clean up image files on playlist deletion
- Use glob-based cleanup to prevent orphaned files across format changes
- Reject uploads with undetermined image type (400)

Frontend:
- Hover overlay on playlist cover with upload (camera) and remove (trash) buttons
- Lightbox for full-size cover art viewing
- Cover art thumbnails in the playlist list view
- Loading/error states and i18n strings

Closes #406

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: adrbn <128328324+adrbn@users.noreply.github.com>

* refactor: rename playlist image path migration file

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(playlist): address review feedback for cover art upload - #406

- Use httpClient instead of raw fetch for image upload/remove
- Revert glob cleanup to simple imagePath check
- Add log.Error before all error HTTP responses
- Add backend tests for SetImage and RemoveImage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: adrbn <128328324+adrbn@users.noreply.github.com>

* refactor(playlist): use Playlist.ArtworkPath() for image storage

Migrate all playlist image path handling to use the new
Playlist.ArtworkPath() method as the single source of truth. The DB now
stores only the filename (e.g. "pls-1.jpg") instead of a relative path,
and images are stored under {DataFolder}/artwork/playlist/ instead of
{DataFolder}/playlist_images/. The artwork root directory is created at
startup alongside DataFolder and CacheFolder. This also removes the
conf dependency from reader_playlist.go since path resolution is now
fully encapsulated in the model.

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor(playlist): streamline artwork image selection logic

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor: move translation keys, add pt-BR translations

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor(playlist): rename image_path to image_file

Rename the playlist cover art column and field from image_path/ImagePath
to image_file/ImageFile across the migration, model, service, tests, and
UI. The new name more accurately describes what the field stores (a
filename, not a path) and aligns with the existing ImageFiles/IsImageFile
naming conventions in the codebase.

---------

Signed-off-by: adrbn <128328324+adrbn@users.noreply.github.com>
Signed-off-by: Deluan <deluan@navidrome.org>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Deluan Quintão <deluan@navidrome.org>
2026-03-01 14:07:18 -05:00

217 lines
4.9 KiB
React

import React, { useMemo } from 'react'
import {
Datagrid,
DateField,
EditButton,
Filter,
NumberField,
ReferenceInput,
SearchInput,
SelectInput,
TextField,
useUpdate,
useNotify,
useRecordContext,
BulkDeleteButton,
usePermissions,
} from 'react-admin'
import Switch from '@material-ui/core/Switch'
import { Avatar } from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import { useMediaQuery } from '@material-ui/core'
import {
DurationField,
List,
Writable,
isWritable,
useSelectedFields,
useResourceRefresh,
} from '../common'
import PlaylistListActions from './PlaylistListActions'
import ChangePublicStatusButton from './ChangePublicStatusButton'
import subsonic from '../subsonic'
const useStyles = makeStyles((theme) => ({
button: {
color: theme.palette.type === 'dark' ? 'white' : undefined,
},
coverArt: {
width: '40px',
height: '40px',
borderRadius: '4px',
},
}))
const PlaylistFilter = (props) => {
const { permissions } = usePermissions()
return (
<Filter {...props} variant={'outlined'}>
<SearchInput source="q" alwaysOn />
{permissions === 'admin' && (
<ReferenceInput
source="owner_id"
label={'resources.playlist.fields.ownerName'}
reference="user"
perPage={0}
sort={{ field: 'name', order: 'ASC' }}
alwaysOn
>
<SelectInput optionText="name" />
</ReferenceInput>
)}
</Filter>
)
}
const TogglePublicInput = ({ resource, source }) => {
const record = useRecordContext()
const notify = useNotify()
const [togglePublic] = useUpdate(
resource,
record.id,
{
...record,
public: !record.public,
},
{
undoable: false,
onFailure: (error) => {
notify('ra.page.error', 'warning')
},
},
)
const handleClick = (e) => {
togglePublic()
e.stopPropagation()
}
return (
<Switch
checked={record[source]}
onClick={handleClick}
disabled={!isWritable(record.ownerId)}
/>
)
}
const ToggleAutoImport = ({ resource, source }) => {
const record = useRecordContext()
const notify = useNotify()
const [ToggleAutoImport] = useUpdate(
resource,
record.id,
{
...record,
sync: !record.sync,
},
{
undoable: false,
onFailure: (error) => {
notify('ra.page.error', 'warning')
},
},
)
const handleClick = (e) => {
ToggleAutoImport()
e.stopPropagation()
}
return record.path ? (
<Switch
checked={record[source]}
onClick={handleClick}
disabled={!isWritable(record.ownerId)}
/>
) : null
}
const CoverArtField = () => {
const classes = useStyles()
const record = useRecordContext()
if (!record) return null
return (
<Avatar
src={subsonic.getCoverArtUrl(record, 80, true)}
variant="square"
className={classes.coverArt}
alt={record.name}
/>
)
}
CoverArtField.defaultProps = {
label: '',
sortable: false,
}
const PlaylistListBulkActions = (props) => {
const classes = useStyles()
return (
<>
<ChangePublicStatusButton
public={true}
{...props}
className={classes.button}
/>
<ChangePublicStatusButton
public={false}
{...props}
className={classes.button}
/>
<BulkDeleteButton {...props} className={classes.button} />
</>
)
}
const PlaylistList = (props) => {
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
useResourceRefresh('playlist')
const toggleableFields = useMemo(
() => ({
ownerName: isDesktop && <TextField source="ownerName" />,
songCount: !isXsmall && <NumberField source="songCount" />,
duration: <DurationField source="duration" />,
updatedAt: isDesktop && (
<DateField source="updatedAt" sortByOrder={'DESC'} />
),
public: !isXsmall && (
<TogglePublicInput source="public" sortByOrder={'DESC'} />
),
comment: <TextField source="comment" />,
sync: <ToggleAutoImport source="sync" sortByOrder={'DESC'} />,
}),
[isDesktop, isXsmall],
)
const columns = useSelectedFields({
resource: 'playlist',
columns: toggleableFields,
defaultOff: ['comment'],
})
return (
<List
{...props}
exporter={false}
sort={{ field: 'name', order: 'ASC' }}
filters={<PlaylistFilter />}
actions={<PlaylistListActions />}
bulkActionButtons={!isXsmall && <PlaylistListBulkActions />}
>
<Datagrid rowClick="show" isRowSelectable={(r) => isWritable(r?.ownerId)}>
<CoverArtField source="id" />
<TextField source="name" />
{columns}
<Writable>
<EditButton />
</Writable>
</Datagrid>
</List>
)
}
export default PlaylistList