From 7b596ec794933fbee7f48c1bc8d6712fae52594c Mon Sep 17 00:00:00 2001 From: Rechner Fox <659028+rechner@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:49:15 -0700 Subject: [PATCH] Add custom URL prefix for HTTP URLs (#1260) Co-authored-by: Johannes Pohl --- server/etc/snapserver.conf | 18 +++++++++++------- server/server_settings.hpp | 1 + server/snapserver.cpp | 1 + server/streamreader/pcm_stream.cpp | 6 +++++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/server/etc/snapserver.conf b/server/etc/snapserver.conf index 2061751a..f17e4333 100644 --- a/server/etc/snapserver.conf +++ b/server/etc/snapserver.conf @@ -24,8 +24,8 @@ # Number of additional worker threads to use # - For values < 0 the number of threads will be 2 (on single and dual cores) # or 4 (for quad and more cores) -# - 0 will utilize just the processes main thread and might cause audio drops -# in case there are a couple of longer running tasks, such as encoding +# - 0 will utilize just the processes main thread and might cause audio drops +# in case there are a couple of longer running tasks, such as encoding # multiple audio streams #threads = -1 @@ -41,7 +41,7 @@ # if empty, data dir will be # - "/var/lib/snapserver/" when running as daemon # - "$HOME/.config/snapserver/" when not running as daemon -#datadir = +#datadir = # ############################################################################### @@ -97,9 +97,13 @@ doc_root = /usr/share/snapserver/snapweb # Hostname or IP under which clients can reach this host # used to serve cached cover art -# use as placeholder for your actual host name +# use as placeholder for your actual host name #host = +# Optional custom URL prefix for generated URLs where clients can reach +# cached album art, to e.g. match scheme behind a reverse proxy. +#url_prefix = https:// + # ############################################################################### @@ -170,7 +174,7 @@ source = pipe:///tmp/snapfifo?name=default # Start Snapserver with "--stream:codec=:?" to get codec specific options #codec = flac -# Default source stream read chunk size [ms]. +# Default source stream read chunk size [ms]. # The server will continously read this number of milliseconds from the source into buffer and pass this buffer to the encoder. # The encoded buffer is sent to the clients. Some codecs have a higher latency and will need more data, e.g. Flac will need ~26ms chunks #chunk_ms = 20 @@ -201,9 +205,9 @@ source = pipe:///tmp/snapfifo?name=default # log sink [null,system,stdout,stderr,file:] # when left empty: if running as daemon "system" else "stdout" -#sink = +#sink = -# log filter :[,:]* +# log filter :[,:]* # with tag = * or and level = [trace,debug,info,notice,warning,error,fatal] #filter = *:info # diff --git a/server/server_settings.hpp b/server/server_settings.hpp index e6c3165b..e9f7b717 100644 --- a/server/server_settings.hpp +++ b/server/server_settings.hpp @@ -73,6 +73,7 @@ struct ServerSettings std::vector ssl_bind_to_address{{"0.0.0.0"}}; std::string doc_root{""}; std::string host{""}; + std::string url_prefix{""}; }; struct Tcp diff --git a/server/snapserver.cpp b/server/snapserver.cpp index ec7e5e4e..4e5290a7 100644 --- a/server/snapserver.cpp +++ b/server/snapserver.cpp @@ -100,6 +100,7 @@ int main(int argc, char* argv[]) settings.http.ssl_bind_to_address.front(), &settings.http.ssl_bind_to_address[0]); conf.add>("", "http.doc_root", "serve a website from the doc_root location", settings.http.doc_root, &settings.http.doc_root); conf.add>("", "http.host", "Hostname or IP under which clients can reach this host", settings.http.host, &settings.http.host); + conf.add>("", "http.url_prefix", "URL prefix for generating album art URLs", settings.http.url_prefix, &settings.http.url_prefix); // TCP RPC settings conf.add>("", "tcp.enabled", "enable TCP Json RPC)", settings.tcp.enabled, &settings.tcp.enabled); diff --git a/server/streamreader/pcm_stream.cpp b/server/streamreader/pcm_stream.cpp index bb2169aa..a6377a68 100644 --- a/server/streamreader/pcm_stream.cpp +++ b/server/streamreader/pcm_stream.cpp @@ -541,7 +541,11 @@ void PcmStream::setProperties(const Properties& properties) auto md5 = ImageCache::instance().setImage(getName(), std::move(data), props.metadata->art_data->extension); std::stringstream url; - url << "http://" << server_settings_.http.host << ":" << server_settings_.http.port << "/__image_cache?name=" << md5; + if (server_settings_.http.url_prefix == "") { + url << "http://" << server_settings_.http.host << ":" << server_settings_.http.port << "/__image_cache?name=" << md5; + } else { + url << server_settings_.http.url_prefix << "/__image_cache?name=" << md5; + } props.metadata->art_url = url.str(); } else if (!props.metadata.has_value() || !props.metadata->art_data.has_value())