Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adapters/interfaces/persistance/i_app_info_access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace adapters
{

/**
* The IAppInfoAccess class makes the API calls to the server to query
* This class makes the API calls to the server to query
* metainformation about Librum.
*/
class ADAPTERS_EXPORT IAppInfoAccess : public QObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace adapters
{

/**
* The IAuthenticationAccess class makes the API calls to the authentication
* server.
* This class makes the API calls to the login server.
*/
class ADAPTERS_EXPORT IAuthenticationAccess : public QObject
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace adapters
{

/**
* The IDictionaryAccess class makes the API calls to the API of the used
* This class makes the API calls to the API of the used
* dictionary to retrieve definitions, etc. from it.
*/
class ADAPTERS_EXPORT IDictionaryAccess : public QObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace adapters
{

/**
* The IFolderStorageAccess class makes the API calls to the API of the used
* This class makes the API calls to the API of the used
* Folder to store folders, etc. from it.
*/
class ADAPTERS_EXPORT IFolderStorageAccess : public QObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace adapters
{

/**
* The ILibraryStorageAccess class makes the API calls to the book storage
* server.
* This class makes the API calls to the server that stores books.
*/
class ADAPTERS_EXPORT ILibraryStorageAccess : public QObject
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace adapters
{

/**
* The IUserStorageAccess class makes the API calls to the user storage server.
* This class makes the API calls to the user storage server.
*/
class ADAPTERS_EXPORT IUserStorageAccess : public QObject
{
Expand Down
28 changes: 14 additions & 14 deletions src/infrastructure/data/endpoints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace infrastructure::data
inline const QString freeBooksDomain { "https://freebooks.librumreader.com" };

// Authentication
inline const QString authenticationEndpoint { "/authentication/login" };
inline const QString registrationEndpoint { "/authentication/register" };
inline const QString loginEndpoint { "/authentication/login" };
inline const QString registerEndpoint { "/authentication/register" };
inline const QString checkIfEmailConfirmedEndpoint {
"/authentication/checkIfEmailConfirmed"
};
Expand All @@ -25,16 +25,16 @@ inline const QString aiCompletionEndpoint { "/Ai/complete" };
inline const QString aiTranslationEndpoint { "/Ai/translate" };

// Library storage
inline const QString bookCreationEndpoint { "/book" };
inline const QString bookCreateEndpoint { "/book" };
inline const QString bookUpdateEndpoint { "/book" };
inline const QString bookDeletionEndpoint { "/book" };
inline const QString booksMetadataGetEndpoint { "/book" };
inline const QString uploadBookDataEndpoint { "/book/bookData" };
inline const QString downloadBookDataEndpoint { "/book/bookData" };
inline const QString getBookCoverEndpoint { "/book/cover" };
inline const QString changeBookCoverEndpoint { "/book/cover" };
inline const QString deleteBookCoverEndpoint { "/book/cover" };
inline const QString getUsedBookStorageEndpoint { "/book/usedBookStorage" };
inline const QString bookDeleteEndpoint { "/book" };
inline const QString getBooksMetadataEndpoint { "/book" };
inline const QString bookDataUploadEndpoint { "/book/bookData" };
inline const QString bookDataDownloadEndpoint { "/book/bookData" };
inline const QString bookCoverGetEndpoint { "/book/cover" };
inline const QString bookCoverChangeEndpoint { "/book/cover" };
inline const QString bookCoverDeleteEndpoint { "/book/cover" };
inline const QString usedBookStorageGetEndpoint { "/book/usedBookStorage" };

// Folder storage
inline const QString folderGetEndpoint { "/folder" };
Expand All @@ -46,11 +46,11 @@ inline const QString getFreeBooksMetadataEndpoint { freeBooksDomain +

// User storage
inline const QString userGetEndpoint { "/user" };
inline const QString userPatchEndpoint { "/user" };
inline const QString userUpdateEndpoint { "/user" };
inline const QString userDeleteEndpoint { "/user" };
inline const QString userForgotPasswordEndpoint { "/user/forgotPassword" };
inline const QString userChangePasswordEndpoint { "/user" };
inline const QString userProfilePictureEndpoint { "/user/profilePicture" };
inline const QString userPasswordForgotEndpoint { "/user/forgotPassword" };
inline const QString userPasswordChangeEndpoint { "/user" };

// Dictionary API
inline const QString dictionaryDefinitionEndpoint {
Expand Down
8 changes: 4 additions & 4 deletions src/infrastructure/persistance/ai_tools_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ namespace infrastructure::persistence

AiToolsAccess::AiToolsAccess()
{
QSettings settings;
domain = settings.value("serverHost").toString();
QSettings appSettings;
m_serverHost = appSettings.value("serverHost").toString();
}

void AiToolsAccess::getExplanation(const QString& authToken,
const QString& query, const QString& mode)
{
auto request =
createRequest(domain + data::aiCompletionEndpoint, authToken);
createRequest(m_serverHost + data::aiCompletionEndpoint, authToken);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::AlwaysNetwork);

Expand Down Expand Up @@ -90,7 +90,7 @@ void AiToolsAccess::getTranslation(const QString& authToken,
const QString& targetLang)
{
auto request =
createRequest(domain + data::aiTranslationEndpoint, authToken);
createRequest(m_serverHost + data::aiTranslationEndpoint, authToken);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::AlwaysNetwork);

Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/persistance/ai_tools_access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AiToolsAccess : public adapters::IAiToolsAccess
QDateTime m_lastRequestStartTime;

QNetworkAccessManager m_networkAccessManager;
QString domain;
QString m_serverHost;
};

} // namespace infrastructure::persistence
76 changes: 39 additions & 37 deletions src/infrastructure/persistance/authentication_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace infrastructure::persistence

AuthenticationAccess::AuthenticationAccess()
{
QSettings settings;
domain = settings.value("serverHost").toString();
QSettings appSettings;
m_serverHost = appSettings.value("serverHost").toString();
}

void AuthenticationAccess::authenticateUser(const LoginDto& loginDto)
{
auto request = createRequest(domain + data::authenticationEndpoint);
auto request = createRequest(m_serverHost + data::loginEndpoint);

QJsonObject jsonObject;
jsonObject["email"] = loginDto.email;
Expand All @@ -24,54 +24,57 @@ void AuthenticationAccess::authenticateUser(const LoginDto& loginDto)
QJsonDocument jsonDocument { jsonObject };
QByteArray data = jsonDocument.toJson(QJsonDocument::Compact);

auto reply = m_networkAccessManager.post(request, data);
auto result = m_networkAccessManager.post(request, data);

// handle ssl errors
connect(reply, &QNetworkReply::sslErrors, this,
[reply](const QList<QSslError>& errors)
// Handle authentication result and release the reply's memory
connect(result, &QNetworkReply::finished, this,
[this, result]()
{
qWarning() << "SSL Errors: " << reply->errorString();
for(int i = 0; i < errors.count(); ++i)
if(api_error_helper::apiRequestFailed(result, 200))
{
qWarning() << errors[i].errorString();
auto errorCode = api_error_helper::logErrorMessage(
result, "Authentication");

emit authenticationFinished("", errorCode);
result->deleteLater();
return;
}

QSettings settings;
if(settings.value("selfHosted").toString() == "true")
reply->ignoreSslErrors();
result->setReadBufferSize(1000);
QString authenticationToken =
QString::fromUtf8(result->readAll());
emit authenticationFinished(authenticationToken);
result->deleteLater();
});

connect(reply, &QNetworkReply::errorOccurred, this,
[reply](QNetworkReply::NetworkError)
// Process the case of ssl errors occuring
connect(result, &QNetworkReply::sslErrors, this,
[result](const QList<QSslError>& sslErrors)
{
qWarning() << "Error " << reply->errorString();
});

qWarning() << "Last SSL Error: " << result->errorString();

// Handle authentication result and release the reply's memory
connect(reply, &QNetworkReply::finished, this,
[this, reply]()
{
if(api_error_helper::apiRequestFailed(reply, 200))
for(const auto& error : sslErrors)
{
auto errorCode = api_error_helper::logErrorMessage(
reply, "Authentication");

emit authenticationFinished("", errorCode);
reply->deleteLater();
return;
qWarning() << error.errorString();
}

reply->setReadBufferSize(1000);
QString token = QString::fromUtf8(reply->readAll());
emit authenticationFinished(token);
reply->deleteLater();
QSettings appSettings;

if(appSettings.value("selfHosted").toString() == "true")
result->ignoreSslErrors();
});

// Process the case of network errors occuring
connect(result, &QNetworkReply::errorOccurred, this,
[result](QNetworkReply::NetworkError)
{
qWarning() << "Network Error " << result->errorString();
});
}

void AuthenticationAccess::registerUser(const RegisterDto& registerDto)
{
auto request = createRequest(domain + data::registrationEndpoint);
auto request = createRequest(m_serverHost + data::registerEndpoint);

QJsonObject jsonObject;
jsonObject["name"] = registerDto.name;
Expand All @@ -83,7 +86,6 @@ void AuthenticationAccess::registerUser(const RegisterDto& registerDto)

auto reply = m_networkAccessManager.post(request, data);


// Handle registration result and release the reply's memory
connect(reply, &QNetworkReply::finished, this,
[this, reply]()
Expand All @@ -105,8 +107,8 @@ void AuthenticationAccess::registerUser(const RegisterDto& registerDto)

void AuthenticationAccess::checkIfEmailConfirmed(const QString& email)
{
auto request = createRequest(domain + data::checkIfEmailConfirmedEndpoint +
"/" + email);
auto request = createRequest(
m_serverHost + data::checkIfEmailConfirmedEndpoint + "/" + email);

auto reply = m_networkAccessManager.get(request);

Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/persistance/authentication_access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AuthenticationAccess : public adapters::IAuthenticationAccess
QNetworkRequest createRequest(QUrl url);

QNetworkAccessManager m_networkAccessManager;
QString domain;
QString m_serverHost;
};

} // namespace infrastructure::persistence
25 changes: 14 additions & 11 deletions src/infrastructure/persistance/library_storage_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace infrastructure::persistence

LibraryStorageAccess::LibraryStorageAccess()
{
QSettings settings;
domain = settings.value("serverHost").toString();
QSettings appSettings;
m_serverHost = appSettings.value("serverHost").toString();
}

void LibraryStorageAccess::createBook(const QString& authToken,
const QJsonObject& jsonBook)
{
auto request =
createRequest(domain + data::bookCreationEndpoint, authToken);
createRequest(m_serverHost + data::bookCreateEndpoint, authToken);

QJsonDocument jsonDocument(jsonBook);
QByteArray data = jsonDocument.toJson(QJsonDocument::Compact);
Expand Down Expand Up @@ -66,7 +66,7 @@ void LibraryStorageAccess::deleteBook(const QString& authToken,
const QUuid& uuid)
{
auto request =
createRequest(domain + data::bookDeletionEndpoint, authToken);
createRequest(m_serverHost + data::bookDeleteEndpoint, authToken);

QJsonArray bookArray;
bookArray.append(QJsonValue::fromVariant(uuid));
Expand Down Expand Up @@ -94,7 +94,8 @@ void LibraryStorageAccess::deleteBook(const QString& authToken,
void LibraryStorageAccess::updateBook(const QString& authToken,
const QJsonObject& jsonBook)
{
auto request = createRequest(domain + data::bookUpdateEndpoint, authToken);
auto request =
createRequest(m_serverHost + data::bookUpdateEndpoint, authToken);

QJsonDocument jsonDocument(jsonBook);
QByteArray data = jsonDocument.toJson(QJsonDocument::Compact);
Expand Down Expand Up @@ -146,7 +147,8 @@ void LibraryStorageAccess::uploadBookCover(const QString& authToken,
bookCover->append(imagePart);


QUrl endpoint = domain + data::changeBookCoverEndpoint + "/" + stringUuid;
QUrl endpoint =
m_serverHost + data::bookCoverChangeEndpoint + "/" + stringUuid;
auto request = createRequest(endpoint, authToken);

// Reset the ContentTypeHeader since it will be set by the multipart
Expand Down Expand Up @@ -176,7 +178,7 @@ void LibraryStorageAccess::uploadBookCover(const QString& authToken,
void LibraryStorageAccess::deleteBookCover(const QString& authToken,
const QUuid& uuid)
{
QUrl endpoint = domain + data::deleteBookCoverEndpoint + "/" +
QUrl endpoint = m_serverHost + data::bookCoverDeleteEndpoint + "/" +
uuid.toString(QUuid::WithoutBraces);
auto request = createRequest(endpoint, authToken);

Expand All @@ -202,7 +204,7 @@ void LibraryStorageAccess::deleteBookCover(const QString& authToken,
void LibraryStorageAccess::getBooksMetaData(const QString& authToken)
{
auto request =
createRequest(domain + data::booksMetadataGetEndpoint, authToken);
createRequest(m_serverHost + data::getBooksMetadataEndpoint, authToken);
auto reply = m_networkAccessManager.get(request);

connect(reply, &QNetworkReply::finished, this,
Expand All @@ -217,7 +219,8 @@ void LibraryStorageAccess::downloadCoverForBook(const QString& authToken,
const QUuid& uuid)
{
QString uuidString = uuid.toString(QUuid::WithoutBraces);
QString endpoint = domain + data::getBookCoverEndpoint + "/" + uuidString;
QString endpoint =
m_serverHost + data::bookCoverGetEndpoint + "/" + uuidString;
auto request = createRequest(endpoint, authToken);
auto reply = m_networkAccessManager.get(request);

Expand All @@ -243,7 +246,7 @@ void LibraryStorageAccess::downloadCoverForBook(const QString& authToken,
void LibraryStorageAccess::downloadBookMedia(const QString& authToken,
const QUuid& uuid)
{
auto endpoint = domain + data::downloadBookDataEndpoint + "/" +
auto endpoint = m_serverHost + data::bookDataDownloadEndpoint + "/" +
uuid.toString(QUuid::WithoutBraces);
auto request = createRequest(endpoint, authToken);
auto reply = m_networkAccessManager.get(request);
Expand Down Expand Up @@ -324,7 +327,7 @@ void LibraryStorageAccess::uploadBookMedia(const QString& uuid,
}


QUrl endpoint = domain + data::uploadBookDataEndpoint + "/" + uuid;
QUrl endpoint = m_serverHost + data::bookDataUploadEndpoint + "/" + uuid;
auto request = createRequest(endpoint, authToken);

// Reset the ContentTypeHeader since it will be set by the multipart
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/persistance/library_storage_access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private slots:


QNetworkAccessManager m_networkAccessManager;
QString domain;
QString m_serverHost;
};

} // namespace infrastructure::persistence
Loading
Loading