88 lines
2.5 KiB
C++
88 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "ImmichClient.h"
|
|
#include "Metrics.h"
|
|
|
|
#include <QElapsedTimer>
|
|
#include <QJsonObject>
|
|
#include <QObject>
|
|
#include <QPointer>
|
|
#include <QTimer>
|
|
|
|
class QHttpMultiPart;
|
|
class QNetworkReply;
|
|
class QTemporaryFile;
|
|
class QWebSocket;
|
|
|
|
class SyncSession final : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit SyncSession(QWebSocket *socket, Metrics &metrics, QObject *parent = nullptr);
|
|
~SyncSession() override;
|
|
|
|
public slots:
|
|
void handleTextMessage(const QString &message);
|
|
void abort();
|
|
|
|
private:
|
|
enum class JobKind {
|
|
None,
|
|
Inspection,
|
|
Synchronization,
|
|
};
|
|
|
|
struct TransferSpec {
|
|
ImmichClient *source = nullptr;
|
|
ImmichClient *destination = nullptr;
|
|
AssetInfo asset;
|
|
QString direction;
|
|
};
|
|
|
|
void inspect(const QJsonObject &request);
|
|
void configureSide(const QString &side, const QJsonValue &value);
|
|
void sideInspected(const QString &side, const ShareInfo &info);
|
|
void sideResolved(const QString &side);
|
|
void sendInspection();
|
|
void startSync(const QString &direction);
|
|
void startNextTransfer();
|
|
bool storeDownloadedData(quint64 serial);
|
|
void beginUpload(quint64 serial);
|
|
void finishTransfer(quint64 serial, bool success, const QString &message, const QString &result = {});
|
|
void finishJob(const QString &reason);
|
|
void reset();
|
|
|
|
void send(QJsonObject message);
|
|
void sendSideStatus(const QString &side, const QString &stage, const QString &message);
|
|
void sendProgress(const QString &phase, qint64 transferred, qint64 total);
|
|
[[nodiscard]] bool directionAllowed(const QString &direction, QString *reason = nullptr) const;
|
|
|
|
QPointer<QWebSocket> m_socket;
|
|
Metrics &m_metrics;
|
|
QTimer m_requestTimer;
|
|
JobKind m_jobKind = JobKind::None;
|
|
QString m_direction;
|
|
ImmichClient *m_leftClient = nullptr;
|
|
ImmichClient *m_rightClient = nullptr;
|
|
ShareInfo m_leftInfo;
|
|
ShareInfo m_rightInfo;
|
|
bool m_leftResolved = false;
|
|
bool m_rightResolved = false;
|
|
bool m_leftUsable = false;
|
|
bool m_rightUsable = false;
|
|
bool m_ready = false;
|
|
bool m_active = false;
|
|
SyncPlan m_plan;
|
|
QList<TransferSpec> m_queue;
|
|
qsizetype m_total = 0;
|
|
qsizetype m_completed = 0;
|
|
qsizetype m_failed = 0;
|
|
quint64 m_transferSerial = 0;
|
|
QNetworkReply *m_download = nullptr;
|
|
QNetworkReply *m_upload = nullptr;
|
|
QHttpMultiPart *m_multipart = nullptr;
|
|
QTemporaryFile *m_temporaryFile = nullptr;
|
|
bool m_uploadCompleteNotified = false;
|
|
QElapsedTimer m_progressTimer;
|
|
};
|