mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
fix: solve review...
This commit is contained in:
parent
407d737c8c
commit
b20a268e0a
@ -12,17 +12,11 @@ import { useInterval } from '../common'
|
|||||||
import { baseUrl, openInNewTab } from '../utils'
|
import { baseUrl, openInNewTab } from '../utils'
|
||||||
import { httpClient } from '../dataProvider'
|
import { httpClient } from '../dataProvider'
|
||||||
|
|
||||||
const defaultAuthUrl = 'https://www.last.fm/api/auth/'
|
|
||||||
|
|
||||||
const buildAuthUrl = (authUrl, apiKey, callbackUrl) => {
|
const buildAuthUrl = (authUrl, apiKey, callbackUrl) => {
|
||||||
try {
|
const url = new URL(authUrl)
|
||||||
const url = new URL(authUrl)
|
url.searchParams.set('api_key', apiKey)
|
||||||
url.searchParams.set('api_key', apiKey)
|
url.searchParams.set('cb', callbackUrl)
|
||||||
url.searchParams.set('cb', callbackUrl)
|
return url.toString()
|
||||||
return url.toString()
|
|
||||||
} catch {
|
|
||||||
return `${defaultAuthUrl}?api_key=${apiKey}&cb=${callbackUrl}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Progress = (props) => {
|
const Progress = (props) => {
|
||||||
@ -37,9 +31,15 @@ const Progress = (props) => {
|
|||||||
`/api/lastfm/link/callback?uid=${localStorage.getItem('userId')}`,
|
`/api/lastfm/link/callback?uid=${localStorage.getItem('userId')}`,
|
||||||
)
|
)
|
||||||
const callbackUrl = `${window.location.origin}${callbackEndpoint}`
|
const callbackUrl = `${window.location.origin}${callbackEndpoint}`
|
||||||
openedTab.current = openInNewTab(
|
try {
|
||||||
buildAuthUrl(authUrl || defaultAuthUrl, apiKey, callbackUrl),
|
openedTab.current = openInNewTab(
|
||||||
)
|
buildAuthUrl(authUrl, apiKey, callbackUrl),
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
setCheckingLink(false)
|
||||||
|
setLinked(false)
|
||||||
|
notify('message.lastfmLinkFailure', 'warning')
|
||||||
|
}
|
||||||
}, [apiKey, authUrl])
|
}, [apiKey, authUrl])
|
||||||
|
|
||||||
const endChecking = (success) => {
|
const endChecking = (success) => {
|
||||||
@ -89,16 +89,14 @@ export const LastfmScrobbleToggle = (props) => {
|
|||||||
const [linked, setLinked] = useState(null)
|
const [linked, setLinked] = useState(null)
|
||||||
const [checkingLink, setCheckingLink] = useState(false)
|
const [checkingLink, setCheckingLink] = useState(false)
|
||||||
const [apiKey, setApiKey] = useState(false)
|
const [apiKey, setApiKey] = useState(false)
|
||||||
const [authUrl, setAuthUrl] = useState(defaultAuthUrl)
|
const [authUrl, setAuthUrl] = useState(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
httpClient('/api/lastfm/link')
|
httpClient('/api/lastfm/link')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setLinked(response.json.status === true)
|
setLinked(response.json.status === true)
|
||||||
setApiKey(response.json.apiKey)
|
setApiKey(response.json.apiKey)
|
||||||
if (response.json.authUrl) {
|
setAuthUrl(response.json.authUrl || null)
|
||||||
setAuthUrl(response.json.authUrl)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setLinked(false)
|
setLinked(false)
|
||||||
@ -107,6 +105,10 @@ export const LastfmScrobbleToggle = (props) => {
|
|||||||
|
|
||||||
const toggleScrobble = () => {
|
const toggleScrobble = () => {
|
||||||
if (!linked) {
|
if (!linked) {
|
||||||
|
if (!authUrl) {
|
||||||
|
notify('message.lastfmLinkFailure', 'warning')
|
||||||
|
return
|
||||||
|
}
|
||||||
setCheckingLink(true)
|
setCheckingLink(true)
|
||||||
} else {
|
} else {
|
||||||
httpClient('/api/lastfm/link', { method: 'DELETE' })
|
httpClient('/api/lastfm/link', { method: 'DELETE' })
|
||||||
@ -126,7 +128,7 @@ export const LastfmScrobbleToggle = (props) => {
|
|||||||
id={'lastfm'}
|
id={'lastfm'}
|
||||||
color="primary"
|
color="primary"
|
||||||
checked={linked || checkingLink}
|
checked={linked || checkingLink}
|
||||||
disabled={!apiKey || linked === null || checkingLink}
|
disabled={!apiKey || !authUrl || linked === null || checkingLink}
|
||||||
onChange={toggleScrobble}
|
onChange={toggleScrobble}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user