Skip to content

Commit

Permalink
Added access to Github API via token to get Kexts download URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
ic005k committed Oct 12, 2024
1 parent 2369c2c commit e875fc1
Show file tree
Hide file tree
Showing 11 changed files with 391 additions and 311 deletions.
42 changes: 25 additions & 17 deletions src/Method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ Method::Method(QWidget* parent) : QMainWindow(parent) {
managerDownLoad = new QNetworkAccessManager(this);
myfile = new QFile(this);
tempDir = QDir::homePath() + "/tempocat/";

errorInfo = tr("Possible reasons:") + "\n\n" + tr("1.Network or URL error!") +
"\n\n" +
tr("2.The Github API is not accessed by token.(A limit of 60 "
"visits per hour). ") +
"\n\n" +
tr("3.Access the Github API via a token, but the token has a "
"problem (expired or incorrect).");
}

QStringList Method::getDLUrlList(QString url) {
Expand Down Expand Up @@ -146,11 +154,7 @@ QString Method::getHTMLSource(QString URLSTR, bool writeFile) {
QString code = reply->readAll();
if (code == "") {
mw_one->dlgSyncOC->on_btnStop_clicked();
QMessageBox::critical(
this, "",
tr("Network or URL error!") + "\n\n" +
tr("Or if the GitHub API has reached the number of accesses per "
"hour (typically 60 per hour), please try again later."));
QMessageBox::critical(this, "", errorInfo);

return "";
}
Expand Down Expand Up @@ -306,7 +310,8 @@ void Method::kextUpdate() {
}
reGetUrl = true;
if (reGetUrl) {
if (mw_one->myDlgPreference->ui->rbtnAPI->isChecked())
if (mw_one->myDlgPreference->ui->rbtnAPI->isChecked() ||
mw_one->myDlgPreference->ui->rbtnToken->isChecked())
getLastReleaseFromUrl(test);
if (mw_one->myDlgPreference->ui->rbtnWeb->isChecked())
getLastReleaseFromHtml(test + "/releases");
Expand Down Expand Up @@ -380,7 +385,8 @@ void Method::downloadAllKexts() {
}
reGetUrl = true;
if (reGetUrl) {
if (mw_one->myDlgPreference->ui->rbtnAPI->isChecked())
if (mw_one->myDlgPreference->ui->rbtnAPI->isChecked() ||
mw_one->myDlgPreference->ui->rbtnToken->isChecked())
getLastReleaseFromUrl(test);
if (mw_one->myDlgPreference->ui->rbtnWeb->isChecked())
getLastReleaseFromHtml(test + "/releases");
Expand Down Expand Up @@ -760,6 +766,16 @@ void Method::getLastReleaseFromUrl(QString strUrl) {
QNetworkRequest quest;
quest.setUrl(QUrl(strAPI));
quest.setHeader(QNetworkRequest::UserAgentHeader, "RT-Thread ART");

if (mw_one->myDlgPreference->ui->rbtnToken->isChecked()) {
QString strToken = mw_one->myDlgPreference->ui->editToken->text().trimmed();
if (strToken != "") {
quest.setRawHeader("Authorization",
QString("token %1").arg(strToken).toUtf8());
qDebug() << "strAPI=" << strAPI;
}
}

manager->get(quest);
}

Expand All @@ -775,11 +791,7 @@ void Method::parse_UpdateJSON(QString str) {

if (err_rpt.error != QJsonParseError::NoError) {
mw_one->dlgSyncOC->on_btnStop_clicked();
QMessageBox::critical(
this, "",
tr("Network or URL error!") + "\n\n" +
tr("Or if the GitHub API has reached the number of accesses per "
"hour (typically 60 per hour), please try again later."));
QMessageBox::critical(this, "", errorInfo);

return;
}
Expand Down Expand Up @@ -827,11 +839,7 @@ void Method::parse_UpdateJSON(QString str) {
qDebug() << strDLInfoList.at(0) << strDLInfoList.at(1);
if (strDLUrl == "") {
mw_one->dlgSyncOC->on_btnStop_clicked();
QMessageBox::critical(
this, "",
tr("Network or URL error!") + "\n\n" +
tr("Or if the GitHub API has reached the number of accesses per "
"hour (typically 60 per hour), please try again later."));
QMessageBox::critical(this, "", errorInfo);

return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Method.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ class Method : public QMainWindow {
void replyFinished(QNetworkReply *reply);

void Quit();
private:

private:
QElapsedTimer downloadTimer;
void cancelDownload();
QString errorInfo;

signals:
private slots:
Expand Down
2 changes: 1 addition & 1 deletion src/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

extern MainWindow* mw_one;
extern QString strAppName, strIniFile;
QString CurVersion = "20240003";
QString CurVersion = "20240004";
QString ocVer = "0.8.8";
QString ocVerDev = "0.8.9";
QString ocFrom, ocFromDev, strOCFrom, strOCFromDev;
Expand Down
Binary file modified src/cn.qm
Binary file not shown.
Loading

0 comments on commit e875fc1

Please sign in to comment.