quintodrome/ui/src/subsonic/index.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
1.8 KiB
JavaScript
Raw Normal View History

import { baseUrl } from '../utils'
2021-06-15 13:29:01 -08:00
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])
})
}
2021-06-15 13:29:01 -08:00
return `/rest/${command}?${params.toString()}`
}
const scrobble = (id, submission = false, time) =>
httpClient(
url('scrobble', id, {
...(submission && time && { time }),
submission,
})
)
const nowPlaying = (id) => scrobble(id, false)
2021-06-15 13:29:01 -08:00
const star = (id) => httpClient(url('star', id))
2021-06-15 13:29:01 -08:00
const unstar = (id) => httpClient(url('unstar', id))
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'))
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))
}
const streamUrl = (id) => {
return baseUrl(url('stream', id, { ts: true }))
}
export default {
url,
scrobble,
nowPlaying,
download,
star,
unstar,
setRating,
2021-06-15 13:29:01 -08:00
startScan,
getScanStatus,
getCoverArtUrl,
streamUrl,
}