mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-24 02:00:24 +07:00
chore: minor bugfixes (#1915)
This commit is contained in:
@@ -64,6 +64,10 @@ namespace apiDefs
|
|||||||
constexpr QLatin1String id("id");
|
constexpr QLatin1String id("id");
|
||||||
constexpr QLatin1String orderId("order_id");
|
constexpr QLatin1String orderId("order_id");
|
||||||
constexpr QLatin1String migrationCode("migration_code");
|
constexpr QLatin1String migrationCode("migration_code");
|
||||||
|
|
||||||
|
constexpr QLatin1String transactionId("transaction_id");
|
||||||
|
|
||||||
|
constexpr QLatin1String userCountryCode("user_country_code");
|
||||||
}
|
}
|
||||||
|
|
||||||
const int requestTimeoutMsecs = 12 * 1000; // 12 secs
|
const int requestTimeoutMsecs = 12 * 1000; // 12 secs
|
||||||
|
|||||||
@@ -150,7 +150,9 @@ ErrorCode GatewayController::post(const QString &endpoint, const QJsonObject api
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
bypassProxy(endpoint, requestFunction, replyProcessingFunction);
|
auto serviceType = apiPayload.value(apiDefs::key::serviceType).toString("");
|
||||||
|
auto userCountryCode = apiPayload.value(apiDefs::key::userCountryCode).toString("");
|
||||||
|
bypassProxy(endpoint, serviceType, userCountryCode, requestFunction, replyProcessingFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto errorCode = apiUtils::checkNetworkReplyErrors(sslErrors, replyErrorString, replyError, httpStatusCode, encryptedResponseBody);
|
auto errorCode = apiUtils::checkNetworkReplyErrors(sslErrors, replyErrorString, replyError, httpStatusCode, encryptedResponseBody);
|
||||||
@@ -168,7 +170,7 @@ ErrorCode GatewayController::post(const QString &endpoint, const QJsonObject api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList GatewayController::getProxyUrls()
|
QStringList GatewayController::getProxyUrls(const QString &serviceType, const QString &userCountryCode)
|
||||||
{
|
{
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setTransferTimeout(m_requestTimeoutMsecs);
|
request.setTransferTimeout(m_requestTimeoutMsecs);
|
||||||
@@ -178,15 +180,25 @@ QStringList GatewayController::getProxyUrls()
|
|||||||
QList<QSslError> sslErrors;
|
QList<QSslError> sslErrors;
|
||||||
QNetworkReply *reply;
|
QNetworkReply *reply;
|
||||||
|
|
||||||
QStringList proxyStorageUrls;
|
QStringList baseUrls;
|
||||||
if (m_isDevEnvironment) {
|
if (m_isDevEnvironment) {
|
||||||
proxyStorageUrls = QString(DEV_S3_ENDPOINT).split(", ");
|
baseUrls = QString(DEV_S3_ENDPOINT).split(", ");
|
||||||
} else {
|
} else {
|
||||||
proxyStorageUrls = QString(PROD_S3_ENDPOINT).split(", ");
|
baseUrls = QString(PROD_S3_ENDPOINT).split(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray key = m_isDevEnvironment ? DEV_AGW_PUBLIC_KEY : PROD_AGW_PUBLIC_KEY;
|
QByteArray key = m_isDevEnvironment ? DEV_AGW_PUBLIC_KEY : PROD_AGW_PUBLIC_KEY;
|
||||||
|
|
||||||
|
QStringList proxyStorageUrls;
|
||||||
|
if (!serviceType.isEmpty()) {
|
||||||
|
for (const auto &baseUrl : baseUrls) {
|
||||||
|
proxyStorageUrls.push_back(baseUrl + "-" + serviceType + "-" + userCountryCode + ".json");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto &baseUrl : baseUrls) {
|
||||||
|
proxyStorageUrls.push_back(baseUrl + ".json");
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &proxyStorageUrl : proxyStorageUrls) {
|
for (const auto &proxyStorageUrl : proxyStorageUrls) {
|
||||||
request.setUrl(proxyStorageUrl);
|
request.setUrl(proxyStorageUrl);
|
||||||
reply = amnApp->networkManager()->get(request);
|
reply = amnApp->networkManager()->get(request);
|
||||||
@@ -231,11 +243,10 @@ QStringList GatewayController::getProxyUrls()
|
|||||||
}
|
}
|
||||||
return endpoints;
|
return endpoints;
|
||||||
} else {
|
} else {
|
||||||
QByteArray responseBody = reply->readAll();
|
|
||||||
QString replyErrorString = reply->errorString();
|
|
||||||
auto replyError = reply->error();
|
auto replyError = reply->error();
|
||||||
int httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
apiUtils::checkNetworkReplyErrors(sslErrors, replyErrorString, replyError, httpStatusCode, responseBody);
|
qDebug() << replyError;
|
||||||
|
qDebug() << httpStatusCode;
|
||||||
qDebug() << "go to the next storage endpoint";
|
qDebug() << "go to the next storage endpoint";
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
@@ -284,10 +295,11 @@ bool GatewayController::shouldBypassProxy(const QNetworkReply::NetworkError &rep
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GatewayController::bypassProxy(const QString &endpoint, std::function<QNetworkReply *(const QString &url)> requestFunction,
|
void GatewayController::bypassProxy(const QString &endpoint, const QString &serviceType, const QString &userCountryCode,
|
||||||
|
std::function<QNetworkReply *(const QString &url)> requestFunction,
|
||||||
std::function<bool(QNetworkReply *reply, const QList<QSslError> &sslErrors)> replyProcessingFunction)
|
std::function<bool(QNetworkReply *reply, const QList<QSslError> &sslErrors)> replyProcessingFunction)
|
||||||
{
|
{
|
||||||
QStringList proxyUrls = getProxyUrls();
|
QStringList proxyUrls = getProxyUrls(serviceType, userCountryCode);
|
||||||
std::random_device randomDevice;
|
std::random_device randomDevice;
|
||||||
std::mt19937 generator(randomDevice());
|
std::mt19937 generator(randomDevice());
|
||||||
std::shuffle(proxyUrls.begin(), proxyUrls.end(), generator);
|
std::shuffle(proxyUrls.begin(), proxyUrls.end(), generator);
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ public:
|
|||||||
amnezia::ErrorCode post(const QString &endpoint, const QJsonObject apiPayload, QByteArray &responseBody);
|
amnezia::ErrorCode post(const QString &endpoint, const QJsonObject apiPayload, QByteArray &responseBody);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList getProxyUrls();
|
QStringList getProxyUrls(const QString &serviceType, const QString &userCountryCode);
|
||||||
bool shouldBypassProxy(const QNetworkReply::NetworkError &replyError, const QByteArray &responseBody, bool checkEncryption,
|
bool shouldBypassProxy(const QNetworkReply::NetworkError &replyError, const QByteArray &responseBody, bool checkEncryption,
|
||||||
const QByteArray &key = "", const QByteArray &iv = "", const QByteArray &salt = "");
|
const QByteArray &key = "", const QByteArray &iv = "", const QByteArray &salt = "");
|
||||||
void bypassProxy(const QString &endpoint, std::function<QNetworkReply *(const QString &url)> requestFunction,
|
void bypassProxy(const QString &endpoint, const QString &serviceType, const QString &userCountryCode,
|
||||||
|
std::function<QNetworkReply *(const QString &url)> requestFunction,
|
||||||
std::function<bool(QNetworkReply *reply, const QList<QSslError> &sslErrors)> replyProcessingFunction);
|
std::function<bool(QNetworkReply *reply, const QList<QSslError> &sslErrors)> replyProcessingFunction);
|
||||||
|
|
||||||
int m_requestTimeoutMsecs;
|
int m_requestTimeoutMsecs;
|
||||||
|
|||||||
+2
-2
@@ -541,12 +541,12 @@ QString Settings::getGatewayEndpoint()
|
|||||||
|
|
||||||
bool Settings::isDevGatewayEnv()
|
bool Settings::isDevGatewayEnv()
|
||||||
{
|
{
|
||||||
return m_isDevGatewayEnv;
|
return value("Conf/devGatewayEnv", false).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::toggleDevGatewayEnv(bool enabled)
|
void Settings::toggleDevGatewayEnv(bool enabled)
|
||||||
{
|
{
|
||||||
m_isDevGatewayEnv = enabled;
|
setValue("Conf/devGatewayEnv", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::isHomeAdLabelVisible()
|
bool Settings::isHomeAdLabelVisible()
|
||||||
|
|||||||
@@ -254,7 +254,6 @@ private:
|
|||||||
mutable SecureQSettings m_settings;
|
mutable SecureQSettings m_settings;
|
||||||
|
|
||||||
QString m_gatewayEndpoint;
|
QString m_gatewayEndpoint;
|
||||||
bool m_isDevGatewayEnv = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ SettingsController::SettingsController(const QSharedPointer<ServersModel> &serve
|
|||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
connect(AndroidController::instance(), &AndroidController::notificationStateChanged, this, &SettingsController::onNotificationStateChanged);
|
connect(AndroidController::instance(), &AndroidController::notificationStateChanged, this, &SettingsController::onNotificationStateChanged);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
m_isDevModeEnabled = m_settings->isDevGatewayEnv();
|
||||||
|
toggleDevGatewayEnv(m_isDevModeEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getPlatformName()
|
QString getPlatformName()
|
||||||
|
|||||||
@@ -109,6 +109,34 @@ PageType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BasicButtonType {
|
||||||
|
id: devGatewayButton
|
||||||
|
objectName: "devGatewayButton"
|
||||||
|
|
||||||
|
property bool isDevGatewayEnabled: SettingsController.isDevGatewayEnv
|
||||||
|
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
|
||||||
|
implicitHeight: 36
|
||||||
|
|
||||||
|
defaultColor: AmneziaStyle.color.transparent
|
||||||
|
hoveredColor: AmneziaStyle.color.translucentWhite
|
||||||
|
pressedColor: AmneziaStyle.color.sheerWhite
|
||||||
|
disabledColor: AmneziaStyle.color.mutedGray
|
||||||
|
textColor: AmneziaStyle.color.mutedGray
|
||||||
|
borderWidth: 0
|
||||||
|
|
||||||
|
visible: SettingsController.isDevModeEnabled && isDevGatewayEnabled
|
||||||
|
text: qsTr("Dev gateway enabled")
|
||||||
|
|
||||||
|
Keys.onEnterPressed: this.clicked()
|
||||||
|
Keys.onReturnPressed: this.clicked()
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
PageController.goToPage(PageEnum.PageDevMenu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ConnectButton {
|
ConnectButton {
|
||||||
id: connectButton
|
id: connectButton
|
||||||
objectName: "connectButton"
|
objectName: "connectButton"
|
||||||
|
|||||||
Reference in New Issue
Block a user