mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-22 02:01:08 +07:00
refactor: remove serverConfig struct (#2595)
* refactor: remove serverConfig struct * refactor: add warnings for api v1 configs * refactor: moved the server type definition to a separate namespace * refactor: simplified gateway stacks * fix: fixed server description * fix: fixed postAsync reply usage * fix: fixed validateConfig call * fix: fixed server name in notifications * fix: fixed initPrepareConfigHandler for lagacy configs
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
#ifndef SECURESERVERSREPOSITORY_H
|
||||
#define SECURESERVERSREPOSITORY_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QJsonObject>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QtGlobal>
|
||||
#include <optional>
|
||||
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "core/models/selfhosted/selfHostedAdminServerConfig.h"
|
||||
#include "core/models/selfhosted/selfHostedUserServerConfig.h"
|
||||
#include "core/models/selfhosted/nativeServerConfig.h"
|
||||
#include "core/models/api/apiV2ServerConfig.h"
|
||||
#include "core/models/api/legacyApiServerConfig.h"
|
||||
#include "core/models/containerConfig.h"
|
||||
#include "core/utils/serverConfigUtils.h"
|
||||
#include "secureQSettings.h"
|
||||
|
||||
using namespace amnezia;
|
||||
@@ -18,47 +24,57 @@ class SecureServersRepository : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SecureServersRepository(SecureQSettings* settings, QObject *parent = nullptr);
|
||||
explicit SecureServersRepository(SecureQSettings *settings, QObject *parent = nullptr);
|
||||
|
||||
QString addServer(const QString &serverId, const QJsonObject &serverJson, serverConfigUtils::ConfigType kind);
|
||||
void editServer(const QString &serverId, const QJsonObject &serverJson, serverConfigUtils::ConfigType kind);
|
||||
void removeServer(const QString &serverId);
|
||||
serverConfigUtils::ConfigType serverKind(const QString &serverId) const;
|
||||
|
||||
std::optional<SelfHostedAdminServerConfig> selfHostedAdminConfig(const QString &serverId) const;
|
||||
std::optional<SelfHostedUserServerConfig> selfHostedUserConfig(const QString &serverId) const;
|
||||
std::optional<NativeServerConfig> nativeConfig(const QString &serverId) const;
|
||||
std::optional<ApiV2ServerConfig> apiV2Config(const QString &serverId) const;
|
||||
std::optional<LegacyApiServerConfig> legacyApiConfig(const QString &serverId) const;
|
||||
|
||||
void addServer(const ServerConfig &server);
|
||||
void editServer(int index, const ServerConfig &server);
|
||||
void removeServer(int index);
|
||||
ServerConfig server(int index) const;
|
||||
QVector<ServerConfig> servers() const;
|
||||
int serversCount() const;
|
||||
int indexOfServerId(const QString &serverId) const;
|
||||
QString serverIdAt(int index) const;
|
||||
QVector<QString> orderedServerIds() const;
|
||||
|
||||
int defaultServerIndex() const;
|
||||
void setDefaultServer(int index);
|
||||
QString defaultServerId() const;
|
||||
void setDefaultServer(const QString &serverId);
|
||||
|
||||
void setDefaultContainer(int serverIndex, DockerContainer container);
|
||||
ContainerConfig containerConfig(int serverIndex, DockerContainer container) const;
|
||||
void setContainerConfig(int serverIndex, DockerContainer container, const ContainerConfig &config);
|
||||
void clearLastConnectionConfig(int serverIndex, DockerContainer container);
|
||||
|
||||
ServerCredentials serverCredentials(int index) const;
|
||||
bool hasServerWithVpnKey(const QString &vpnKey) const;
|
||||
bool hasServerWithCrc(quint16 crc) const;
|
||||
|
||||
void setServersArray(const QJsonArray &servers);
|
||||
void clearServers();
|
||||
|
||||
void invalidateCache();
|
||||
|
||||
signals:
|
||||
void serverAdded(ServerConfig config);
|
||||
void serverEdited(int index, ServerConfig config);
|
||||
void serverRemoved(int index);
|
||||
void defaultServerChanged(int index);
|
||||
void serverAdded(const QString &serverId);
|
||||
void serverEdited(const QString &serverId);
|
||||
void serverRemoved(const QString &serverId, int removedIndex);
|
||||
void defaultServerChanged(const QString &defaultServerId);
|
||||
|
||||
private:
|
||||
void loadFromStorage();
|
||||
void updateDefaultServerFromStorage();
|
||||
void persistDefaultServerFields();
|
||||
|
||||
QString normalizedOrGeneratedServerId(const QString &candidateId) const;
|
||||
|
||||
void syncToStorage();
|
||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||
QVariant value(const QString &key, const QVariant &defaultValue) const;
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
|
||||
SecureQSettings* m_settings;
|
||||
|
||||
QVector<ServerConfig> m_servers;
|
||||
int m_defaultServerIndex = 0;
|
||||
|
||||
void clearServerStateMaps();
|
||||
|
||||
SecureQSettings *m_settings;
|
||||
|
||||
QHash<QString, QJsonObject> m_serverJsonById;
|
||||
QVector<QString> m_orderedServerIds;
|
||||
|
||||
QString m_defaultServerId;
|
||||
};
|
||||
|
||||
#endif // SECURESERVERSREPOSITORY_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user