mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-05 21:42:05 +08:00
eea78cd686
Not just parents, we also made the UI look nicer. old-commit-hash: 2eb81aa1d33887bd11083bc4f57e6f51271198f9
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <QCryptographicHash>
|
|
#include <QJsonValue>
|
|
#include <QNetworkReply>
|
|
#include <QNetworkRequest>
|
|
#include <QPair>
|
|
#include <QString>
|
|
#include <QVector>
|
|
#include <QWidget>
|
|
#include <atomic>
|
|
#include <openssl/bio.h>
|
|
#include <openssl/pem.h>
|
|
#include <openssl/rsa.h>
|
|
class CommaApi : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static QByteArray rsa_sign(QByteArray data);
|
|
static QString create_jwt(QVector<QPair<QString, QJsonValue>> payloads, int expiry = 60);
|
|
static QString create_jwt();
|
|
private:
|
|
QNetworkAccessManager* networkAccessManager;
|
|
};
|
|
|
|
/**
|
|
* Makes repeated requests to the request endpoint.
|
|
*/
|
|
class RequestRepeater : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
explicit RequestRepeater(QWidget* parent, QString requestURL, int period = 10, QVector<QPair<QString, QJsonValue>> payloads = *(new QVector<QPair<QString, QJsonValue>>()), bool disableWithScreen = true);
|
|
bool active = true;
|
|
private:
|
|
bool disableWithScreen;
|
|
QNetworkReply* reply;
|
|
QNetworkAccessManager* networkAccessManager;
|
|
QTimer* networkTimer;
|
|
std::atomic<bool> aborted = false; // Not 100% sure we need atomic
|
|
void sendRequest(QString requestURL, QVector<QPair<QString, QJsonValue>> payloads);
|
|
private slots:
|
|
void requestTimeout();
|
|
void requestFinished();
|
|
signals:
|
|
void receivedResponse(QString response);
|
|
void failedResponse(QString errorString);
|
|
};
|