Refactor URL builders in UI

This commit is contained in:
Deluan 2023-01-21 21:01:50 -05:00
parent 84aa094e56
commit 357c0e1e19
6 changed files with 27 additions and 21 deletions

View File

@ -1,13 +1,13 @@
import ReactJkMusicPlayer from 'navidrome-music-player'
import config, { shareInfo } from './config'
import { baseUrl } from './utils'
import { baseUrl, shareCoverUrl, shareStreamUrl } from './utils'
const SharePlayer = () => {
const list = shareInfo?.tracks.map((s) => {
return {
name: s.title,
musicSrc: baseUrl(config.publicBaseUrl + '/s/' + s.id),
cover: baseUrl(config.publicBaseUrl + '/img/' + s.id + '?size=300'),
musicSrc: shareStreamUrl(s.id),
cover: shareCoverUrl(s.id),
singer: s.artist,
duration: s.duration,
}

View File

@ -1,8 +0,0 @@
import config from '../config'
export const baseUrl = (path) => {
const base = config.baseURL || ''
const parts = [base]
parts.push(path.replace(/^\//, ''))
return parts.join('/')
}

View File

@ -1 +0,0 @@
export const docsUrl = (path) => `https://www.navidrome.org${path}`

View File

@ -1,7 +1,5 @@
export * from './baseUrl'
export * from './docsUrl'
export * from './formatters'
export * from './intersperse'
export * from './notifications'
export * from './openInNewTab'
export * from './shareUrl'
export * from './urls'

View File

@ -1,6 +0,0 @@
import config from '../config'
export const shareUrl = (path) => {
const url = new URL(config.publicBaseUrl + '/' + path, window.location.href)
return url.href
}

23
ui/src/utils/urls.js Normal file
View File

@ -0,0 +1,23 @@
import config from '../config'
export const baseUrl = (path) => {
const base = config.baseURL || ''
const parts = [base]
parts.push(path.replace(/^\//, ''))
return parts.join('/')
}
export const shareUrl = (path) => {
const url = new URL(config.publicBaseUrl + '/' + path, window.location.href)
return url.href
}
export const shareStreamUrl = (id) => {
return baseUrl(config.publicBaseUrl + '/s/' + id)
}
export const shareCoverUrl = (id) => {
return baseUrl(config.publicBaseUrl + '/img/' + id + '?size=300')
}
export const docsUrl = (path) => `https://www.navidrome.org${path}`