mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-14 11:17:19 +03:00
Add download for songs
This commit is contained in:
parent
d72468003f
commit
6fe1f84c68
@ -24,7 +24,8 @@
|
||||
"addToQueue": "Adicionar à fila",
|
||||
"playNow": "Tocar agora",
|
||||
"addToPlaylist": "Adicionar à playlist",
|
||||
"shuffleAll": "Aleatório"
|
||||
"shuffleAll": "Aleatório",
|
||||
"download": "Baixar"
|
||||
}
|
||||
},
|
||||
"album": {
|
||||
|
@ -86,9 +86,9 @@ func (c *StreamController) Download(w http.ResponseWriter, r *http.Request) (*re
|
||||
}
|
||||
|
||||
setHeaders := func(name string) {
|
||||
filename := fmt.Sprintf("attachment; filename=%s.zip", name)
|
||||
filename = strings.ReplaceAll(filename, ",", "_")
|
||||
w.Header().Set("Content-Disposition", filename)
|
||||
name = strings.ReplaceAll(name, ",", "_")
|
||||
disposition := fmt.Sprintf("attachment; filename=\"%s.zip\"", name)
|
||||
w.Header().Set("Content-Disposition", disposition)
|
||||
w.Header().Set("Content-Type", "application/zip")
|
||||
}
|
||||
|
||||
@ -99,6 +99,8 @@ func (c *StreamController) Download(w http.ResponseWriter, r *http.Request) (*re
|
||||
return nil, err
|
||||
}
|
||||
|
||||
disposition := fmt.Sprintf("attachment; filename=\"%s\"", stream.Name())
|
||||
w.Header().Set("Content-Disposition", disposition)
|
||||
http.ServeContent(w, r, stream.Name(), stream.ModTime(), stream)
|
||||
return nil, nil
|
||||
case *model.Album:
|
||||
|
@ -35,22 +35,27 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
|
||||
const options = {
|
||||
play: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.playAll',
|
||||
action: (data, ids) => dispatch(playTracks(data, ids)),
|
||||
},
|
||||
addToQueue: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.addToQueue',
|
||||
action: (data, ids) => dispatch(addTracks(data, ids)),
|
||||
},
|
||||
shuffle: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.shuffle',
|
||||
action: (data, ids) => dispatch(shuffleTracks(data, ids)),
|
||||
},
|
||||
addToPlaylist: {
|
||||
needData: true,
|
||||
label: 'resources.album.actions.addToPlaylist',
|
||||
action: (data, ids) => dispatch(openAddToPlaylist({ selectedIds: ids })),
|
||||
},
|
||||
download: {
|
||||
needData: false,
|
||||
label: 'resources.album.actions.download',
|
||||
action: () => subsonic.download(record.id),
|
||||
},
|
||||
@ -80,19 +85,23 @@ const AlbumContextMenu = ({ record, discNumber, color, visible }) => {
|
||||
const handleItemClick = (e) => {
|
||||
setAnchorEl(null)
|
||||
const key = e.target.getAttribute('value')
|
||||
dataProvider
|
||||
.getList('albumSong', {
|
||||
pagination: { page: 1, perPage: -1 },
|
||||
sort: { field: 'discNumber, trackNumber', order: 'ASC' },
|
||||
filter: { album_id: record.id, disc_number: discNumber },
|
||||
})
|
||||
.then((response) => {
|
||||
let { data, ids } = extractSongsData(response)
|
||||
options[key].action(data, ids)
|
||||
})
|
||||
.catch(() => {
|
||||
notify('ra.page.error', 'warning')
|
||||
})
|
||||
if (options[key].needData) {
|
||||
dataProvider
|
||||
.getList('albumSong', {
|
||||
pagination: { page: 1, perPage: -1 },
|
||||
sort: { field: 'discNumber, trackNumber', order: 'ASC' },
|
||||
filter: { album_id: record.id, disc_number: discNumber },
|
||||
})
|
||||
.then((response) => {
|
||||
let { data, ids } = extractSongsData(response)
|
||||
options[key].action(data, ids)
|
||||
})
|
||||
.catch(() => {
|
||||
notify('ra.page.error', 'warning')
|
||||
})
|
||||
} else {
|
||||
options[key].action()
|
||||
}
|
||||
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import StarIcon from '@material-ui/icons/Star'
|
||||
import StarBorderIcon from '@material-ui/icons/StarBorder'
|
||||
import { addTracks, setTrack } from '../audioplayer'
|
||||
import { openAddToPlaylist } from '../dialogs/dialogState'
|
||||
import subsonic from '../subsonic'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
noWrap: {
|
||||
@ -39,19 +40,25 @@ const SongContextMenu = ({
|
||||
const options = {
|
||||
playNow: {
|
||||
label: 'resources.song.actions.playNow',
|
||||
action: (record) => setTrack(record),
|
||||
action: (record) => dispatch(setTrack(record)),
|
||||
},
|
||||
addToQueue: {
|
||||
label: 'resources.song.actions.addToQueue',
|
||||
action: (record) => addTracks({ [record.id]: record }),
|
||||
action: (record) => dispatch(addTracks({ [record.id]: record })),
|
||||
},
|
||||
addToPlaylist: {
|
||||
label: 'resources.song.actions.addToPlaylist',
|
||||
action: (record) =>
|
||||
openAddToPlaylist({
|
||||
selectedIds: [record.mediaFileId || record.id],
|
||||
onSuccess: (id) => onAddToPlaylist(id),
|
||||
}),
|
||||
dispatch(
|
||||
openAddToPlaylist({
|
||||
selectedIds: [record.mediaFileId || record.id],
|
||||
onSuccess: (id) => onAddToPlaylist(id),
|
||||
})
|
||||
),
|
||||
},
|
||||
download: {
|
||||
label: 'resources.song.actions.download',
|
||||
action: (record) => subsonic.download(record.id),
|
||||
},
|
||||
}
|
||||
|
||||
@ -69,7 +76,7 @@ const SongContextMenu = ({
|
||||
e.preventDefault()
|
||||
setAnchorEl(null)
|
||||
const key = e.target.getAttribute('value')
|
||||
dispatch(options[key].action(record))
|
||||
options[key].action(record)
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,8 @@
|
||||
"addToQueue": "Play Later",
|
||||
"addToPlaylist": "Add to Playlist",
|
||||
"playNow": "Play Now",
|
||||
"shuffleAll": "Shuffle All"
|
||||
"shuffleAll": "Shuffle All",
|
||||
"download": "Download"
|
||||
}
|
||||
},
|
||||
"album": {
|
||||
|
@ -26,6 +26,6 @@ const url = (command, id, options) => {
|
||||
const scrobble = (id, submit) =>
|
||||
fetchUtils.fetchJson(url('scrobble', id, { submission: submit }))
|
||||
|
||||
const download = (id, submit) => (window.location.href = url('download', id))
|
||||
const download = (id) => (window.location.href = url('download', id))
|
||||
|
||||
export default { url, scrobble, download }
|
||||
|
Loading…
x
Reference in New Issue
Block a user