mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-16 10:22:07 +08:00
UI: check if dongle id is valid before calling API (#21275)
This commit is contained in:
@@ -155,6 +155,10 @@ std::string dir_name(std::string const &path) {
|
||||
return path.substr(0, pos);
|
||||
}
|
||||
|
||||
bool is_valid_dongle_id(std::string const& dongle_id) {
|
||||
return !dongle_id.empty() && dongle_id != "UnregisteredDevice";
|
||||
}
|
||||
|
||||
struct tm get_time() {
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
|
||||
@@ -58,6 +58,7 @@ std::string tohex(const uint8_t* buf, size_t buf_size);
|
||||
std::string hexdump(const std::string& in);
|
||||
std::string base_name(std::string const& path);
|
||||
std::string dir_name(std::string const& path);
|
||||
bool is_valid_dongle_id(std::string const& dongle_id);
|
||||
|
||||
// **** file fhelpers *****
|
||||
std::string read_file(const std::string& fn);
|
||||
|
||||
@@ -48,10 +48,12 @@ DriveStats::DriveStats(QWidget* parent) : QWidget(parent) {
|
||||
add_stats_layouts("ALL TIME", all_);
|
||||
add_stats_layouts("PAST WEEK", week_);
|
||||
|
||||
QString dongleId = QString::fromStdString(Params().get("DongleId"));
|
||||
QString url = "https://api.commadotai.com/v1.1/devices/" + dongleId + "/stats";
|
||||
RequestRepeater* repeater = new RequestRepeater(this, url, "ApiCache_DriveStats", 30);
|
||||
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &DriveStats::parseResponse);
|
||||
std::string dongle_id = Params().get("DongleId");
|
||||
if (util::is_valid_dongle_id(dongle_id)) {
|
||||
std::string url = "https://api.commadotai.com/v1.1/devices/" + dongle_id + "/stats";
|
||||
RequestRepeater* repeater = new RequestRepeater(this, QString::fromStdString(url), "ApiCache_DriveStats", 30);
|
||||
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &DriveStats::parseResponse);
|
||||
}
|
||||
|
||||
setStyleSheet(R"(QLabel {font-size: 48px; font-weight: 500;})");
|
||||
}
|
||||
|
||||
@@ -101,14 +101,12 @@ PrimeUserWidget::PrimeUserWidget(QWidget* parent) : QWidget(parent) {
|
||||
)");
|
||||
|
||||
// set up API requests
|
||||
QString dongleId = QString::fromStdString(Params().get("DongleId"));
|
||||
if (!dongleId.length()) {
|
||||
return;
|
||||
std::string dongleId = Params().get("DongleId");
|
||||
if (util::is_valid_dongle_id(dongleId)) {
|
||||
std::string url = "https://api.commadotai.com/v1/devices/" + dongleId + "/owner";
|
||||
RequestRepeater *repeater = new RequestRepeater(this, QString::fromStdString(url), "ApiCache_Owner", 6);
|
||||
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &PrimeUserWidget::replyFinished);
|
||||
}
|
||||
|
||||
QString url = "https://api.commadotai.com/v1/devices/" + dongleId + "/owner";
|
||||
RequestRepeater *repeater = new RequestRepeater(this, url, "ApiCache_Owner", 6);
|
||||
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &PrimeUserWidget::replyFinished);
|
||||
}
|
||||
|
||||
void PrimeUserWidget::replyFinished(const QString &response) {
|
||||
@@ -232,12 +230,14 @@ SetupWidget::SetupWidget(QWidget* parent) : QFrame(parent) {
|
||||
setSizePolicy(sp_retain);
|
||||
|
||||
// set up API requests
|
||||
QString dongleId = QString::fromStdString(Params().get("DongleId"));
|
||||
QString url = "https://api.commadotai.com/v1.1/devices/" + dongleId + "/";
|
||||
RequestRepeater* repeater = new RequestRepeater(this, url, "ApiCache_Device", 5);
|
||||
std::string dongleId = Params().get("DongleId");
|
||||
if (util::is_valid_dongle_id(dongleId)) {
|
||||
std::string url = "https://api.commadotai.com/v1.1/devices/" + dongleId + "/";
|
||||
RequestRepeater* repeater = new RequestRepeater(this, QString::fromStdString(url), "ApiCache_Device", 5);
|
||||
|
||||
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &SetupWidget::replyFinished);
|
||||
QObject::connect(repeater, &RequestRepeater::failedResponse, this, &SetupWidget::parseError);
|
||||
QObject::connect(repeater, &RequestRepeater::receivedResponse, this, &SetupWidget::replyFinished);
|
||||
QObject::connect(repeater, &RequestRepeater::failedResponse, this, &SetupWidget::parseError);
|
||||
}
|
||||
hide(); // Only show when first request comes back
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user