Added an option ui-allow-downloads in lms.conf to enable/disable downloads, fixes #776

This commit is contained in:
emeric
2025-12-03 22:02:16 +01:00
parent 7feecb2027
commit 2d90281b11
13 changed files with 88 additions and 37 deletions
+29 -21
View File
@@ -26,9 +26,11 @@
#include <Wt/WServer.h>
#include <Wt/WStackedWidget.h>
#include "core/IConfig.hpp"
#include "core/ILogger.hpp"
#include "core/ITraceLogger.hpp"
#include "core/Service.hpp"
#include "database/IDb.hpp"
#include "database/IQueryPlanRecorder.hpp"
#include "database/Session.hpp"
@@ -198,6 +200,31 @@ namespace lms::ui
return static_cast<LmsApplication*>(Wt::WApplication::instance());
}
LmsApplication::LmsApplication(const Wt::WEnvironment& env, db::IDb& db, LmsApplicationManager& appManager, AuthenticationBackend authBackend)
: Wt::WApplication{ env }
, _db{ db }
, _appManager{ appManager }
, _authBackend{ authBackend }
, _areDownloadsEnabled(core::Service<core::IConfig>::get()->getBool("ui-allow-downloads", true))
{
try
{
init();
}
catch (LmsApplicationException& e)
{
LMS_LOG(UI, WARNING, "Caught a LmsApplication exception: " << e.what());
handleException(e);
}
catch (std::exception& e)
{
LMS_LOG(UI, ERROR, "Caught exception: " << e.what());
throw core::LmsException{ "Internal error" }; // Do not put details here at it may appear on the user rendered html
}
}
LmsApplication::~LmsApplication() = default;
db::IDb& LmsApplication::getDb()
{
return _db;
@@ -240,30 +267,11 @@ namespace lms::ui
return _user->userLoginName;
}
LmsApplication::LmsApplication(const Wt::WEnvironment& env, db::IDb& db, LmsApplicationManager& appManager, AuthenticationBackend authBackend)
: Wt::WApplication{ env }
, _db{ db }
, _appManager{ appManager }
, _authBackend{ authBackend }
bool LmsApplication::areDownloadsEnabled() const
{
try
{
init();
}
catch (LmsApplicationException& e)
{
LMS_LOG(UI, WARNING, "Caught a LmsApplication exception: " << e.what());
handleException(e);
}
catch (std::exception& e)
{
LMS_LOG(UI, ERROR, "Caught exception: " << e.what());
throw core::LmsException{ "Internal error" }; // Do not put details here at it may appear on the user rendered html
}
return _areDownloadsEnabled;
}
LmsApplication::~LmsApplication() = default;
void LmsApplication::init()
{
LMS_SCOPED_TRACE_OVERVIEW("UI", "ApplicationInit");
+3
View File
@@ -70,6 +70,8 @@ namespace lms::ui
db::UserType getUserType() const; // user must be logged in prior this call
std::string_view getUserLoginName() const; // user must be logged in prior this call
bool areDownloadsEnabled() const;
// Proxified scanner events
scanner::Events& getScannerEvents() { return _scannerEvents; }
@@ -109,6 +111,7 @@ namespace lms::ui
Wt::Signal<> _preQuit;
LmsApplicationManager& _appManager;
const AuthenticationBackend _authBackend;
const bool _areDownloadsEnabled;
scanner::Events _scannerEvents;
struct UserAuthInfo
{
+7 -3
View File
@@ -114,7 +114,7 @@ namespace lms::ui
PlayQueue::PlayQueue()
: Template{ Wt::WString::tr("Lms.PlayQueue.template") }
, _capacity{ core::Service<core::IConfig>::get()->getULong("playqueue-max-entry-count", 1000) }
, _capacity{ core::Service<core::IConfig>::get()->getULong("ui-playqueue-max-entry-count", 1000) }
{
initTrackLists();
@@ -578,8 +578,12 @@ namespace lms::ui
}
});
entry->bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackResource>(trackId) });
if (LmsApp->areDownloadsEnabled())
{
entry->setCondition("if-has-download", true);
entry->bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackResource>(trackId) });
}
}
void PlayQueue::enqueueRadioTracksIfNeeded()
+7 -2
View File
@@ -168,8 +168,13 @@ namespace lms::ui
.connect([this] {
_playQueueController.processCommand(PlayQueueController::Command::PlayOrAddLast, { _artistId });
});
bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadArtistResource>(_artistId) });
if (LmsApp->areDownloadsEnabled())
{
setCondition("if-has-download", true);
bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadArtistResource>(_artistId) });
}
{
auto isStarred{ [this] { return core::Service<feedback::IFeedbackService>::get()->isStarred(LmsApp->getUserId(), _artistId); } };
+12 -4
View File
@@ -359,8 +359,12 @@ namespace lms::ui
_playQueueController.processCommand(PlayQueueController::Command::PlayOrAddLast, { _releaseId });
});
bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadReleaseResource>(_releaseId) });
if (LmsApp->areDownloadsEnabled())
{
setCondition("if-has-download", true);
bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadReleaseResource>(_releaseId) });
}
bindNew<Wt::WPushButton>("release-info", Wt::WString::tr("Lms.Explore.release-info"))
->clicked()
@@ -527,8 +531,12 @@ namespace lms::ui
starBtn->clicked().connect([=] { toggle(); });
}
entry->bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackResource>(trackId) });
if (LmsApp->areDownloadsEnabled())
{
entry->setCondition("if-has-download", true);
entry->bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackResource>(trackId) });
}
entry->bindNew<Wt::WPushButton>("track-info", Wt::WString::tr("Lms.Explore.track-info"))
->clicked()
+6 -2
View File
@@ -299,8 +299,12 @@ namespace lms::ui::TrackListHelpers
starBtn->clicked().connect([=] { toggle(); });
}
entry->bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackResource>(trackId) });
if (LmsApp->areDownloadsEnabled())
{
entry->setCondition("if-has-download", true);
entry->bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackResource>(trackId) });
}
entry->bindNew<Wt::WPushButton>("track-info", Wt::WString::tr("Lms.Explore.track-info"))
->clicked()
+6 -2
View File
@@ -135,8 +135,12 @@ namespace lms::ui
_playQueueController.processCommand(PlayQueueController::Command::PlayOrAddLast, *trackListId);
});
bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackListResource>(*trackListId) });
if (LmsApp->areDownloadsEnabled())
{
setCondition("if-has-download", true);
bindNew<Wt::WPushButton>("download", Wt::WString::tr("Lms.Explore.download"))
->setLink(Wt::WLink{ std::make_unique<DownloadTrackListResource>(*trackListId) });
}
if (trackList->getUserId() == LmsApp->getUserId())
{