Use defaultDownsamplingFormat in share options

This commit is contained in:
Deluan
2023-01-21 21:44:26 -05:00
parent 63b4a12a93
commit 364fdfbd8d
6 changed files with 54 additions and 37 deletions
+1
View File
@@ -61,6 +61,7 @@ func serveIndex(ds model.DataStore, fs fs.FS, shareInfo *model.Share) http.Handl
"devShowArtistPage": conf.Server.DevShowArtistPage, "devShowArtistPage": conf.Server.DevShowArtistPage,
"listenBrainzEnabled": conf.Server.ListenBrainz.Enabled, "listenBrainzEnabled": conf.Server.ListenBrainz.Enabled,
"enableReplayGain": conf.Server.EnableReplayGain, "enableReplayGain": conf.Server.EnableReplayGain,
"defaultDownsamplingFormat": conf.Server.DefaultDownsamplingFormat,
} }
if strings.HasPrefix(conf.Server.UILoginBackgroundURL, "/") { if strings.HasPrefix(conf.Server.UILoginBackgroundURL, "/") {
appConfig["loginBackgroundURL"] = path.Join(conf.Server.BaseURL, conf.Server.UILoginBackgroundURL) appConfig["loginBackgroundURL"] = path.Join(conf.Server.BaseURL, conf.Server.UILoginBackgroundURL)
+10
View File
@@ -234,6 +234,16 @@ var _ = Describe("serveIndex", func() {
Expect(config).To(HaveKeyWithValue("devEnableShare", false)) Expect(config).To(HaveKeyWithValue("devEnableShare", false))
}) })
It("sets the defaultDownsamplingFormat", func() {
r := httptest.NewRequest("GET", "/index.html", nil)
w := httptest.NewRecorder()
serveIndex(ds, fs, nil)(w, r)
config := extractAppConfig(w.Body.String())
Expect(config).To(HaveKeyWithValue("defaultDownsamplingFormat", conf.Server.DefaultDownsamplingFormat))
})
It("sets the devSidebarPlaylists", func() { It("sets the devSidebarPlaylists", func() {
conf.Server.DevSidebarPlaylists = true conf.Server.DevSidebarPlaylists = true
+1
View File
@@ -28,6 +28,7 @@ const defaultConfig = {
enableCoverAnimation: true, enableCoverAnimation: true,
devShowArtistPage: true, devShowArtistPage: true,
enableReplayGain: true, enableReplayGain: true,
defaultDownsamplingFormat: 'opus',
publicBaseUrl: '/p', publicBaseUrl: '/p',
} }
+2
View File
@@ -20,3 +20,5 @@ DraggableTypes.ALL.push(
) )
export const MAX_SIDEBAR_PLAYLISTS = 100 export const MAX_SIDEBAR_PLAYLISTS = 100
export const DEFAULT_SHARE_BITRATE = 128
+12 -10
View File
@@ -16,13 +16,15 @@ import {
} from 'react-admin' } from 'react-admin'
import { useMemo, useState } from 'react' import { useMemo, useState } from 'react'
import { shareUrl } from '../utils' import { shareUrl } from '../utils'
import config from '../config'
import { DEFAULT_SHARE_BITRATE } from '../consts'
export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => { export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
const notify = useNotify() const notify = useNotify()
const [format, setFormat] = useState('') const [format, setFormat] = useState(config.defaultDownsamplingFormat)
const [maxBitRate, setMaxBitRate] = useState(0) const [maxBitRate, setMaxBitRate] = useState(DEFAULT_SHARE_BITRATE)
const [originalFormat, setUseOriginalFormat] = useState(true) const [originalFormat, setUseOriginalFormat] = useState(true)
const { data: formats, loading } = useGetList( const { data: formats, loading: loadingFormats } = useGetList(
'transcoding', 'transcoding',
{ {
page: 1, page: 1,
@@ -33,12 +35,12 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
const formatOptions = useMemo( const formatOptions = useMemo(
() => () =>
loading loadingFormats
? [] ? []
: Object.values(formats).map((f) => { : Object.values(formats).map((f) => {
return { id: f.targetFormat, name: f.targetFormat } return { id: f.targetFormat, name: f.targetFormat }
}), }),
[formats, loading] [formats, loadingFormats]
) )
const handleOriginal = (e) => { const handleOriginal = (e) => {
@@ -57,8 +59,8 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
{ {
resourceType: resource, resourceType: resource,
resourceIds: ids?.join(','), resourceIds: ids?.join(','),
format, ...(!originalFormat && { format }),
maxBitRate, ...(!originalFormat && { maxBitRate }),
}, },
{ {
onSuccess: (res) => { onSuccess: (res) => {
@@ -106,8 +108,8 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
{!originalFormat && ( {!originalFormat && (
<SelectInput <SelectInput
source="format" source="format"
defaultValue={format}
choices={formatOptions} choices={formatOptions}
resettable
onChange={(event) => { onChange={(event) => {
setFormat(event.target.value) setFormat(event.target.value)
}} }}
@@ -115,7 +117,8 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
)} )}
{!originalFormat && ( {!originalFormat && (
<SelectInput <SelectInput
source="bitrate" source="maxBitRate"
defaultValue={maxBitRate}
choices={[ choices={[
{ id: 32, name: '32' }, { id: 32, name: '32' },
{ id: 48, name: '48' }, { id: 48, name: '48' },
@@ -129,7 +132,6 @@ export const ShareDialog = ({ open, close, onClose, ids, resource, title }) => {
{ id: 256, name: '256' }, { id: 256, name: '256' },
{ id: 320, name: '320' }, { id: 320, name: '320' },
]} ]}
resettable
onChange={(event) => { onChange={(event) => {
setMaxBitRate(event.target.value) setMaxBitRate(event.target.value)
}} }}
+3 -2
View File
@@ -9,11 +9,12 @@ import React from 'react'
import { DateField, QualityInfo } from '../common' import { DateField, QualityInfo } from '../common'
import { shareUrl } from '../utils' import { shareUrl } from '../utils'
import { Link } from '@material-ui/core' import { Link } from '@material-ui/core'
import config from '../config'
export const FormatInfo = ({ record, size }) => { export const FormatInfo = ({ record, size }) => {
const r = { suffix: record.format, bitRate: record.maxBitRate } const r = { suffix: record.format, bitRate: record.maxBitRate }
// TODO Get DefaultDownsamplingFormat r.suffix =
r.suffix = r.suffix || (r.bitRate ? 'opus' : 'Original') r.suffix || (r.bitRate ? config.defaultDownsamplingFormat : 'Original')
return <QualityInfo record={r} size={size} /> return <QualityInfo record={r} size={size} />
} }