Changed the way services are handled

This commit is contained in:
emeric
2020-08-22 15:20:18 +02:00
parent 9fbbca97a4
commit bd7561af8e
23 changed files with 107 additions and 127 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ namespace API::Subsonic::Scan
{
Response::Node statusResponse;
const IMediaScanner::Status scanStatus {ServiceProvider<IMediaScanner>::get()->getStatus()};
const IMediaScanner::Status scanStatus {Service<IMediaScanner>::get()->getStatus()};
statusResponse.setAttribute("scanning", scanStatus.currentState == IMediaScanner::State::InProgress);
if (scanStatus.currentState == IMediaScanner::State::InProgress)
@@ -61,7 +61,7 @@ namespace API::Subsonic::Scan
Response
handleStartScan(RequestContext& context)
{
ServiceProvider<IMediaScanner>::get()->requestImmediateScan(false);
Service<IMediaScanner>::get()->requestImmediateScan(false);
Response response {Response::createOkResponse(context)};
response.addNode("scanStatus", createStatusResponseNode());
+11 -11
View File
@@ -511,10 +511,10 @@ handleChangePassword(RequestContext& context)
std::string username {getMandatoryParameterAs<std::string>(context.parameters, "username")};
std::string password {decodePasswordIfNeeded(getMandatoryParameterAs<std::string>(context.parameters, "password"))};
if (!ServiceProvider<Auth::IPasswordService>::get()->evaluatePasswordStrength(username, password))
if (!Service<Auth::IPasswordService>::get()->evaluatePasswordStrength(username, password))
throw PasswordTooWeakGenericError {};
const User::PasswordHash hash {ServiceProvider<Auth::IPasswordService>::get()->hashPassword(password)};
const User::PasswordHash hash {Service<Auth::IPasswordService>::get()->hashPassword(password)};
auto transaction {context.dbSession.createUniqueTransaction()};
@@ -593,10 +593,10 @@ handleCreateUserRequest(RequestContext& context)
std::string password {decodePasswordIfNeeded(getMandatoryParameterAs<std::string>(context.parameters, "password"))};
// Just ignore all the other fields as we don't handle them
if (!ServiceProvider<Auth::IPasswordService>::get()->evaluatePasswordStrength(username, password))
if (!Service<Auth::IPasswordService>::get()->evaluatePasswordStrength(username, password))
throw PasswordTooWeakGenericError {};
const User::PasswordHash hash {ServiceProvider<Auth::IPasswordService>::get()->hashPassword(password)};
const User::PasswordHash hash {Service<Auth::IPasswordService>::get()->hashPassword(password)};
auto transaction {context.dbSession.createUniqueTransaction()};
@@ -878,7 +878,7 @@ handleGetArtistInfoRequestCommon(RequestContext& context, bool id3)
artistInfoNode.createChild("musicBrainzId").setValue(artistMBID->getAsString());
}
auto similarArtistsId {ServiceProvider<Recommendation::IEngine>::get()->getSimilarArtists(context.dbSession, id.value, count)};
auto similarArtistsId {Service<Recommendation::IEngine>::get()->getSimilarArtists(context.dbSession, id.value, count)};
{
auto transaction {context.dbSession.createSharedTransaction()};
@@ -1107,7 +1107,7 @@ handleGetSimilarSongsRequestCommon(RequestContext& context, bool id3)
// Optional params
std::size_t count {getParameterAs<std::size_t>(context.parameters, "count").value_or(50)};
auto similarArtistsId {ServiceProvider<Recommendation::IEngine>::get()->getSimilarArtists(context.dbSession, id.value, 5)};
auto similarArtistsId {Service<Recommendation::IEngine>::get()->getSimilarArtists(context.dbSession, id.value, 5)};
auto transaction {context.dbSession.createSharedTransaction()};
@@ -1552,10 +1552,10 @@ handleUpdateUserRequest(RequestContext& context)
if (password)
{
*password = decodePasswordIfNeeded(*password);
if (!ServiceProvider<Auth::IPasswordService>::get()->evaluatePasswordStrength(username, *password))
if (!Service<Auth::IPasswordService>::get()->evaluatePasswordStrength(username, *password))
throw PasswordTooWeakGenericError {};
hash = ServiceProvider<Auth::IPasswordService>::get()->hashPassword(*password);
hash = Service<Auth::IPasswordService>::get()->hashPassword(*password);
}
auto transaction {context.dbSession.createUniqueTransaction()};
@@ -1746,10 +1746,10 @@ handleGetCoverArt(RequestContext& context, const Wt::Http::Request& /*request*/,
switch (id.type)
{
case Id::Type::Track:
data = ServiceProvider<CoverArt::IGrabber>::get()->getFromTrack(context.dbSession, id.value, CoverArt::Format::JPEG, size);
data = Service<CoverArt::IGrabber>::get()->getFromTrack(context.dbSession, id.value, CoverArt::Format::JPEG, size);
break;
case Id::Type::Release:
data = ServiceProvider<CoverArt::IGrabber>::get()->getFromRelease(context.dbSession, id.value, CoverArt::Format::JPEG, size);
data = Service<CoverArt::IGrabber>::get()->getFromRelease(context.dbSession, id.value, CoverArt::Format::JPEG, size);
break;
default:
throw BadParameterGenericError {"id"};
@@ -1909,7 +1909,7 @@ SubsonicResource::handleRequest(const Wt::Http::Request &request, Wt::Http::Resp
SessionPool::ScopedSession dbSession {_sessionPool};
switch (ServiceProvider<Auth::IPasswordService>::get()->checkUserPassword(dbSession.get(),
switch (Service<Auth::IPasswordService>::get()->checkUserPassword(dbSession.get(),
boost::asio::ip::address::from_string(request.clientAddress()),
clientInfo.user, clientInfo.password))
{