93adda66d9
* lastfm album.getInfo, getAlbuminfo(2) endpoints * ... for description and reduce not found log level * address first comments * return all images * Update migration timestamp * Handle a few edge cases * Add CoverArtPriority option to retrieve albumart from external sources * Make agents methods more descriptive * Use Last.fm name consistently Co-authored-by: Deluan <deluan@navidrome.org>
89 lines
2.2 KiB
JavaScript
89 lines
2.2 KiB
JavaScript
import { baseUrl } from '../utils'
|
|
import { httpClient } from '../dataProvider'
|
|
|
|
const url = (command, id, options) => {
|
|
const params = new URLSearchParams()
|
|
params.append('u', localStorage.getItem('username'))
|
|
params.append('t', localStorage.getItem('subsonic-token'))
|
|
params.append('s', localStorage.getItem('subsonic-salt'))
|
|
params.append('f', 'json')
|
|
params.append('v', '1.8.0')
|
|
params.append('c', 'NavidromeUI')
|
|
id && params.append('id', id)
|
|
if (options) {
|
|
if (options.ts) {
|
|
options['_'] = new Date().getTime()
|
|
delete options.ts
|
|
}
|
|
Object.keys(options).forEach((k) => {
|
|
params.append(k, options[k])
|
|
})
|
|
}
|
|
return `/rest/${command}?${params.toString()}`
|
|
}
|
|
|
|
const scrobble = (id, time, submission = true) =>
|
|
httpClient(
|
|
url('scrobble', id, {
|
|
...(submission && time && { time }),
|
|
submission,
|
|
})
|
|
)
|
|
|
|
const nowPlaying = (id) => scrobble(id, null, false)
|
|
|
|
const star = (id) => httpClient(url('star', id))
|
|
|
|
const unstar = (id) => httpClient(url('unstar', id))
|
|
|
|
const setRating = (id, rating) => httpClient(url('setRating', id, { rating }))
|
|
|
|
const download = (id, format = 'raw', bitrate = '0') =>
|
|
(window.location.href = baseUrl(url('download', id, { format, bitrate })))
|
|
|
|
const startScan = (options) => httpClient(url('startScan', null, options))
|
|
|
|
const getScanStatus = () => httpClient(url('getScanStatus'))
|
|
|
|
const getCoverArtUrl = (record, size) => {
|
|
const options = {
|
|
...(record.updatedAt && { _: record.updatedAt }),
|
|
...(size && { size }),
|
|
}
|
|
|
|
// TODO Move this logic to server. `song` and `album` should have a CoverArtID
|
|
if (record.album) {
|
|
return baseUrl(url('getCoverArt', 'mf-' + record.id, options))
|
|
} else {
|
|
return baseUrl(url('getCoverArt', 'al-' + record.id, options))
|
|
}
|
|
}
|
|
|
|
const getArtistInfo = (id) => {
|
|
return httpClient(url('getArtistInfo', id))
|
|
}
|
|
|
|
const getAlbumInfo = (id) => {
|
|
return httpClient(url('getAlbumInfo', id))
|
|
}
|
|
|
|
const streamUrl = (id) => {
|
|
return baseUrl(url('stream', id, { ts: true }))
|
|
}
|
|
|
|
export default {
|
|
url,
|
|
scrobble,
|
|
nowPlaying,
|
|
download,
|
|
star,
|
|
unstar,
|
|
setRating,
|
|
startScan,
|
|
getScanStatus,
|
|
getCoverArtUrl,
|
|
streamUrl,
|
|
getAlbumInfo,
|
|
getArtistInfo,
|
|
}
|