forked from j62/ctbrec
1
0
Fork 0

Merge branch 'jasmin' into dev

This commit is contained in:
0xboobface 2019-01-24 15:52:38 +01:00
commit 2c67b0b75c
3 changed files with 28 additions and 5 deletions

View File

@ -38,6 +38,10 @@ public class LiveJasminFollowedUpdateService extends PaginatedScheduledService {
return new Task<List<Model>>() {
@Override
public List<Model> call() throws IOException {
if(!liveJasmin.credentialsAvailable()) {
throw new RuntimeException("Credentials missing");
}
boolean loggedIn = SiteUiFactory.getUi(liveJasmin).login();
if(!loggedIn) {
throw new RuntimeException("Couldn't login to livejasmin");

View File

@ -34,7 +34,7 @@ public class CookieJarImpl implements CookieJar {
String name = oldCookie.name();
for (Cookie newCookie : cookies) {
if(newCookie.name().equalsIgnoreCase(name)) {
LOG.debug("Replacing cookie {} {} -> {} [{}]", oldCookie.name(), oldCookie.value(), newCookie.value(), oldCookie.domain());
LOG.trace("Replacing cookie {} {} -> {} [{}]", oldCookie.name(), oldCookie.value(), newCookie.value(), oldCookie.domain());
iterator.remove();
break;
}
@ -42,11 +42,11 @@ public class CookieJarImpl implements CookieJar {
}
cookiesForUrl.addAll(cookies);
cookieStore.put(host, cookiesForUrl);
LOG.debug("Adding cookie: {} for {}", cookiesForUrl, host);
LOG.trace("Adding cookie: {} for {}", cookiesForUrl, host);
}
else {
cookieStore.put(host, cookies);
LOG.debug("Storing cookie: {} for {}", cookies, host);
LOG.trace("Storing cookie: {} for {}", cookies, host);
}
}
@ -54,9 +54,9 @@ public class CookieJarImpl implements CookieJar {
public List<Cookie> loadForRequest(HttpUrl url) {
String host = getDomain(url);
List<Cookie> cookies = cookieStore.get(host);
LOG.debug("Cookies for {}", url);
LOG.trace("Cookies for {}", url);
Optional.ofNullable(cookies).ifPresent(cookiez -> cookiez.forEach(c -> {
LOG.debug(" {} expires on:{}", c, c.expiresAt());
LOG.trace(" {} expires on:{}", c, c.expiresAt());
}));
//LOG.debug("Cookies for {}: {}", url.host(), cookies);
return cookies != null ? cookies : new ArrayList<Cookie>();
@ -72,6 +72,19 @@ public class CookieJarImpl implements CookieJar {
throw new NoSuchElementException("No cookie named " + name + " for " + url.host() + " available");
}
public void deleteCookie(HttpUrl url, String name) {
List<Cookie> cookies = loadForRequest(url);
for (Iterator<Cookie> iterator = cookies.iterator(); iterator.hasNext();) {
Cookie cookie = iterator.next();
if(Objects.equals(cookie.name(), name)) {
iterator.remove();
LOG.debug("Removed cookie \"{}\" for {}", name, url.toString());
return;
}
}
throw new NoSuchElementException("No cookie named " + name + " for " + url.host() + " available");
}
private String getDomain(HttpUrl url) {
// String host = url.host();
// if (host.startsWith("www.")) {

View File

@ -20,6 +20,12 @@ public class LiveJasminHttpClient extends HttpClient {
protected LiveJasminHttpClient() {
super("livejasmin");
// delete all cookies, if we are guests, because old guest sessions cause
// endless redirects
if(Config.getInstance().getSettings().livejasminUsername.isEmpty()) {
getCookieJar().clear();
}
}
@Override