Skip to content

Commit

Permalink
bugfix/api auth data saving (#1195)
Browse files Browse the repository at this point in the history
* bugfix: fixed authData saving

* bugfix: added serviceInfo processing from api response
  • Loading branch information
Nethius authored Oct 24, 2024
1 parent 7a389e8 commit 4685d3b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions client/core/controllers/apiController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions client/ui/controllers/installController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions client/ui/models/apiCountryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -76,5 +79,6 @@ QHash<int, QByteArray> ApiCountryModel::roleNames() const
QHash<int, QByteArray> roles;
roles[CountryNameRole] = "countryName";
roles[CountryCodeRole] = "countryCode";
roles[CountryImageCodeRole] = "countryImageCode";
return roles;
}
3 changes: 2 additions & 1 deletion client/ui/models/apiCountryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class ApiCountryModel : public QAbstractListModel
public:
enum Roles {
CountryNameRole = Qt::UserRole + 1,
CountryCodeRole
CountryCodeRole,
CountryImageCodeRole
};

explicit ApiCountryModel(QObject *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion client/ui/models/servers_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
2 changes: 1 addition & 1 deletion client/ui/qml/Pages2/PageSettingsApiLanguageList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down

0 comments on commit 4685d3b

Please sign in to comment.