mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-03 20:42:09 +08:00
d991de5d30
* CommaApi: use auth.py for request authentication when on PC * whitespace * only when replay * nicer way to do this * tabs * use bool * tabs * tabs * prefer this to just be state * initialize with stdString * tabs * include order * fix order + ifdef fix * whitespace' old-commit-hash: a337097b5ee515560e9f1a804b997753767d3c9a
55 lines
1.1 KiB
C++
55 lines
1.1 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 = 3600);
|
|
|
|
private:
|
|
QNetworkAccessManager* networkAccessManager;
|
|
};
|
|
|
|
/**
|
|
* Makes a request to the request endpoint.
|
|
*/
|
|
|
|
class HttpRequest : public QObject {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit HttpRequest(QObject* parent, QString requestURL, const QString &cache_key = "", bool create_jwt_ = true);
|
|
QNetworkReply *reply;
|
|
void sendRequest(QString requestURL);
|
|
|
|
private:
|
|
QNetworkAccessManager *networkAccessManager;
|
|
QTimer *networkTimer;
|
|
QString cache_key;
|
|
bool create_jwt;
|
|
|
|
private slots:
|
|
void requestTimeout();
|
|
void requestFinished();
|
|
|
|
signals:
|
|
void receivedResponse(QString response);
|
|
void failedResponse(QString errorString);
|
|
void timeoutResponse(QString errorString);
|
|
};
|