mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 16:23:46 +08:00
nav: Send DELETE to clear next destination on server (#21746)
old-commit-hash: 34bb5b935fd3c2bb481129cb4bc27ce646c24f12
This commit is contained in:
@@ -80,7 +80,7 @@ bool HttpRequest::active() {
|
|||||||
return reply != nullptr;
|
return reply != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpRequest::sendRequest(const QString &requestURL) {
|
void HttpRequest::sendRequest(const QString &requestURL, const HttpRequest::Method method) {
|
||||||
if (active()) {
|
if (active()) {
|
||||||
qDebug() << "HttpRequest is active";
|
qDebug() << "HttpRequest is active";
|
||||||
return;
|
return;
|
||||||
@@ -98,7 +98,11 @@ void HttpRequest::sendRequest(const QString &requestURL) {
|
|||||||
request.setUrl(QUrl(requestURL));
|
request.setUrl(QUrl(requestURL));
|
||||||
request.setRawHeader(QByteArray("Authorization"), ("JWT " + token).toUtf8());
|
request.setRawHeader(QByteArray("Authorization"), ("JWT " + token).toUtf8());
|
||||||
|
|
||||||
reply = networkAccessManager->get(request);
|
if (method == HttpRequest::Method::GET) {
|
||||||
|
reply = networkAccessManager->get(request);
|
||||||
|
} else if (method == HttpRequest::Method::DELETE) {
|
||||||
|
reply = networkAccessManager->deleteResource(request);
|
||||||
|
}
|
||||||
|
|
||||||
networkTimer->start();
|
networkTimer->start();
|
||||||
connect(reply, &QNetworkReply::finished, this, &HttpRequest::requestFinished);
|
connect(reply, &QNetworkReply::finished, this, &HttpRequest::requestFinished);
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ class HttpRequest : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum class Method {GET, DELETE};
|
||||||
|
|
||||||
explicit HttpRequest(QObject* parent, bool create_jwt = true, int timeout = 20000);
|
explicit HttpRequest(QObject* parent, bool create_jwt = true, int timeout = 20000);
|
||||||
void sendRequest(const QString &requestURL);
|
void sendRequest(const QString &requestURL, const Method method = Method::GET);
|
||||||
bool active();
|
bool active();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -105,10 +105,11 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
|
|||||||
|
|
||||||
// Destination set while offline
|
// Destination set while offline
|
||||||
{
|
{
|
||||||
std::string url = "https://api.commadotai.com/v1/navigation/" + dongle_id + "/next";
|
QString url = QString::fromStdString("https://api.commadotai.com/v1/navigation/" + dongle_id + "/next");
|
||||||
RequestRepeater* repeater = new RequestRepeater(this, QString::fromStdString(url), "", 10, true);
|
RequestRepeater* repeater = new RequestRepeater(this, url, "", 10, true);
|
||||||
|
HttpRequest* deleter = new HttpRequest(this);
|
||||||
|
|
||||||
QObject::connect(repeater, &RequestRepeater::receivedResponse, [](QString resp) {
|
QObject::connect(repeater, &RequestRepeater::receivedResponse, [=](QString resp) {
|
||||||
auto params = Params();
|
auto params = Params();
|
||||||
if (resp != "null") {
|
if (resp != "null") {
|
||||||
if (params.get("NavDestination").empty()) {
|
if (params.get("NavDestination").empty()) {
|
||||||
@@ -117,6 +118,9 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) {
|
|||||||
} else {
|
} else {
|
||||||
qWarning() << "Got location from /next, but NavDestination already set";
|
qWarning() << "Got location from /next, but NavDestination already set";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send DELETE to clear destination server side
|
||||||
|
deleter->sendRequest(url, HttpRequest::Method::DELETE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user