From 4685d3b543b19a7bf4ac1ab81de31c20021c71a7 Mon Sep 17 00:00:00 2001 From: Nethius Date: Thu, 24 Oct 2024 19:12:53 +0400 Subject: [PATCH] bugfix/api auth data saving (#1195) * bugfix: fixed authData saving * bugfix: added serviceInfo processing from api response --- client/core/controllers/apiController.cpp | 6 ++++++ client/ui/controllers/installController.cpp | 2 ++ client/ui/models/apiCountryModel.cpp | 4 ++++ client/ui/models/apiCountryModel.h | 3 ++- client/ui/models/servers_model.cpp | 2 +- client/ui/qml/Pages2/PageSettingsApiLanguageList.qml | 2 +- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/core/controllers/apiController.cpp b/client/core/controllers/apiController.cpp index a7cbd40a..193ac481 100644 --- a/client/core/controllers/apiController.cpp +++ b/client/core/controllers/apiController.cpp @@ -37,6 +37,7 @@ namespace constexpr char userCountryCode[] = "user_country_code"; constexpr char serverCountryCode[] = "server_country_code"; constexpr char serviceType[] = "service_type"; + constexpr char serviceInfo[] = "service_info"; constexpr char aesKey[] = "aes_key"; constexpr char aesIv[] = "aes_iv"; @@ -163,6 +164,11 @@ void ApiController::fillServerConfig(const QString &protocol, const ApiControlle QVariantMap map = serverConfig.value(configKey::apiConfig).toObject().toVariantMap(); map.insert(newServerConfig.value(configKey::apiConfig).toObject().toVariantMap()); auto apiConfig = QJsonObject::fromVariantMap(map); + + if (newServerConfig.value(config_key::configVersion).toInt() == ApiConfigSources::AmneziaGateway) { + apiConfig.insert(configKey::serviceInfo, QJsonDocument::fromJson(apiResponseBody).object().value(configKey::serviceInfo).toObject()); + } + serverConfig[configKey::apiConfig] = apiConfig; return; diff --git a/client/ui/controllers/installController.cpp b/client/ui/controllers/installController.cpp index 4ac0bc32..306e7f38 100755 --- a/client/ui/controllers/installController.cpp +++ b/client/ui/controllers/installController.cpp @@ -847,6 +847,8 @@ bool InstallController::updateServiceFromApi(const int serverIndex, const QStrin newApiConfig.insert(configKey::serviceProtocol, apiConfig.value(configKey::serviceProtocol)); newServerConfig.insert(configKey::apiConfig, newApiConfig); + newServerConfig.insert(configKey::authData, authData); + newServerConfig.insert(config_key::crc, serverConfig.value(config_key::crc)); m_serversModel->editServer(newServerConfig, serverIndex); if (reloadServiceConfig) { diff --git a/client/ui/models/apiCountryModel.cpp b/client/ui/models/apiCountryModel.cpp index ae58329f..922a9d56 100644 --- a/client/ui/models/apiCountryModel.cpp +++ b/client/ui/models/apiCountryModel.cpp @@ -39,6 +39,9 @@ QVariant ApiCountryModel::data(const QModelIndex &index, int role) const case CountryNameRole: { return countryInfo.value(configKey::serverCountryName).toString(); } + case CountryImageCodeRole: { + return countryInfo.value(configKey::serverCountryCode).toString().toUpper(); + } } return QVariant(); @@ -76,5 +79,6 @@ QHash ApiCountryModel::roleNames() const QHash roles; roles[CountryNameRole] = "countryName"; roles[CountryCodeRole] = "countryCode"; + roles[CountryImageCodeRole] = "countryImageCode"; return roles; } diff --git a/client/ui/models/apiCountryModel.h b/client/ui/models/apiCountryModel.h index 8789158b..b9e243d0 100644 --- a/client/ui/models/apiCountryModel.h +++ b/client/ui/models/apiCountryModel.h @@ -11,7 +11,8 @@ class ApiCountryModel : public QAbstractListModel public: enum Roles { CountryNameRole = Qt::UserRole + 1, - CountryCodeRole + CountryCodeRole, + CountryImageCodeRole }; explicit ApiCountryModel(QObject *parent = nullptr); diff --git a/client/ui/models/servers_model.cpp b/client/ui/models/servers_model.cpp index 85e5dae2..c87499a7 100644 --- a/client/ui/models/servers_model.cpp +++ b/client/ui/models/servers_model.cpp @@ -771,5 +771,5 @@ const QString ServersModel::getDefaultServerImagePathCollapsed() if (countryCode.isEmpty()) { return ""; } - return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode); + return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper()); } diff --git a/client/ui/qml/Pages2/PageSettingsApiLanguageList.qml b/client/ui/qml/Pages2/PageSettingsApiLanguageList.qml index 234e5142..120313cd 100644 --- a/client/ui/qml/Pages2/PageSettingsApiLanguageList.qml +++ b/client/ui/qml/Pages2/PageSettingsApiLanguageList.qml @@ -90,7 +90,7 @@ PageType { Layout.rightMargin: 32 Layout.alignment: Qt.AlignRight - source: "qrc:/countriesFlags/images/flagKit/" + countryCode + ".svg" + source: "qrc:/countriesFlags/images/flagKit/" + countryImageCode + ".svg" } }