mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-20 09:06:38 +00:00
Normalize baseUrl behaviour
Fully normalizes the baseUrl behaviour to better match how this sort of feature works in other programs. 1. The baseUrl is always appended to paths, even the built-in `/emby` and `/mediabrowser` paths. 2. The baseUrl is set statically at class instance creation, to ensure it persists through changes until the next restart. 3. Configuration is normalized using a function when set, to ensure it's in a standard `/mypath` format with leading `/`. 4. Cleans up the conditionals around default redirects. For sanity after changing the URL, it will match *any* path that doesn't match the current baseUrl and redirect it back to the main page (with baseUrl). 5. Adds a second method, NormalizeUrlPath, to avoid lots of `+ "/" +` string manipulations which are unclean - we should always have a leading slash. 6. Sets the default baseUrl to an empty string to avoid unexpected behaviour, though this would be worked-around automatically. 7. Adds some debug logs whenever a URL is normalized, to help track down issues with this code (if any arise).
This commit is contained in:
@@ -10,6 +10,7 @@ namespace MediaBrowser.Model.Configuration
|
||||
{
|
||||
public const int DefaultHttpPort = 8096;
|
||||
public const int DefaultHttpsPort = 8920;
|
||||
private string _baseUrl;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether [enable u pn p].
|
||||
@@ -162,7 +163,36 @@ namespace MediaBrowser.Model.Configuration
|
||||
public bool SkipDeserializationForBasicTypes { get; set; }
|
||||
|
||||
public string ServerName { get; set; }
|
||||
public string BaseUrl { get; set; }
|
||||
public string BaseUrl
|
||||
{
|
||||
get => _baseUrl;
|
||||
set
|
||||
{
|
||||
_baseUrl = value;
|
||||
// Normalize the start of the string
|
||||
if (string.IsNullOrWhiteSpace(_baseUrl))
|
||||
{
|
||||
// If baseUrl is empty, set an empty prefix string
|
||||
_baseUrl = string.Empty;
|
||||
}
|
||||
else if (!_baseUrl.StartsWith("/"))
|
||||
{
|
||||
// If baseUrl was not configured with a leading slash, append one for consistency
|
||||
_baseUrl = "/" + _baseUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If baseUrl was configured with a leading slash, just return it as-is
|
||||
_baseUrl = _baseUrl;
|
||||
}
|
||||
// Normalize the end of the string
|
||||
if (_baseUrl.EndsWith("/"))
|
||||
{
|
||||
// If baseUrl was configured with a trailing slash, remove it for consistency
|
||||
_baseUrl = _baseUrl.Remove(_baseUrl.Length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string UICulture { get; set; }
|
||||
|
||||
@@ -243,7 +273,7 @@ namespace MediaBrowser.Model.Configuration
|
||||
SortRemoveCharacters = new[] { ",", "&", "-", "{", "}", "'" };
|
||||
SortRemoveWords = new[] { "the", "a", "an" };
|
||||
|
||||
BaseUrl = "jellyfin";
|
||||
BaseUrl = string.Empty;
|
||||
UICulture = "en-US";
|
||||
|
||||
MetadataOptions = new[]
|
||||
|
||||
Reference in New Issue
Block a user