quintodrome/ui/src/subsonic/index.js
Deluan Quintão 5882889a80
feat(ui): Add Artist Radio and Shuffle options (#4186)
* Add Play Similar option

* Add pt-br translation for Play Similar

* Refactor playSimilar and add helper

* Improve Play Similar feedback

* Add artist actions bar with shuffle and radio

* Add Play Similar menu and align artist actions

* Refine artist actions and revert menu option

* fix(ui): enhance layout of ArtistActions and ArtistShow components

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(i18n): revert unused changes

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(ui): improve layout for mobile

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(ui): improve error handling for fetching similar songs

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(ui): enhance error logging for fetching songs in shuffle

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor(ui): shuffle handling to use async/await for better readability

Signed-off-by: Deluan <deluan@navidrome.org>

* refactor(ui): simplify button label handling in ArtistActions component

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
2025-06-09 17:06:10 -04:00

114 lines
2.7 KiB
JavaScript

import { baseUrl } from '../utils'
import { httpClient } from '../dataProvider'
const url = (command, id, options) => {
const username = localStorage.getItem('username')
const token = localStorage.getItem('subsonic-token')
const salt = localStorage.getItem('subsonic-salt')
if (!username || !token || !salt) {
return ''
}
const params = new URLSearchParams()
params.append('u', username)
params.append('t', token)
params.append('s', 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 ping = () => httpClient(url('ping'))
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, square) => {
const options = {
...(record.updatedAt && { _: record.updatedAt }),
...(size && { size }),
...(square && { square }),
}
// TODO Move this logic to server
if (record.album) {
return baseUrl(url('getCoverArt', 'mf-' + record.id, options))
} else if (record.albumArtist) {
return baseUrl(url('getCoverArt', 'al-' + record.id, options))
} else if (record.sync !== undefined) {
// This is a playlist
return baseUrl(url('getCoverArt', 'pl-' + record.id, options))
} else {
return baseUrl(url('getCoverArt', 'ar-' + record.id, options))
}
}
const getArtistInfo = (id) => {
return httpClient(url('getArtistInfo', id))
}
const getAlbumInfo = (id) => {
return httpClient(url('getAlbumInfo', id))
}
const getSimilarSongs2 = (id, count = 100) => {
return httpClient(url('getSimilarSongs2', id, { count }))
}
const streamUrl = (id, options) => {
return baseUrl(
url('stream', id, {
ts: true,
...options,
}),
)
}
export default {
url,
ping,
scrobble,
nowPlaying,
download,
star,
unstar,
setRating,
startScan,
getScanStatus,
getCoverArtUrl,
streamUrl,
getAlbumInfo,
getArtistInfo,
getSimilarSongs2,
}