Skip to content

Commit

Permalink
Merge pull request #6059 from psiinon/client/crawlbug
Browse files Browse the repository at this point in the history
Client: report nodes with no components as visited
  • Loading branch information
kingthorin authored Jan 2, 2025
2 parents 942802e + 8621b2a commit a487a45
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ private void handleReportObject(JSONObject json) {
}
}

private void handleReportEvent(JSONObject json) {
ReportedEvent event = new ReportedEvent(json);
if (event.getUrl() == null || !ExtensionClientIntegration.isApiUrl(event.getUrl())) {
this.extension.addReportedObject(event);
if (event.getUrl() != null) {
ThreadUtils.invokeAndWaitHandled(() -> this.extension.setVisited(event.getUrl()));
}
}
}

@Override
public ApiResponse handleApiAction(String name, JSONObject params) throws ApiException {
JSONObject json;
Expand All @@ -131,11 +141,7 @@ public ApiResponse handleApiAction(String name, JSONObject params) throws ApiExc
String eventJson = this.getParam(params, PARAM_EVENT_JSON, "");
LOGGER.debug("Got event: {}", eventJson);
json = JSONObject.fromObject(eventJson);
ReportedEvent event = new ReportedEvent(json);
if (event.getUrl() == null
|| !ExtensionClientIntegration.isApiUrl(event.getUrl())) {
this.extension.addReportedObject(event);
}
handleReportEvent(json);
break;

case ACTION_REPORT_ZEST_STATEMENT:
Expand Down Expand Up @@ -193,7 +199,7 @@ public String handleCallBack(HttpMessage msg) throws ApiException {
} else if (body.startsWith(PARAM_EVENT_JSON)) {
JSONObject json = decodeParam(body, PARAM_EVENT_JSON);
LOGGER.debug("Got event: {}", json);
this.extension.addReportedObject(new ReportedEvent(json));
handleReportEvent(json);
} else if (body.startsWith(PARAM_STATEMENT_JSON)) {
try {
this.extension.addZestStatement(decodeParamString(body, PARAM_STATEMENT_JSON));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,15 @@ public boolean setRedirect(String originalUrl, String redirectedUrl) {
return false;
}

public boolean setVisited(String url) {
ClientNode node = this.clientTree.setVisited(url);
if (node != null) {
this.clientNodeChanged(node);
return true;
}
return false;
}

public void deleteNodes(List<ClientNode> nodes) {
this.clientTree.deleteNodes(nodes);
if (View.isInitialised()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ public ClientNode setRedirect(String originalUrl, String redirectedUrl) {
LOGGER.debug("setRedirect, no node for URL {}", originalUrl);
return null;
}

public ClientNode setVisited(String url) {
ClientNode node = getNode(url, false, false);
if (node != null && !node.getUserObject().isVisited()) {
node.getUserObject().setVisited(true);
return node;
}
LOGGER.debug("setVisited, no node for URL or already visited {}", url);
return null;
}
}

/**
Expand Down

0 comments on commit a487a45

Please sign in to comment.