From 8bccf93e27cc737d30917c907431796375a9fe8e Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Tue, 14 May 2024 08:57:42 +0100 Subject: [PATCH 1/2] feat: Make DLNA port configurable #4760 Signed-off-by: Ivan Pedrazas --- internal/dlna/service.go | 5 +++-- internal/manager/config/config.go | 19 +++++++++++++++++++ .../manager/config/config_concurrency_test.go | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/internal/dlna/service.go b/internal/dlna/service.go index 955edf6e05c..07f41608441 100644 --- a/internal/dlna/service.go +++ b/internal/dlna/service.go @@ -76,6 +76,7 @@ type Config interface { GetDLNAServerName() string GetDLNADefaultIPWhitelist() []string GetVideoSortOrder() string + GetDLNAPortAsString() string } type Service struct { @@ -138,7 +139,7 @@ func (s *Service) init() error { var dmsConfig = &dmsConfig{ Path: "", IfNames: s.config.GetDLNADefaultIPWhitelist(), - Http: ":1338", + Http: s.config.GetDLNAPortAsString(), FriendlyName: friendlyName, LogHeaders: false, NotifyInterval: 30 * time.Second, @@ -241,7 +242,7 @@ func (s *Service) Start(duration *time.Duration) error { } go func() { - logger.Info("Starting DLNA") + logger.Info("Starting DLNA " + s.server.HTTPConn.Addr().String()) if err := s.server.Serve(); err != nil { logger.Error(err) } diff --git a/internal/manager/config/config.go b/internal/manager/config/config.go index c907ac8d7d8..4b4bcd70ef2 100644 --- a/internal/manager/config/config.go +++ b/internal/manager/config/config.go @@ -6,6 +6,7 @@ import ( "path/filepath" "regexp" "runtime" + "strconv" "strings" "sync" @@ -237,6 +238,9 @@ const ( DLNAVideoSortOrder = "dlna.video_sort_order" dlnaVideoSortOrderDefault = "title" + DLNAPort = "dlna.port" + DLNAPortDefault = 1338 + // Logging options LogFile = "logFile" LogOut = "logOut" @@ -1477,6 +1481,21 @@ func (i *Config) GetDLNAInterfaces() []string { return i.getStringSlice(DLNAInterfaces) } +// GetDLNAPort returns the port to run the DLNA server on. If empty, 1338 +// will be used. +func (i *Config) GetDLNAPort() int { + ret := i.getInt(DLNAPort) + if ret == 0 { + ret = DLNAPortDefault + } + return ret +} + +// GetDLNAPortAsString returns the port to run the DLNA server on as a string. +func (i *Config) GetDLNAPortAsString() string { + return ":" + strconv.Itoa(i.GetDLNAPort()) +} + // GetVideoSortOrder returns the sort order to display videos. If // empty, videos will be sorted by titles. func (i *Config) GetVideoSortOrder() string { diff --git a/internal/manager/config/config_concurrency_test.go b/internal/manager/config/config_concurrency_test.go index 076f3a829d5..1ebe45f26ef 100644 --- a/internal/manager/config/config_concurrency_test.go +++ b/internal/manager/config/config_concurrency_test.go @@ -97,6 +97,7 @@ func TestConcurrentConfigAccess(t *testing.T) { i.Set(DLNADefaultEnabled, i.GetDLNADefaultEnabled()) i.Set(DLNADefaultIPWhitelist, i.GetDLNADefaultIPWhitelist()) i.Set(DLNAInterfaces, i.GetDLNAInterfaces()) + i.Set(DLNAPort, i.GetDLNAPort()) i.Set(LogFile, i.GetLogFile()) i.Set(LogOut, i.GetLogOut()) i.Set(LogLevel, i.GetLogLevel()) From f2458b4dd4288b32bf2e3f827f0186e2e5d969c9 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Thu, 16 May 2024 15:02:00 +1000 Subject: [PATCH 2/2] Add UI configuration --- graphql/schema/types/config.graphql | 4 ++++ internal/api/resolver_mutation_configure.go | 4 ++++ internal/api/resolver_query_configuration.go | 1 + ui/v2.5/graphql/data/config.graphql | 1 + .../components/Settings/SettingsServicesPanel.tsx | 12 ++++++++++++ ui/v2.5/src/locales/en-GB.json | 2 ++ 6 files changed, 24 insertions(+) diff --git a/graphql/schema/types/config.graphql b/graphql/schema/types/config.graphql index d98c9210065..4d6d2080b59 100644 --- a/graphql/schema/types/config.graphql +++ b/graphql/schema/types/config.graphql @@ -469,6 +469,8 @@ input ConfigDLNAInput { serverName: String "True if DLNA service should be enabled by default" enabled: Boolean + "Defaults to 1338" + port: Int "List of IPs whitelisted for DLNA service" whitelistedIPs: [String!] "List of interfaces to run DLNA on. Empty for all" @@ -481,6 +483,8 @@ type ConfigDLNAResult { serverName: String! "True if DLNA service should be enabled by default" enabled: Boolean! + "Defaults to 1338" + port: Int! "List of IPs whitelisted for DLNA service" whitelistedIPs: [String!]! "List of interfaces to run DLNA on. Empty for all" diff --git a/internal/api/resolver_mutation_configure.go b/internal/api/resolver_mutation_configure.go index c1cf987c90c..a68cbc7d788 100644 --- a/internal/api/resolver_mutation_configure.go +++ b/internal/api/resolver_mutation_configure.go @@ -576,6 +576,10 @@ func (r *mutationResolver) ConfigureDlna(ctx context.Context, input ConfigDLNAIn c.Set(config.DLNAVideoSortOrder, input.VideoSortOrder) } + if input.Port != nil { + c.Set(config.DLNAPort, *input.Port) + } + refresh := false if input.Enabled != nil { c.Set(config.DLNADefaultEnabled, *input.Enabled) diff --git a/internal/api/resolver_query_configuration.go b/internal/api/resolver_query_configuration.go index 4e8b1b5b12d..3328e4a356b 100644 --- a/internal/api/resolver_query_configuration.go +++ b/internal/api/resolver_query_configuration.go @@ -199,6 +199,7 @@ func makeConfigDLNAResult() *ConfigDLNAResult { return &ConfigDLNAResult{ ServerName: config.GetDLNAServerName(), Enabled: config.GetDLNADefaultEnabled(), + Port: config.GetDLNAPort(), WhitelistedIPs: config.GetDLNADefaultIPWhitelist(), Interfaces: config.GetDLNAInterfaces(), VideoSortOrder: config.GetVideoSortOrder(), diff --git a/ui/v2.5/graphql/data/config.graphql b/ui/v2.5/graphql/data/config.graphql index 3d4a00e6ece..7286dd0b5b2 100644 --- a/ui/v2.5/graphql/data/config.graphql +++ b/ui/v2.5/graphql/data/config.graphql @@ -111,6 +111,7 @@ fragment ConfigInterfaceData on ConfigInterfaceResult { fragment ConfigDLNAData on ConfigDLNAResult { serverName enabled + port whitelistedIPs interfaces videoSortOrder diff --git a/ui/v2.5/src/components/Settings/SettingsServicesPanel.tsx b/ui/v2.5/src/components/Settings/SettingsServicesPanel.tsx index 63137b94a78..e1322c43292 100644 --- a/ui/v2.5/src/components/Settings/SettingsServicesPanel.tsx +++ b/ui/v2.5/src/components/Settings/SettingsServicesPanel.tsx @@ -19,6 +19,7 @@ import { StringListSetting, StringSetting, SelectSetting, + NumberSetting, } from "./Inputs"; import { useSettings } from "./context"; import { @@ -31,6 +32,8 @@ import { faUserClock, } from "@fortawesome/free-solid-svg-icons"; +const defaultDLNAPort = 1338; + export const SettingsServicesPanel: React.FC = () => { const intl = useIntl(); const Toast = useToast(); @@ -417,6 +420,15 @@ export const SettingsServicesPanel: React.FC = () => { onChange={(v) => saveDLNA({ serverName: v })} /> + saveDLNA({ port: v ? v : defaultDLNAPort })} + /> +