Skip to content

Commit

Permalink
fix(cpn): multi protocol and sd card updates (EdgeTX#4774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Horne authored and ThomasKuehne committed Mar 24, 2024
1 parent c1c5d7a commit 33e38b1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion companion/src/updates/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Repo::~Repo()

bool Repo::getJson(const QString filename, QJsonDocument * json)
{
m_network->downloadJson(m_releases->urlContent(filename), json);
m_network->downloadJsonContent(m_releases->urlContent(filename), json);

if (!m_network->isSuccess()) {
m_status->reportProgress("Unable to download json data", QtDebugMsg);
Expand Down
2 changes: 1 addition & 1 deletion companion/src/updates/repoassets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void RepoAssets::dumpItemModel(const QString modelName, const QAbstractItemModel

bool RepoAssets::getJson(QJsonDocument * json)
{
network()->downloadJson(urlAsset(id()), json);
network()->downloadJsonAsset(urlAsset(id()), json);

if (!network()->isSuccess()) {
status()->reportProgress("Unable to download json data", QtDebugMsg);
Expand Down
2 changes: 1 addition & 1 deletion companion/src/updates/updatemultiprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ UpdateMultiProtocol::UpdateMultiProtocol(QWidget * parent) :
UpdateInterface(parent, CID_MultiProtocol, tr("Multiprotocol"))
{
// GitHub REST API default ResultsPerPage = 30
init(QString(GH_API_REPOS).append("/pascallanger/DIY-Multiprotocol-TX-Module"), "", 50);
init(QString(GH_API_REPOS).append("/pascallanger/DIY-Multiprotocol-TX-Module"), "", 100);
}

void UpdateMultiProtocol::assetSettingsInit()
Expand Down
26 changes: 23 additions & 3 deletions companion/src/updates/updatenetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include <QtNetwork/QNetworkProxyFactory>

constexpr char GH_API_VERSION[] {"2022-11-28"};
constexpr char GH_ACCEPT_HEADER_CONTENT[] {"application/octet-stream"};
constexpr char GH_ACCEPT_HEADER_CONTENT[] {"application/octet-stream"};
constexpr char GH_ACCEPT_HEADER_METADATA[] {"application/vnd.github+json"};
// constexpr char GH_ACCEPT_HEADER_RAW[] {"application/vnd.github.raw"};
constexpr char GH_ACCEPT_HEADER_RAW[] {"application/vnd.github.raw+json"};

UpdateNetwork::UpdateNetwork(QObject * parent, UpdateStatus * status) :
QObject(parent),
Expand Down Expand Up @@ -59,6 +59,8 @@ QString UpdateNetwork::downloadDataTypeToString(const DownloadDataType val)
return "Content";
case DDT_MetaData:
return "Meta Data";
case DDT_Raw:
return "Raw";
default:
return CPN_STR_UNKNOWN_ITEM;
}
Expand All @@ -78,10 +80,28 @@ void UpdateNetwork::downloadJson(const QString & url, QJsonDocument * json)
convertBufferToJson(json);
}

void UpdateNetwork::downloadJsonAsset(const QString & url, QJsonDocument * json)
{
downloadToBuffer(DDT_Content, url);
if (m_success)
convertBufferToJson(json);
}

void UpdateNetwork::downloadJsonContent(const QString & url, QJsonDocument * json)
{
downloadToBuffer(DDT_Raw, url);
if (m_success)
convertBufferToJson(json);
}

void UpdateNetwork::downloadToBuffer(const DownloadDataType type, const QString & url)
{
m_success = false;
download(type, url, type == DDT_MetaData ? GH_ACCEPT_HEADER_METADATA : GH_ACCEPT_HEADER_CONTENT, QString());
download(type,
url,
type == DDT_MetaData ? GH_ACCEPT_HEADER_METADATA :
type == DDT_Raw ? GH_ACCEPT_HEADER_RAW : GH_ACCEPT_HEADER_CONTENT,
QString());
}

void UpdateNetwork::downloadToFile(const QString & url, const QString & filePath)
Expand Down
3 changes: 3 additions & 0 deletions companion/src/updates/updatenetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class UpdateNetwork : public QObject
DDT_Content,
DDT_SaveToFile,
DDT_MetaData,
DDT_Raw,
};
Q_ENUM(DownloadDataType)

Expand All @@ -48,6 +49,8 @@ class UpdateNetwork : public QObject
void convertBufferToJson(QJsonDocument * json);
void downloadMetaData(const QString & url, QJsonDocument * json);
void downloadJson(const QString & url, QJsonDocument * json);
void downloadJsonAsset(const QString & url, QJsonDocument * json);
void downloadJsonContent(const QString & url, QJsonDocument * json);
void downloadToFile(const QString & url, const QString & filePath);
void downloadToBuffer(const DownloadDataType type, const QString & url);
void download(const DownloadDataType type, const QString & urlStr, const char * header, const QString & filePath);
Expand Down

0 comments on commit 33e38b1

Please sign in to comment.