diff --git a/bubble-server/src/main/java/bubble/resources/stream/FilterHttpResource.java b/bubble-server/src/main/java/bubble/resources/stream/FilterHttpResource.java index 5f2cf618..3525f5ea 100644 --- a/bubble-server/src/main/java/bubble/resources/stream/FilterHttpResource.java +++ b/bubble-server/src/main/java/bubble/resources/stream/FilterHttpResource.java @@ -36,9 +36,11 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.cobbzilla.util.collection.ExpirationEvictionPolicy; import org.cobbzilla.util.collection.ExpirationMap; +import org.cobbzilla.util.collection.NameAndValue; import org.cobbzilla.util.http.HttpContentEncodingType; import org.cobbzilla.util.http.HttpUtil; import org.cobbzilla.util.network.NetworkUtil; +import org.cobbzilla.util.string.StringUtil; import org.cobbzilla.wizard.cache.redis.RedisService; import org.glassfish.grizzly.http.server.Request; import org.glassfish.jersey.server.ContainerRequest; @@ -67,6 +69,7 @@ import static org.cobbzilla.util.collection.ArrayUtil.arrayToString; import static org.cobbzilla.util.daemon.ZillaRuntime.*; import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON; import static org.cobbzilla.util.http.HttpContentTypes.TEXT_PLAIN; +import static org.cobbzilla.util.http.HttpUtil.applyRegexToUrl; import static org.cobbzilla.util.json.JsonUtil.COMPACT_MAPPER; import static org.cobbzilla.util.json.JsonUtil.json; import static org.cobbzilla.util.network.NetworkUtil.isLocalIpv4; @@ -695,9 +698,32 @@ public class FilterHttpResource { public Response followLink(@Context Request req, @Context ContainerRequest ctx, @PathParam("requestId") String requestId, - JsonNode urlNode) { + JsonNode followSpec) { final FilterSubContext filterCtx = new FilterSubContext(req, requestId); - return ok(redirectCache.computeIfAbsent(urlNode.textValue(), HttpUtil::chaseRedirects)); + + // is this a request to parse regexes from a URL? + if (followSpec.has("regex")) { + return ok(redirectCache.computeIfAbsent(json(followSpec), k -> { + final String url = followSpec.get("url").textValue(); + final String regex = followSpec.get("regex").textValue(); + final Integer group = followSpec.has("group") ? followSpec.get("group").asInt() : null; + final List headers = new ArrayList<>(); + for (String name : req.getHeaderNames()) { + final String value = req.getHeader(name); + headers.add(new NameAndValue(name, value)); + } + final List matches = applyRegexToUrl(url, headers, regex, group); + return matches == null ? null : StringUtil.toString(matches, "\n"); + })); + + } else if (followSpec.isTextual()) { + // just a regular follow -- chase redirects + return ok(redirectCache.computeIfAbsent(followSpec.textValue(), HttpUtil::chaseRedirects)); + } else { + final String json = json(followSpec); + log.error("followLink: invalid json (expected String or {regex, url}): "+json); + return notFound(json); + } } @Path(EP_ASSETS+"/{requestId}/{appId}") diff --git a/bubble-server/src/main/resources/bubble/rule/social/block/site/LI.js.hbs b/bubble-server/src/main/resources/bubble/rule/social/block/site/LI.js.hbs index 3a259786..d38f958a 100644 --- a/bubble-server/src/main/resources/bubble/rule/social/block/site/LI.js.hbs +++ b/bubble-server/src/main/resources/bubble/rule/social/block/site/LI.js.hbs @@ -3,12 +3,12 @@ const {{JS_PREFIX}}_site_host = location.protocol + '//' + window.location.hostname + '/'; function {{JS_PREFIX}}_apply_blocks(blocked_users) { - const comments = document.querySelector('#comments'); - if (comments === null || comments.length === 0) { - console.warn('No comments found, not filtering'); + const articles = Array.from(document.getElementsByClassName('feed-shared-update-v2')); + if (articles === null || articles.length === 0) { + console.warn('No articles found, not filtering'); return; } - {{JS_PREFIX}}_consider_block(comments.querySelectorAll('feed-shared-update-v2'), blocked_users); + {{JS_PREFIX}}_consider_block(articles, blocked_users); } function {{JS_PREFIX}}_author_from_href(href) { @@ -29,8 +29,9 @@ function {{JS_PREFIX}}_author_from_href(href) { return name; } -function {{JS_PREFIX}}_remove_article_from_dom(comment) { - comment.parentNode.removeChild(comment); +function {{JS_PREFIX}}_remove_article_from_dom(article) { + // todo: does this work? + article.parentNode.removeChild(article); } function {{JS_PREFIX}}_create_block_control(article, authorName, articleLink) { @@ -72,6 +73,7 @@ function {{JS_PREFIX}}_consider_block(articles, blocked_users) { const articleLinks = Array.from(article.getElementsByTagName('a')); for (let j=0; j