Various minor cleanup
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include "core/String.hpp"
|
||||
|
||||
namespace lms::api::subsonic
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
|
||||
#include "SubsonicId.hpp"
|
||||
|
||||
#include "SubsonicResponse.hpp"
|
||||
|
||||
#include "core/ILogger.hpp"
|
||||
#include "core/String.hpp"
|
||||
|
||||
namespace lms::api::subsonic
|
||||
@@ -47,11 +44,6 @@ namespace lms::api::subsonic
|
||||
return "al-" + id.toString();
|
||||
}
|
||||
|
||||
std::string idToString(RootId)
|
||||
{
|
||||
return "root";
|
||||
}
|
||||
|
||||
std::string idToString(db::TrackId id)
|
||||
{
|
||||
return "tr-" + id.toString();
|
||||
@@ -122,15 +114,6 @@ namespace lms::core::stringUtils
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::optional<api::subsonic::RootId> readAs(std::string_view str)
|
||||
{
|
||||
if (str == "root")
|
||||
return api::subsonic::RootId{};
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template<>
|
||||
std::optional<db::TrackId> readAs(std::string_view str)
|
||||
{
|
||||
|
||||
@@ -29,25 +29,17 @@
|
||||
|
||||
namespace lms::api::subsonic
|
||||
{
|
||||
struct RootId
|
||||
{
|
||||
};
|
||||
|
||||
std::string idToString(db::ArtistId id);
|
||||
std::string idToString(db::DirectoryId id);
|
||||
std::string idToString(db::MediaLibraryId id);
|
||||
std::string idToString(db::ReleaseId id);
|
||||
std::string idToString(db::TrackId id);
|
||||
std::string idToString(db::TrackListId id);
|
||||
std::string idToString(RootId);
|
||||
} // namespace lms::api::subsonic
|
||||
|
||||
// Used to parse parameters
|
||||
namespace lms::core::stringUtils
|
||||
{
|
||||
template<>
|
||||
std::optional<api::subsonic::RootId> readAs(std::string_view str);
|
||||
|
||||
template<>
|
||||
std::optional<db::ArtistId> readAs(std::string_view str);
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "core/LiteralString.hpp"
|
||||
#include "core/Service.hpp"
|
||||
#include "core/String.hpp"
|
||||
#include "core/Utils.hpp"
|
||||
#include "database/Db.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/User.hpp"
|
||||
@@ -39,7 +38,6 @@
|
||||
#include "ParameterParsing.hpp"
|
||||
#include "ProtocolVersion.hpp"
|
||||
#include "RequestContext.hpp"
|
||||
#include "SubsonicId.hpp"
|
||||
#include "SubsonicResponse.hpp"
|
||||
#include "endpoints/AlbumSongLists.hpp"
|
||||
#include "endpoints/Bookmarks.hpp"
|
||||
@@ -105,8 +103,8 @@ namespace lms::api::subsonic
|
||||
auto censorValue = [](const std::string& type, const std::string& value) -> std::string {
|
||||
if (type == "p" || type == "password")
|
||||
return "*REDACTED*";
|
||||
else
|
||||
return value;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
std::string res;
|
||||
@@ -138,7 +136,7 @@ namespace lms::api::subsonic
|
||||
throw UserNotAuthorizedError{};
|
||||
}
|
||||
|
||||
Response handleNotImplemented(RequestContext&)
|
||||
Response handleNotImplemented(RequestContext& /*context*/)
|
||||
{
|
||||
throw NotImplementedGenericError{};
|
||||
}
|
||||
@@ -292,6 +290,18 @@ namespace lms::api::subsonic
|
||||
|
||||
throw UserNotAuthorizedError{};
|
||||
}
|
||||
|
||||
ClientInfo getClientInfo(const Wt::Http::Request& request)
|
||||
{
|
||||
const auto& parameters{ request.getParameterMap() };
|
||||
ClientInfo res;
|
||||
|
||||
// Mandatory parameters
|
||||
res.name = getMandatoryParameterAs<std::string>(parameters, "c");
|
||||
res.version = getMandatoryParameterAs<ProtocolVersion>(parameters, "v");
|
||||
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
SubsonicResource::SubsonicResource(db::Db& db)
|
||||
@@ -403,25 +413,13 @@ namespace lms::api::subsonic
|
||||
throw ClientMustUpgradeError{};
|
||||
if (client.minor > server.minor)
|
||||
throw ServerMustUpgradeError{};
|
||||
else if (client.minor == server.minor)
|
||||
if (client.minor == server.minor)
|
||||
{
|
||||
if (client.patch > server.patch)
|
||||
throw ServerMustUpgradeError{};
|
||||
}
|
||||
}
|
||||
|
||||
ClientInfo SubsonicResource::getClientInfo(const Wt::Http::Request& request)
|
||||
{
|
||||
const auto& parameters{ request.getParameterMap() };
|
||||
ClientInfo res;
|
||||
|
||||
// Mandatory parameters
|
||||
res.name = getMandatoryParameterAs<std::string>(parameters, "c");
|
||||
res.version = getMandatoryParameterAs<ProtocolVersion>(parameters, "v");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
RequestContext SubsonicResource::buildRequestContext(const Wt::Http::Request& request)
|
||||
{
|
||||
const Wt::Http::ParameterMap& parameters{ request.getParameterMap() };
|
||||
|
||||
@@ -25,10 +25,8 @@
|
||||
#include <Wt/Http/Response.h>
|
||||
#include <Wt/WResource.h>
|
||||
|
||||
#include "database/Types.hpp"
|
||||
#include "database/UserId.hpp"
|
||||
|
||||
#include "ClientInfo.hpp"
|
||||
#include "RequestContext.hpp"
|
||||
|
||||
namespace lms::db
|
||||
@@ -48,7 +46,6 @@ namespace lms::api::subsonic
|
||||
ProtocolVersion getServerProtocolVersion(const std::string& clientName) const;
|
||||
|
||||
static void checkProtocolVersion(ProtocolVersion client, ProtocolVersion server);
|
||||
ClientInfo getClientInfo(const Wt::Http::Request& request);
|
||||
RequestContext buildRequestContext(const Wt::Http::Request& request);
|
||||
db::UserId authenticateUser(const Wt::Http::Request& request);
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
|
||||
#include "core/Exception.hpp"
|
||||
#include "core/String.hpp"
|
||||
|
||||
#include "ProtocolVersion.hpp"
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace lms::api::subsonic
|
||||
constexpr Allocator() noexcept = default;
|
||||
|
||||
template<typename U>
|
||||
constexpr Allocator(const Allocator<MemoryResource, U>&) noexcept
|
||||
constexpr Allocator(const Allocator<MemoryResource, U>& /*allocator*/) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace lms::api::subsonic
|
||||
}
|
||||
|
||||
// Deallocate memory pointed to by p
|
||||
void deallocate(pointer p, std::size_t) noexcept
|
||||
void deallocate(pointer p, std::size_t /*n*/) noexcept
|
||||
{
|
||||
MemoryResource::getInstance().deallocate(reinterpret_cast<std::byte*>(p));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user