Add download for songs

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