diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 793848c98f44..68e502d0adaf 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1013,6 +1013,19 @@ void Preferences::setWebUITrustedReverseProxiesList(const QString &addr) setValue(u"Preferences/WebUI/TrustedReverseProxiesList"_s, addr); } +QString Preferences::getWebUIBasePath() const +{ + return value(u"Preferences/WebUI/BasePath"_s, u"/"_s); +} + +void Preferences::setWebUIBasePath(const QString &path) +{ + if (path == getWebUIBasePath()) + return; + + setValue(u"Preferences/WebUI/BasePath"_s, path); +} + bool Preferences::isDynDNSEnabled() const { return value(u"Preferences/DynDNS/Enabled"_s, false); diff --git a/src/base/preferences.h b/src/base/preferences.h index 3aa369576bef..7360144ee606 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -235,6 +235,8 @@ class Preferences final : public QObject void setWebUIReverseProxySupportEnabled(bool enabled); QString getWebUITrustedReverseProxiesList() const; void setWebUITrustedReverseProxiesList(const QString &addr); + QString getWebUIBasePath() const; + void setWebUIBasePath(const QString &path); // Dynamic DNS bool isDynDNSEnabled() const; diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 682cf76a12df..da22eb65872b 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -494,6 +494,13 @@ void WebApplication::configure() } m_isReverseProxySupportEnabled = pref->isWebUIReverseProxySupportEnabled(); + const QString newBasePath = m_isReverseProxySupportEnabled ? pref->getWebUIBasePath() : u"/"_s; + if (m_basePath != newBasePath) + { + m_cachedFiles.clear(); + m_basePath = newBasePath; + } + if (m_isReverseProxySupportEnabled) { const QStringList proxyList = pref->getWebUITrustedReverseProxiesList().split(u';', Qt::SkipEmptyParts); @@ -575,20 +582,25 @@ void WebApplication::sendFile(const Path &path) QByteArray data = readResult.value(); const QMimeType mimeType = QMimeDatabase().mimeTypeForFileNameAndData(path.data(), data); - const bool isTranslatable = !m_isAltUIUsed && mimeType.inherits(u"text/plain"_s); - - if (isTranslatable) + const bool isTextFile = mimeType.inherits(u"text/plain"_s); + if (isTextFile) { auto dataStr = QString::fromUtf8(data); - // Translate the file - translateDocument(dataStr); + dataStr.replace(u"${BASE_PATH}"_s, m_basePath); + + const bool isTranslatable = !m_isAltUIUsed; + if (isTranslatable) + { + // Translate the file + translateDocument(dataStr); - // Add the language options - if (path == (m_rootFolder / Path(PRIVATE_FOLDER) / Path(u"views/preferences.html"_s))) - dataStr.replace(u"${LANGUAGE_OPTIONS}"_s, createLanguagesOptionsHtml()); + // Add the language options + if (path == (m_rootFolder / Path(PRIVATE_FOLDER) / Path(u"views/preferences.html"_s))) + dataStr.replace(u"${LANGUAGE_OPTIONS}"_s, createLanguagesOptionsHtml()); + } data = dataStr.toUtf8(); - m_cachedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file + m_cachedFiles[path] = {data, mimeType.name(), lastModified}; } print(data, mimeType.name()); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index a6b7c464d45b..49b69d2cbfa5 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -225,6 +225,7 @@ class WebApplication final : public ApplicationComponent }; bool m_isAltUIUsed = false; Path m_rootFolder; + QString m_basePath; struct CachedFile {