#2306 -- Partially revert removal of "Prefer Browser URL" setting.

This commit is contained in:
Buster "Silver Eagle" Neece 2020-01-21 00:02:06 -06:00
parent 153f7a8ec7
commit feeb8b9af1
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
5 changed files with 33 additions and 9 deletions

View File

@ -33,6 +33,18 @@ $config = [
],
],
Entity\Settings::PREFER_BROWSER_URL => [
'toggle',
[
'label' => __('Prefer Browser URL (If Available)'),
'description' => __('If this setting is set to "Yes", the browser URL will be used instead of the base URL when it\'s available. Set to "No" to always use the base URL.'),
'selected_text' => __('Yes'),
'deselected_text' => __('No'),
'default' => true,
'form_group_class' => 'col-md-6',
],
],
Entity\Settings::USE_RADIO_PROXY => [
'toggle',
[
@ -187,4 +199,8 @@ $config = [
],
];
if (!$settings->isDocker()) {
unset($config['groups']['security']['elements'][Entity\Settings::ENABLE_FTP_SERVER]);
}
return $config;

View File

@ -13,6 +13,7 @@ class Settings extends AbstractFixture
Entity\Settings::BASE_URL => getenv('INIT_BASE_URL') ?? 'docker.local',
Entity\Settings::INSTANCE_NAME => getenv('INIT_INSTANCE_NAME') ?? 'local test',
Entity\Settings::GEOLITE_LICENSE_KEY => getenv('INIT_GEOLITE_LICENSE_KEY') ?? '',
Entity\Settings::PREFER_BROWSER_URL => 1,
Entity\Settings::SETUP_COMPLETE => time(),
Entity\Settings::USE_RADIO_PROXY => 1,
Entity\Settings::SEND_ERROR_REPORTS => 0,

View File

@ -12,10 +12,11 @@ class Settings
// Predefined settings constants.
public const BASE_URL = 'base_url';
public const INSTANCE_NAME = 'instance_name';
public const PREFER_BROWSER_URL = 'prefer_browser_url';
public const USE_RADIO_PROXY = 'use_radio_proxy';
public const HISTORY_KEEP_DAYS = 'history_keep_days';
public const ALWAYS_USE_SSL = 'always_use_ssl';
public const API_ACCESS_CONTROL = 'api_access_control';
public const NOWPLAYING_USE_WEBSOCKETS = 'nowplaying_use_websockets';

View File

@ -40,12 +40,15 @@ class Router extends \Azura\Http\Router
$use_https = true;
}
$ignored_hosts = ['web', 'nginx', 'localhost'];
if (!in_array($current_uri->getHost(), $ignored_hosts, true)) {
$base_url = (new Uri())
->withScheme($current_uri->getScheme())
->withHost($current_uri->getHost())
->withPort($current_uri->getPort());
$prefer_browser_url = (bool)$this->settingsRepo->getSetting(Entity\Settings::PREFER_BROWSER_URL, 0);
if ($prefer_browser_url || $base_url->getHost() === '') {
$ignored_hosts = ['web', 'nginx', 'localhost'];
if (!in_array($current_uri->getHost(), $ignored_hosts, true)) {
$base_url = (new Uri())
->withScheme($current_uri->getScheme())
->withHost($current_uri->getHost())
->withPort($current_uri->getPort());
}
}
}

View File

@ -40,6 +40,9 @@ class Api
Entity\AuditLog::setCurrentUser($api_user);
}
// Set default cache control for API pages.
$prefer_browser_url = (bool)$this->settings_repo->getSetting(Entity\Settings::PREFER_BROWSER_URL, 0);
$response = $handler->handle($request);
// Check for a user-set CORS header override.
@ -72,7 +75,7 @@ class Api
}
if ($response instanceof Response) {
if ($request->getAttribute(ServerRequest::ATTR_USER) instanceof Entity\User) {
if ($prefer_browser_url || $request->getAttribute(ServerRequest::ATTR_USER) instanceof Entity\User) {
$response = $response->withNoCache();
} else {
$response = $response->withCacheLifetime(15);