Skip to content

🎧 Your Personal Streaming Service

Refactor URL builders in UI

Deluan357c0e1e19a0
diff --git a/ui/src/SharePlayer.js b/ui/src/SharePlayer.js
index 74df7b95b..2c34058cc 100644
--- a/ui/src/SharePlayer.js
+++ b/ui/src/SharePlayer.js
@@ -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,
}
diff --git a/ui/src/utils/baseUrl.js b/ui/src/utils/baseUrl.js
deleted file mode 100644
index d9f4dfb31..000000000
--- a/ui/src/utils/baseUrl.js
+++ /dev/null
@@ -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('/')
-}
diff --git a/ui/src/utils/docsUrl.js b/ui/src/utils/docsUrl.js
deleted file mode 100644
index 2507cc27e..000000000
--- a/ui/src/utils/docsUrl.js
+++ /dev/null
@@ -1 +0,0 @@
-export const docsUrl = (path) => `https://www.navidrome.org${path}`
diff --git a/ui/src/utils/index.js b/ui/src/utils/index.js
index 18c6ced2f..779b6f886 100644
--- a/ui/src/utils/index.js
+++ b/ui/src/utils/index.js
@@ -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'
diff --git a/ui/src/utils/shareUrl.js b/ui/src/utils/shareUrl.js
deleted file mode 100644
index d93add9ce..000000000
--- a/ui/src/utils/shareUrl.js
+++ /dev/null
@@ -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
-}
diff --git a/ui/src/utils/urls.js b/ui/src/utils/urls.js
new file mode 100644
index 000000000..427e15326
--- /dev/null
+++ b/ui/src/utils/urls.js
@@ -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}`