From 357c0e1e19a0063a3fc8d128e37206a073a6fa7e Mon Sep 17 00:00:00 2001 From: Deluan Date: Sat, 21 Jan 2023 21:01:50 -0500 Subject: [PATCH] Refactor URL builders in UI --- ui/src/SharePlayer.js | 6 +++--- ui/src/utils/baseUrl.js | 8 -------- ui/src/utils/docsUrl.js | 1 - ui/src/utils/index.js | 4 +--- ui/src/utils/shareUrl.js | 6 ------ ui/src/utils/urls.js | 23 +++++++++++++++++++++++ 6 files changed, 27 insertions(+), 21 deletions(-) delete mode 100644 ui/src/utils/baseUrl.js delete mode 100644 ui/src/utils/docsUrl.js delete mode 100644 ui/src/utils/shareUrl.js create mode 100644 ui/src/utils/urls.js diff --git a/ui/src/SharePlayer.js b/ui/src/SharePlayer.js index 74df7b95..2c34058c 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 d9f4dfb3..00000000 --- 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 2507cc27..00000000 --- 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 18c6ced2..779b6f88 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 d93add9c..00000000 --- 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 00000000..427e1532 --- /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}`