mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-23 06:35:24 -07:00
Add concept of configurable WebUI URL base path
This provides the underlying support for having a configurable base path. Future commit(s) will expose this functionality to users.
This commit is contained in:
parent
d93ee05b91
commit
07b514b05a
4 changed files with 37 additions and 9 deletions
|
@ -1026,6 +1026,19 @@ void Preferences::setWebUITrustedReverseProxiesList(const QString &addr)
|
||||||
setValue(u"Preferences/WebUI/TrustedReverseProxiesList"_s, 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
|
bool Preferences::isDynDNSEnabled() const
|
||||||
{
|
{
|
||||||
return value(u"Preferences/DynDNS/Enabled"_s, false);
|
return value(u"Preferences/DynDNS/Enabled"_s, false);
|
||||||
|
|
|
@ -237,6 +237,8 @@ public:
|
||||||
void setWebUIReverseProxySupportEnabled(bool enabled);
|
void setWebUIReverseProxySupportEnabled(bool enabled);
|
||||||
QString getWebUITrustedReverseProxiesList() const;
|
QString getWebUITrustedReverseProxiesList() const;
|
||||||
void setWebUITrustedReverseProxiesList(const QString &addr);
|
void setWebUITrustedReverseProxiesList(const QString &addr);
|
||||||
|
QString getWebUIBasePath() const;
|
||||||
|
void setWebUIBasePath(const QString &path);
|
||||||
|
|
||||||
// Dynamic DNS
|
// Dynamic DNS
|
||||||
bool isDynDNSEnabled() const;
|
bool isDynDNSEnabled() const;
|
||||||
|
|
|
@ -495,6 +495,13 @@ void WebApplication::configure()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isReverseProxySupportEnabled = pref->isWebUIReverseProxySupportEnabled();
|
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)
|
if (m_isReverseProxySupportEnabled)
|
||||||
{
|
{
|
||||||
const QStringList proxyList = pref->getWebUITrustedReverseProxiesList().split(u';', Qt::SkipEmptyParts);
|
const QStringList proxyList = pref->getWebUITrustedReverseProxiesList().split(u';', Qt::SkipEmptyParts);
|
||||||
|
@ -576,20 +583,25 @@ void WebApplication::sendFile(const Path &path)
|
||||||
|
|
||||||
QByteArray data = readResult.value();
|
QByteArray data = readResult.value();
|
||||||
const QMimeType mimeType = QMimeDatabase().mimeTypeForFileNameAndData(path.data(), data);
|
const QMimeType mimeType = QMimeDatabase().mimeTypeForFileNameAndData(path.data(), data);
|
||||||
const bool isTranslatable = !m_isAltUIUsed && mimeType.inherits(u"text/plain"_s);
|
const bool isTextFile = mimeType.inherits(u"text/plain"_s);
|
||||||
|
if (isTextFile)
|
||||||
if (isTranslatable)
|
|
||||||
{
|
{
|
||||||
auto dataStr = QString::fromUtf8(data);
|
auto dataStr = QString::fromUtf8(data);
|
||||||
|
dataStr.replace(u"${BASE_PATH}"_s, m_basePath);
|
||||||
|
|
||||||
|
const bool isTranslatable = !m_isAltUIUsed;
|
||||||
|
if (isTranslatable)
|
||||||
|
{
|
||||||
// Translate the file
|
// Translate the file
|
||||||
translateDocument(dataStr);
|
translateDocument(dataStr);
|
||||||
|
|
||||||
// Add the language options
|
// Add the language options
|
||||||
if (path == (m_rootFolder / Path(PRIVATE_FOLDER) / Path(u"views/preferences.html"_s)))
|
if (path == (m_rootFolder / Path(PRIVATE_FOLDER) / Path(u"views/preferences.html"_s)))
|
||||||
dataStr.replace(u"${LANGUAGE_OPTIONS}"_s, createLanguagesOptionsHtml());
|
dataStr.replace(u"${LANGUAGE_OPTIONS}"_s, createLanguagesOptionsHtml());
|
||||||
|
}
|
||||||
|
|
||||||
data = dataStr.toUtf8();
|
data = dataStr.toUtf8();
|
||||||
m_cachedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file
|
m_cachedFiles[path] = {data, mimeType.name(), lastModified};
|
||||||
}
|
}
|
||||||
|
|
||||||
print(data, mimeType.name());
|
print(data, mimeType.name());
|
||||||
|
|
|
@ -225,6 +225,7 @@ private:
|
||||||
};
|
};
|
||||||
bool m_isAltUIUsed = false;
|
bool m_isAltUIUsed = false;
|
||||||
Path m_rootFolder;
|
Path m_rootFolder;
|
||||||
|
QString m_basePath;
|
||||||
|
|
||||||
struct CachedFile
|
struct CachedFile
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue