fix(githubsync): add HTTP timeout and JSON filter to prevent sync failure on slow connections and large repos
This commit is contained in:
1 parent
8cd6e6c522
commit
970c7afa3e
1 file changed
+13
-1
@@ -71,6 +71,7 @@ bool downloadFile(const std::string& rawUrl, const std::string& pat,
|
|||||||
|
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
http.begin(client, rawUrl.c_str());
|
http.begin(client, rawUrl.c_str());
|
||||||
|
http.setTimeout(15000);
|
||||||
http.addHeader("User-Agent", "CrossPoint-GitHubSync/1.0");
|
http.addHeader("User-Agent", "CrossPoint-GitHubSync/1.0");
|
||||||
if (!pat.empty()) {
|
if (!pat.empty()) {
|
||||||
std::string auth = "token " + pat;
|
std::string auth = "token " + pat;
|
||||||
@@ -137,6 +138,8 @@ bool fetchTree(RepoInfo& info, const std::string& pat,
|
|||||||
http.addHeader("Authorization", auth.c_str());
|
http.addHeader("Authorization", auth.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http.setTimeout(15000);
|
||||||
|
|
||||||
int code = http.GET();
|
int code = http.GET();
|
||||||
if (code != 200) {
|
if (code != 200) {
|
||||||
LOG_ERR("GHS", "Tree fetch HTTP %d for branch %s", code, branches[i]);
|
LOG_ERR("GHS", "Tree fetch HTTP %d for branch %s", code, branches[i]);
|
||||||
@@ -144,10 +147,19 @@ bool fetchTree(RepoInfo& info, const std::string& pat,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonDocument filter;
|
||||||
|
filter["sha"] = true;
|
||||||
|
JsonArray filterTree = filter["tree"].to<JsonArray>();
|
||||||
|
JsonObject filterItem = filterTree.add<JsonObject>();
|
||||||
|
filterItem["type"] = true;
|
||||||
|
filterItem["path"] = true;
|
||||||
|
filterItem["sha"] = true;
|
||||||
|
|
||||||
WiFiClient* stream = http.getStreamPtr();
|
WiFiClient* stream = http.getStreamPtr();
|
||||||
|
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
DeserializationError err = deserializeJson(doc, *stream);
|
DeserializationError err = deserializeJson(doc, *stream,
|
||||||
|
DeserializationOption::Filter(filter));
|
||||||
http.end();
|
http.end();
|
||||||
|
|
||||||
if (err != DeserializationError::Ok) {
|
if (err != DeserializationError::Ok) {
|
||||||
|
|||||||
Reference in new issue
Block a user