chore: return missing code after merge with mmvm (#2553)

This commit is contained in:
vkamn
2026-05-01 20:50:24 +08:00
committed by GitHub
parent fd5051262d
commit b05ee0a654
8 changed files with 48 additions and 42 deletions

View File

@@ -332,13 +332,8 @@ ErrorCode SubscriptionController::importServiceFromAppStore(const QString &userC
appendProtocolDataToApiPayload(serviceProtocol, protocolData, apiPayload);
apiPayload[apiDefs::key::transactionId] = transactionId;
GatewayController gatewayController(m_appSettingsRepository->getGatewayEndpoint(),
m_appSettingsRepository->isDevGatewayEnv(),
apiDefs::requestTimeoutMsecs,
m_appSettingsRepository->isStrictKillSwitchEnabled());
QByteArray responseBody;
ErrorCode errorCode = gatewayController.post(QString("%1v1/subscriptions"), apiPayload, responseBody);
ErrorCode errorCode = executeRequest(QString("%1v1/subscriptions"), apiPayload, responseBody, isTestPurchase);
if (errorCode != ErrorCode::NoError) {
return errorCode;
}
@@ -351,6 +346,9 @@ ErrorCode SubscriptionController::importServiceFromAppStore(const QString &userC
return ErrorCode::ApiPurchaseError;
}
QString normalizedKey = key;
normalizedKey.replace(QStringLiteral("vpn://"), QString());
// Check if server with this VPN key already exists
for (int i = 0; i < m_serversRepository->serversCount(); ++i) {
ServerConfig existingServerConfig = m_serversRepository->server(i);
@@ -362,7 +360,8 @@ ErrorCode SubscriptionController::importServiceFromAppStore(const QString &userC
const ApiV2ServerConfig* apiV2 = existingServerConfig.as<ApiV2ServerConfig>();
existingVpnKey = apiV2 ? apiV2->vpnKey() : QString();
}
if (existingVpnKey == key) {
existingVpnKey.replace(QStringLiteral("vpn://"), QString());
if (!existingVpnKey.isEmpty() && existingVpnKey == normalizedKey) {
if (duplicateServerIndex) {
*duplicateServerIndex = i;
}
@@ -371,9 +370,6 @@ ErrorCode SubscriptionController::importServiceFromAppStore(const QString &userC
}
}
QString normalizedKey = key;
normalizedKey.replace(QStringLiteral("vpn://"), QString());
QByteArray configString = QByteArray::fromBase64(normalizedKey.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
QByteArray configUncompressed = qUncompress(configString);
if (!configUncompressed.isEmpty()) {
@@ -423,6 +419,7 @@ ErrorCode SubscriptionController::updateServiceFromGateway(int serverIndex, cons
if (!apiV2) {
return ErrorCode::InternalError;
}
const bool isTestPurchase = apiV2->apiConfig.isTestPurchase;
QString serviceProtocol = apiV2->serviceProtocol();
ProtocolData protocolData = generateProtocolData(serviceProtocol);
@@ -445,7 +442,7 @@ ErrorCode SubscriptionController::updateServiceFromGateway(int serverIndex, cons
}
QByteArray responseBody;
ErrorCode errorCode = executeRequest(QString("%1v1/config"), apiPayload, responseBody);
ErrorCode errorCode = executeRequest(QString("%1v1/config"), apiPayload, responseBody, isTestPurchase);
if (errorCode != ErrorCode::NoError) {
if (errorCode == ErrorCode::ApiSubscriptionExpiredError && !apiV2->apiConfig.isInAppPurchase) {
ServerConfig expiredServerConfig = serverConfigModel;
@@ -494,7 +491,7 @@ ErrorCode SubscriptionController::updateServiceFromGateway(int serverIndex, cons
return ErrorCode::NoError;
}
ErrorCode SubscriptionController::deactivateDevice(int serverIndex, bool isRemoveEvent)
ErrorCode SubscriptionController::deactivateDevice(int serverIndex)
{
ServerConfig serverConfigModel = m_serversRepository->server(serverIndex);
@@ -524,8 +521,9 @@ ErrorCode SubscriptionController::deactivateDevice(int serverIndex, bool isRemov
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
const bool isTestPurchase = apiV2->apiConfig.isTestPurchase;
QByteArray responseBody;
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody);
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody, isTestPurchase);
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
return errorCode;
}
@@ -567,8 +565,9 @@ ErrorCode SubscriptionController::deactivateExternalDevice(int serverIndex, cons
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
const bool isTestPurchase = apiV2->apiConfig.isTestPurchase;
QByteArray responseBody;
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody);
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody, isTestPurchase);
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
return errorCode;
}
@@ -595,6 +594,7 @@ ErrorCode SubscriptionController::exportNativeConfig(int serverIndex, const QStr
if (!apiV2) {
return ErrorCode::InternalError;
}
const bool isTestPurchase = apiV2->apiConfig.isTestPurchase;
QString protocol = configKey::awg;
ProtocolData protocolData = generateProtocolData(protocol);
@@ -613,7 +613,7 @@ ErrorCode SubscriptionController::exportNativeConfig(int serverIndex, const QStr
appendProtocolDataToApiPayload(protocol, protocolData, apiPayload);
QByteArray responseBody;
ErrorCode errorCode = executeRequest(QString("%1v1/native_config"), apiPayload, responseBody);
ErrorCode errorCode = executeRequest(QString("%1v1/native_config"), apiPayload, responseBody, isTestPurchase);
if (errorCode != ErrorCode::NoError) {
return errorCode;
}
@@ -636,6 +636,7 @@ ErrorCode SubscriptionController::revokeNativeConfig(int serverIndex, const QStr
if (!apiV2) {
return ErrorCode::InternalError;
}
const bool isTestPurchase = apiV2->apiConfig.isTestPurchase;
QString protocol = configKey::awg;
QJsonObject authDataJson = apiV2->authData.toJson();
@@ -652,7 +653,7 @@ ErrorCode SubscriptionController::revokeNativeConfig(int serverIndex, const QStr
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
QByteArray responseBody;
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_native_config"), apiPayload, responseBody);
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_native_config"), apiPayload, responseBody, isTestPurchase);
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
return errorCode;
}
@@ -746,7 +747,7 @@ ErrorCode SubscriptionController::prepareVpnKeyExport(int serverIndex, QString &
ErrorCode SubscriptionController::validateAndUpdateConfig(int serverIndex, bool hasInstalledContainers)
{
ServerConfig serverConfigModel = m_serversRepository->server(serverIndex);
apiDefs::ConfigSource configSource;
if (serverConfigModel.isApiV1()) {
configSource = apiDefs::ConfigSource::Telegram;
@@ -760,11 +761,11 @@ ErrorCode SubscriptionController::validateAndUpdateConfig(int serverIndex, bool
removeApiConfig(serverIndex);
return updateServiceFromTelegram(serverIndex);
} else if (configSource == apiDefs::ConfigSource::AmneziaGateway && !hasInstalledContainers) {
return updateServiceFromGateway(serverIndex, "", false);
return updateServiceFromGateway(serverIndex, "", true);
} else if (configSource && isApiKeyExpired(serverIndex)) {
qDebug() << "attempt to update api config by expires_at event";
if (configSource == apiDefs::ConfigSource::AmneziaGateway) {
return updateServiceFromGateway(serverIndex, "", false);
return updateServiceFromGateway(serverIndex, "", true);
} else {
removeApiConfig(serverIndex);
return updateServiceFromTelegram(serverIndex);
@@ -1062,6 +1063,7 @@ QFuture<QPair<ErrorCode, QString>> SubscriptionController::getRenewalLink(int se
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
apiPayload[apiDefs::key::cliVersion] = QString(APP_VERSION);
apiPayload[apiDefs::key::subscriptionStatus] = getSubscriptionStatusForRenewal(apiV2->apiConfig);
auto gatewayController = QSharedPointer<GatewayController>::create(m_appSettingsRepository->getGatewayEndpoint(isTestPurchase),
m_appSettingsRepository->isDevGatewayEnv(isTestPurchase),
@@ -1081,11 +1083,7 @@ QFuture<QPair<ErrorCode, QString>> SubscriptionController::getRenewalLink(int se
QJsonObject responseJson = QJsonDocument::fromJson(responseBody).object();
const QString url = responseJson.value("renewal_url").toString();
if (url.isEmpty()) {
promise->addResult(qMakePair(ErrorCode::InternalError, QString()));
} else {
promise->addResult(qMakePair(ErrorCode::NoError, url));
}
promise->addResult(qMakePair(ErrorCode::NoError, url));
promise->finish();
});
watcher->setFuture(postFuture);

View File

@@ -65,7 +65,7 @@ public:
ErrorCode updateServiceFromGateway(int serverIndex, const QString &newCountryCode, bool isConnectEvent);
ErrorCode deactivateDevice(int serverIndex, bool isRemoveEvent);
ErrorCode deactivateDevice(int serverIndex);
ErrorCode deactivateExternalDevice(int serverIndex, const QString &uuid, const QString &serverCountryCode);

View File

@@ -58,7 +58,7 @@ struct ApiConfig
QString stackType;
QString cliVersion;
bool isTestPurchase;
bool isTestPurchase = false;
bool isInAppPurchase = false;
bool subscriptionExpiredByServer = false;

View File

@@ -23,6 +23,9 @@ bool ServicesCatalogUiController::fillAvailableServices()
}
m_apiServicesModel->updateModel(servicesData);
if (m_apiServicesModel->rowCount() > 0) {
m_apiServicesModel->setServiceIndex(0);
}
return true;
}

View File

@@ -307,7 +307,8 @@ bool SubscriptionUiController::updateServiceFromGateway(const int serverIndex, c
if (oldServerConfig.isApiV2()) {
const ApiV2ServerConfig *oldApiV2 = oldServerConfig.as<ApiV2ServerConfig>();
if (oldApiV2) {
wasSubscriptionExpired = oldApiV2->apiConfig.isSubscriptionExpired();
wasSubscriptionExpired = oldApiV2->apiConfig.subscriptionExpiredByServer
|| oldApiV2->apiConfig.isSubscriptionExpired();
}
}
@@ -328,8 +329,9 @@ bool SubscriptionUiController::updateServiceFromGateway(const int serverIndex, c
} else {
if (errorCode == ErrorCode::ApiSubscriptionExpiredError) {
emit subscriptionExpiredOnServer();
} else {
emit errorOccurred(errorCode);
}
emit errorOccurred(errorCode);
return false;
}
}
@@ -352,14 +354,10 @@ bool SubscriptionUiController::updateServiceFromTelegram(const int serverIndex)
}
}
bool SubscriptionUiController::deactivateDevice(int serverIndex, const bool isRemoveEvent)
bool SubscriptionUiController::deactivateDevice(int serverIndex)
{
ErrorCode errorCode = m_subscriptionController->deactivateDevice(serverIndex, isRemoveEvent);
ErrorCode errorCode = m_subscriptionController->deactivateDevice(serverIndex);
if (errorCode != ErrorCode::NoError) {
if (errorCode == ErrorCode::ApiSubscriptionExpiredError && isRemoveEvent) {
return true;
}
emit errorOccurred(errorCode);
return false;
}
@@ -386,7 +384,11 @@ void SubscriptionUiController::validateConfig()
ErrorCode errorCode = m_subscriptionController->validateAndUpdateConfig(serverIndex, hasInstalledContainers);
if (errorCode != ErrorCode::NoError) {
emit errorOccurred(errorCode);
if (errorCode == ErrorCode::ApiSubscriptionExpiredError) {
emit subscriptionExpiredOnServer();
} else {
emit errorOccurred(errorCode);
}
emit configValidated(false);
return;
}
@@ -476,6 +478,9 @@ void SubscriptionUiController::getRenewalLink(int serverIndex)
emit errorOccurred(errorCode);
return;
}
if (url.isEmpty()) {
return;
}
emit renewalLinkReceived(url);
});
watcher->setFuture(m_subscriptionController->getRenewalLink(serverIndex));

View File

@@ -48,7 +48,7 @@ public slots:
bool updateServiceFromGateway(const int serverIndex, const QString &newCountryCode, const QString &newCountryName,
bool reloadServiceConfig = false);
bool updateServiceFromTelegram(const int serverIndex);
bool deactivateDevice(int serverIndex, const bool isRemoveEvent);
bool deactivateDevice(int serverIndex);
bool deactivateExternalDevice(int serverIndex, const QString &uuid, const QString &serverCountryCode);
void validateConfig();

View File

@@ -15,7 +15,7 @@ DrawerType2 {
property bool isRenewalAvailable: false
onOpened: {
isRenewalAvailable = ServersModel.getProcessedServerData("isRenewalAvailable") && !ApiAccountInfoModel.data("isInAppPurchase")
isRenewalAvailable = ServersModel.getDefaultServerData("isRenewalAvailable") && !ApiAccountInfoModel.data("isInAppPurchase")
}
expandedStateContent: ColumnLayout {
@@ -28,7 +28,7 @@ DrawerType2 {
spacing: 0
onImplicitHeightChanged: {
root.expandedHeight = content.implicitHeight + 32 + SettingsController.safeAreaBottomMargin
root.expandedHeight = content.implicitHeight + 32 + PageController.safeAreaBottomMargin
}
Item {
@@ -43,7 +43,7 @@ DrawerType2 {
anchors.left: parent.left
anchors.right: parent.right
text: ServersModel.getProcessedServerData("name") + qsTr(" subscription has expired")
text: ServersModel.getDefaultServerData("name") + qsTr(" subscription has expired")
horizontalAlignment: Text.AlignLeft
}
}
@@ -76,7 +76,7 @@ DrawerType2 {
textColor: AmneziaStyle.color.midnightBlack
clickedFunc: function() {
SubscriptionUiController.getRenewalLink(ServersUiController.getProcessedServerIndex())
SubscriptionUiController.getRenewalLink(ServersUiController.defaultIndex)
}
}
@@ -96,7 +96,7 @@ DrawerType2 {
clickedFunc: function() {
PageController.showBusyIndicator(true)
let result = ApiSettingsController.getAccountInfo(false)
let result = SubscriptionUiController.getAccountInfo(ServersUiController.defaultIndex, false)
PageController.showBusyIndicator(false)
if (result) {
root.closeTriggered()

View File

@@ -469,7 +469,7 @@ PageType {
PageController.showNotificationMessage(qsTr("Cannot unlink device during active connection"))
} else {
PageController.showBusyIndicator(true)
if (SubscriptionUiController.deactivateDevice(ServersUiController.getProcessedServerIndex(), false)) {
if (SubscriptionUiController.deactivateDevice(ServersUiController.getProcessedServerIndex())) {
SubscriptionUiController.getAccountInfo(ServersUiController.getProcessedServerIndex(), true)
}
PageController.showBusyIndicator(false)