mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 18:36:02 -05:00
[web] Clean code for better maintainability
This commit is contained in:
parent
6f6d804e44
commit
775108f088
@ -78,8 +78,8 @@ export default {
|
|||||||
return axios.post(`./api/queue/items/add?uris=${uri}`).then((response) => {
|
return axios.post(`./api/queue/items/add?uris=${uri}`).then((response) => {
|
||||||
store.dispatch('add_notification', {
|
store.dispatch('add_notification', {
|
||||||
text: t('server.appended-tracks', { count: response.data.count }),
|
text: t('server.appended-tracks', { count: response.data.count }),
|
||||||
type: 'info',
|
timeout: 2000,
|
||||||
timeout: 2000
|
type: 'info'
|
||||||
})
|
})
|
||||||
return Promise.resolve(response)
|
return Promise.resolve(response)
|
||||||
})
|
})
|
||||||
@ -97,48 +97,44 @@ export default {
|
|||||||
text: t('server.appended-tracks', {
|
text: t('server.appended-tracks', {
|
||||||
count: response.data.count
|
count: response.data.count
|
||||||
}),
|
}),
|
||||||
type: 'info',
|
timeout: 2000,
|
||||||
timeout: 2000
|
type: 'info'
|
||||||
})
|
})
|
||||||
return Promise.resolve(response)
|
return Promise.resolve(response)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
queue_expression_add(expression) {
|
queue_expression_add(expression) {
|
||||||
const options = {}
|
|
||||||
options.expression = expression
|
|
||||||
|
|
||||||
return axios
|
return axios
|
||||||
.post('./api/queue/items/add', undefined, { params: options })
|
.post('./api/queue/items/add', undefined, { params: { expression } })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
store.dispatch('add_notification', {
|
store.dispatch('add_notification', {
|
||||||
text: t('server.appended-tracks', {
|
text: t('server.appended-tracks', {
|
||||||
count: response.data.count
|
count: response.data.count
|
||||||
}),
|
}),
|
||||||
type: 'info',
|
timeout: 2000,
|
||||||
timeout: 2000
|
type: 'info'
|
||||||
})
|
})
|
||||||
return Promise.resolve(response)
|
return Promise.resolve(response)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
queue_expression_add_next(expression) {
|
queue_expression_add_next(expression) {
|
||||||
const options = {}
|
const params = {}
|
||||||
options.expression = expression
|
params.expression = expression
|
||||||
options.position = 0
|
params.position = 0
|
||||||
if (store.getters.now_playing && store.getters.now_playing.id) {
|
if (store.getters.now_playing && store.getters.now_playing.id) {
|
||||||
options.position = store.getters.now_playing.position + 1
|
params.position = store.getters.now_playing.position + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return axios
|
return axios
|
||||||
.post('./api/queue/items/add', undefined, { params: options })
|
.post('./api/queue/items/add', undefined, { params })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
store.dispatch('add_notification', {
|
store.dispatch('add_notification', {
|
||||||
text: t('server.appended-tracks', {
|
text: t('server.appended-tracks', {
|
||||||
count: response.data.count
|
count: response.data.count
|
||||||
}),
|
}),
|
||||||
type: 'info',
|
timeout: 2000,
|
||||||
timeout: 2000
|
type: 'info'
|
||||||
})
|
})
|
||||||
return Promise.resolve(response)
|
return Promise.resolve(response)
|
||||||
})
|
})
|
||||||
@ -150,8 +146,8 @@ export default {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
store.dispatch('add_notification', {
|
store.dispatch('add_notification', {
|
||||||
text: t('server.queue-saved', { name }),
|
text: t('server.queue-saved', { name }),
|
||||||
type: 'info',
|
timeout: 2000,
|
||||||
timeout: 2000
|
type: 'info'
|
||||||
})
|
})
|
||||||
return Promise.resolve(response)
|
return Promise.resolve(response)
|
||||||
})
|
})
|
||||||
@ -162,25 +158,25 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
player_play_uri(uris, shuffle, position = undefined) {
|
player_play_uri(uris, shuffle, position = undefined) {
|
||||||
const options = {}
|
const params = {
|
||||||
options.uris = uris
|
clear: 'true',
|
||||||
options.shuffle = shuffle ? 'true' : 'false'
|
playback: 'start',
|
||||||
options.clear = 'true'
|
playback_from_position: position,
|
||||||
options.playback = 'start'
|
shuffle: `${shuffle}`,
|
||||||
options.playback_from_position = position
|
uris
|
||||||
|
}
|
||||||
return axios.post('./api/queue/items/add', undefined, { params: options })
|
return axios.post('./api/queue/items/add', undefined, { params })
|
||||||
},
|
},
|
||||||
|
|
||||||
player_play_expression(expression, shuffle, position = undefined) {
|
player_play_expression(expression, shuffle, position = undefined) {
|
||||||
const options = {}
|
const params = {
|
||||||
options.expression = expression
|
clear: 'true',
|
||||||
options.shuffle = shuffle ? 'true' : 'false'
|
expression,
|
||||||
options.clear = 'true'
|
playback: 'start',
|
||||||
options.playback = 'start'
|
playback_from_position: position,
|
||||||
options.playback_from_position = position
|
shuffle: `${shuffle}`
|
||||||
|
}
|
||||||
return axios.post('./api/queue/items/add', undefined, { params: options })
|
return axios.post('./api/queue/items/add', undefined, { params })
|
||||||
},
|
},
|
||||||
|
|
||||||
player_play(options = {}) {
|
player_play(options = {}) {
|
||||||
@ -211,18 +207,16 @@ export default {
|
|||||||
return axios.put('./api/player/previous')
|
return axios.put('./api/player/previous')
|
||||||
},
|
},
|
||||||
|
|
||||||
player_shuffle(newState) {
|
player_shuffle(state) {
|
||||||
const shuffle = newState ? 'true' : 'false'
|
return axios.put(`./api/player/shuffle?state=${state}`)
|
||||||
return axios.put(`./api/player/shuffle?state=${shuffle}`)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
player_consume(newState) {
|
player_consume(state) {
|
||||||
const consume = newState ? 'true' : 'false'
|
return axios.put(`./api/player/consume?state=${state}`)
|
||||||
return axios.put(`./api/player/consume?state=${consume}`)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
player_repeat(newRepeatMode) {
|
player_repeat(mode) {
|
||||||
return axios.put(`./api/player/repeat?state=${newRepeatMode}`)
|
return axios.put(`./api/player/repeat?state=${mode}`)
|
||||||
},
|
},
|
||||||
|
|
||||||
player_volume(volume) {
|
player_volume(volume) {
|
||||||
@ -256,9 +250,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
library_artists(media_kind = undefined) {
|
library_artists(media_kind = undefined) {
|
||||||
return axios.get('./api/library/artists', {
|
return axios.get('./api/library/artists', { params: { media_kind } })
|
||||||
params: { media_kind }
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_artist(artistId) {
|
library_artist(artistId) {
|
||||||
@ -270,9 +262,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
library_albums(media_kind = undefined) {
|
library_albums(media_kind = undefined) {
|
||||||
return axios.get('./api/library/albums', {
|
return axios.get('./api/library/albums', { params: { media_kind } })
|
||||||
params: { media_kind }
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_album(albumId) {
|
library_album(albumId) {
|
||||||
@ -292,9 +282,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
library_genres(media_kind = undefined) {
|
library_genres(media_kind = undefined) {
|
||||||
return axios.get('./api/library/genres', {
|
return axios.get('./api/library/genres', { params: { media_kind } })
|
||||||
params: { media_kind }
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_genre(genre, media_kind = undefined) {
|
library_genre(genre, media_kind = undefined) {
|
||||||
@ -304,23 +292,19 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
library_genre_albums(genre, media_kind) {
|
library_genre_albums(genre, media_kind) {
|
||||||
const genreParams = {
|
const params = {
|
||||||
expression: `genre is "${genre}" and media_kind is ${media_kind}`,
|
expression: `genre is "${genre}" and media_kind is ${media_kind}`,
|
||||||
type: 'albums'
|
type: 'albums'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params: genreParams
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_genre_tracks(genre, media_kind) {
|
library_genre_tracks(genre, media_kind) {
|
||||||
const genreParams = {
|
const params = {
|
||||||
expression: `genre is "${genre}" and media_kind is ${media_kind}`,
|
expression: `genre is "${genre}" and media_kind is ${media_kind}`,
|
||||||
type: 'tracks'
|
type: 'tracks'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params: genreParams
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_radio_streams() {
|
library_radio_streams() {
|
||||||
@ -329,15 +313,11 @@ export default {
|
|||||||
media_kind: 'music',
|
media_kind: 'music',
|
||||||
expression: 'data_kind is url and song_length = 0'
|
expression: 'data_kind is url and song_length = 0'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_composers(media_kind = undefined) {
|
library_composers(media_kind = undefined) {
|
||||||
return axios.get('./api/library/composers', {
|
return axios.get('./api/library/composers', { params: { media_kind } })
|
||||||
params: { media_kind }
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_composer(composer) {
|
library_composer(composer) {
|
||||||
@ -346,55 +326,45 @@ export default {
|
|||||||
|
|
||||||
library_composer_albums(composer) {
|
library_composer_albums(composer) {
|
||||||
const params = {
|
const params = {
|
||||||
type: 'albums',
|
expression: `composer is "${composer}" and media_kind is music`,
|
||||||
expression: `composer is "${composer}" and media_kind is music`
|
type: 'albums'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_composer_tracks(composer) {
|
library_composer_tracks(composer) {
|
||||||
const params = {
|
const params = {
|
||||||
type: 'tracks',
|
expression: `composer is "${composer}" and media_kind is music`,
|
||||||
expression: `composer is "${composer}" and media_kind is music`
|
type: 'tracks'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_artist_tracks(artist) {
|
library_artist_tracks(artist) {
|
||||||
if (artist) {
|
if (artist) {
|
||||||
const artistParams = {
|
const params = {
|
||||||
type: 'tracks',
|
expression: `songartistid is "${artist}"`,
|
||||||
expression: `songartistid is "${artist}"`
|
type: 'tracks'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params: artistParams
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
library_podcasts_new_episodes() {
|
library_podcasts_new_episodes() {
|
||||||
const episodesParams = {
|
const params = {
|
||||||
type: 'tracks',
|
|
||||||
expression:
|
expression:
|
||||||
'media_kind is podcast and play_count = 0 ORDER BY time_added DESC'
|
'media_kind is podcast and play_count = 0 ORDER BY time_added DESC',
|
||||||
|
type: 'tracks'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params: episodesParams
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_podcast_episodes(albumId) {
|
library_podcast_episodes(albumId) {
|
||||||
const episodesParams = {
|
const params = {
|
||||||
type: 'tracks',
|
expression: `media_kind is podcast and songalbumid is "${albumId}" ORDER BY date_released DESC`,
|
||||||
expression: `media_kind is podcast and songalbumid is "${albumId}" ORDER BY date_released DESC`
|
type: 'tracks'
|
||||||
}
|
}
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params })
|
||||||
params: episodesParams
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
library_add(url) {
|
library_add(url) {
|
||||||
@ -436,16 +406,11 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
library_files(directory = undefined) {
|
library_files(directory = undefined) {
|
||||||
const filesParams = { directory }
|
return axios.get('./api/library/files', { params: { directory } })
|
||||||
return axios.get('./api/library/files', {
|
|
||||||
params: filesParams
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
search(searchParams) {
|
search(searchParams) {
|
||||||
return axios.get('./api/search', {
|
return axios.get('./api/search', { params: searchParams })
|
||||||
params: searchParams
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
spotify() {
|
spotify() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user