honor public URL in share links

This commit is contained in:
2026-07-29 10:24:45 -05:00
parent 7059a25728
commit d3063bcc7f
3 changed files with 21 additions and 2 deletions
+3
View File
@@ -25,6 +25,9 @@ db-profile-queries = false;
# Listen port/addr of the web server
listen-port = 5082;
listen-addr = "0.0.0.0";
# Externally visible URL used in generated share links. Leave empty to infer it
# from the request. This is normally set when LMS is behind a reverse proxy.
public-url = "";
behind-reverse-proxy = false;
# original-ip-header and trusted-proxies are used only if behind-reverse-proxy is set to true
original-ip-header = "X-Forwarded-For";
@@ -24,6 +24,8 @@
#include "SubsonicResponse.hpp"
#include "database/objects/MediaLibrary.hpp"
#include "database/objects/User.hpp"
#include "core/IConfig.hpp"
#include "core/Service.hpp"
namespace lms::api::subsonic
{
@@ -59,6 +61,12 @@ namespace lms::api::subsonic
std::string RequestContext::getPublicBaseUrl() const
{
std::string publicUrl{ core::Service<core::IConfig>::get()->getString("public-url", "") };
while (publicUrl.ends_with('/'))
publicUrl.pop_back();
if (!publicUrl.empty())
return publicUrl;
std::string scheme{ _request.headerValue("X-Forwarded-Proto") };
if (scheme.empty())
scheme = _request.urlScheme();
+9 -1
View File
@@ -16,6 +16,7 @@
#include "database/objects/User.hpp"
#include "services/podcast/IPodcastService.hpp"
#include "core/Service.hpp"
#include "core/IConfig.hpp"
#include "LmsApplication.hpp"
#include "ModalManager.hpp"
@@ -36,8 +37,15 @@ namespace lms::ui::shareUtils
LmsApp->getDbSession().create<db::Share>(token, mediaId, user);
}
std::string publicUrl{ core::Service<core::IConfig>::get()->getString("public-url", "") };
while (publicUrl.ends_with('/'))
publicUrl.pop_back();
if (publicUrl.empty())
{
const auto& env{ LmsApp->environment() };
const std::string url{ env.urlScheme() + "://" + env.hostName() + "/share/" + token };
publicUrl = env.urlScheme() + "://" + env.hostName();
}
const std::string url{ publicUrl + "/share/" + token };
auto modal{ std::make_unique<Wt::WTemplate>(Wt::WString::fromUTF8(R"(
<div class="modal fade" tabindex="-1"><div class="modal-dialog"><div class="modal-content">
<div class="modal-header"><h5 class="modal-title">Share</h5>${close-x class="btn-close" data-bs-dismiss="modal" aria-label="Close"}</div>