2020-11-10 15:27:28 -09:00
|
|
|
import { baseUrl } from '../utils'
|
2021-06-15 13:29:01 -08:00
|
|
|
import { httpClient } from '../dataProvider'
|
2020-03-31 10:27:39 -08:00
|
|
|
|
|
|
|
|
const url = (command, id, options) => {
|
2020-02-15 10:20:04 -09:00
|
|
|
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')
|
2020-11-07 20:06:48 -09:00
|
|
|
id && params.append('id', id)
|
2020-02-07 08:36:26 -09:00
|
|
|
if (options) {
|
2020-02-15 10:20:04 -09:00
|
|
|
if (options.ts) {
|
|
|
|
|
options['_'] = new Date().getTime()
|
|
|
|
|
delete options.ts
|
|
|
|
|
}
|
|
|
|
|
Object.keys(options).forEach((k) => {
|
|
|
|
|
params.append(k, options[k])
|
|
|
|
|
})
|
2020-02-07 08:36:26 -09:00
|
|
|
}
|
2021-06-15 13:29:01 -08:00
|
|
|
return `/rest/${command}?${params.toString()}`
|
2020-02-07 08:36:26 -09:00
|
|
|
}
|
|
|
|
|
|
2021-06-23 05:19:58 -08:00
|
|
|
const scrobble = (id, submission = false, time) =>
|
|
|
|
|
httpClient(
|
|
|
|
|
url('scrobble', id, {
|
|
|
|
|
...(submission && time && { time }),
|
|
|
|
|
submission,
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const nowPlaying = (id) => scrobble(id, false)
|
2020-03-31 10:27:39 -08:00
|
|
|
|
2021-06-15 13:29:01 -08:00
|
|
|
const star = (id) => httpClient(url('star', id))
|
2020-10-03 16:06:38 -08:00
|
|
|
|
2021-06-15 13:29:01 -08:00
|
|
|
const unstar = (id) => httpClient(url('unstar', id))
|
2020-10-03 16:06:38 -08:00
|
|
|
|
2021-06-15 13:29:01 -08:00
|
|
|
const setRating = (id, rating) => httpClient(url('setRating', id, { rating }))
|
|
|
|
|
|
|
|
|
|
const download = (id) => (window.location.href = baseUrl(url('download', id)))
|
|
|
|
|
|
|
|
|
|
const startScan = (options) => httpClient(url('startScan', null, options))
|
|
|
|
|
|
|
|
|
|
const getScanStatus = () => httpClient(url('getScanStatus'))
|
2020-08-05 10:57:59 -08:00
|
|
|
|
2021-03-12 11:39:31 -09:00
|
|
|
const getCoverArtUrl = (record, size) => {
|
|
|
|
|
const options = {
|
|
|
|
|
...(record.updatedAt && { _: record.updatedAt }),
|
|
|
|
|
...(size && { size }),
|
|
|
|
|
}
|
2021-06-15 13:29:01 -08:00
|
|
|
return baseUrl(url('getCoverArt', record.coverArtId || 'not_found', options))
|
2021-03-12 11:39:31 -09:00
|
|
|
}
|
|
|
|
|
|
2021-06-16 12:38:50 -08:00
|
|
|
const streamUrl = (id) => {
|
|
|
|
|
return baseUrl(url('stream', id, { ts: true }))
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 11:39:31 -09:00
|
|
|
export default {
|
|
|
|
|
url,
|
|
|
|
|
scrobble,
|
2021-06-23 05:19:58 -08:00
|
|
|
nowPlaying,
|
2021-03-12 11:39:31 -09:00
|
|
|
download,
|
|
|
|
|
star,
|
|
|
|
|
unstar,
|
2021-04-07 12:02:52 -08:00
|
|
|
setRating,
|
2021-06-15 13:29:01 -08:00
|
|
|
startScan,
|
|
|
|
|
getScanStatus,
|
|
|
|
|
getCoverArtUrl,
|
2021-06-16 12:38:50 -08:00
|
|
|
streamUrl,
|
2021-03-12 11:39:31 -09:00
|
|
|
}
|