Ver código fonte

WIP. linkedin support

tags/v1.1.4
Jonathan Cobb 4 anos atrás
pai
commit
248681c115
3 arquivos alterados com 44 adições e 13 exclusões
  1. +28
    -2
      bubble-server/src/main/java/bubble/resources/stream/FilterHttpResource.java
  2. +15
    -10
      bubble-server/src/main/resources/bubble/rule/social/block/site/LI.js.hbs
  3. +1
    -1
      utils/cobbzilla-utils

+ 28
- 2
bubble-server/src/main/java/bubble/resources/stream/FilterHttpResource.java Ver arquivo

@@ -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<NameAndValue> headers = new ArrayList<>();
for (String name : req.getHeaderNames()) {
final String value = req.getHeader(name);
headers.add(new NameAndValue(name, value));
}
final List<String> 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}")


+ 15
- 10
bubble-server/src/main/resources/bubble/rule/social/block/site/LI.js.hbs Ver arquivo

@@ -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<articleLinks.length; j++) {
const articleLink = articleLinks[i];
console.log('consider_block: examining articleLink with href='+articleLink.href);
const author = {{JS_PREFIX}}_author_from_href(articleLink.href);
if (author === null) continue;
if (author in blocked_users) {
@@ -86,10 +88,13 @@ function {{JS_PREFIX}}_consider_block(articles, blocked_users) {
}

let b = {{JS_PREFIX}}_create_block_control(article, author, articleLink);
// console.log('inserting span='+b.id+' for article by '+author);

authorSpans[0].parentNode.appendChild(b);
{{JS_PREFIX}}_tally_allow();
if (b !== null) {
console.log('consider_block: inserting span='+b.id+' for article by '+author);
authorSpans[0].parentNode.appendChild(b);
{{JS_PREFIX}}_tally_allow();
} else {
console.log('consider_block: create_block_control returned null for author '+author)
}
}
}
}


+ 1
- 1
utils/cobbzilla-utils

@@ -1 +1 @@
Subproject commit c66f9e167ca32887374ec07a05fd3bddaeb8c2d5
Subproject commit ea72ac4a1619c4f5915047650cdd18b8a6202681

Carregando…
Cancelar
Salvar