forked from j62/ctbrec
fix null pointer error
This commit is contained in:
parent
ae1d5c7af8
commit
97554fcd2a
|
@ -11,6 +11,7 @@ import java.time.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
|
@ -189,8 +190,11 @@ public class ChaturbateHttpClient extends HttpClient {
|
||||||
|
|
||||||
// we need to prevent repeated challenge requests from multiple threads, so we check if the clearance cookie needs updating
|
// we need to prevent repeated challenge requests from multiple threads, so we check if the clearance cookie needs updating
|
||||||
// maybe this can be done with some syncronization primitive, or maybe an expiresAt() check is enough
|
// maybe this can be done with some syncronization primitive, or maybe an expiresAt() check is enough
|
||||||
var cookie = cookieJar.getCookieFromCollection(cookieJar.getCookies().get(req.url().topPrivateDomain()), "cf_clearance");
|
var needRefresh = Optional
|
||||||
if (cookie.map(c -> Instant.ofEpochMilli(c.expiresAt()).isBefore(Instant.now())).orElse(true)) {
|
.ofNullable(cookieJar.getCookies().get(req.url().topPrivateDomain()))
|
||||||
|
.flatMap(x -> cookieJar.getCookieFromCollection(x, "cf_clearance"))
|
||||||
|
.map(c -> Instant.ofEpochMilli(c.expiresAt()).isBefore(Instant.now())).orElse(true);
|
||||||
|
if (needRefresh) {
|
||||||
var apiResponse = flaresolverr.getCookies(req.url().toString()).get();
|
var apiResponse = flaresolverr.getCookies(req.url().toString()).get();
|
||||||
if (apiResponse.getStatus().equals("ok")) {
|
if (apiResponse.getStatus().equals("ok")) {
|
||||||
// update user agent. It should be the same for all sites, assuming we use the same api address every time
|
// update user agent. It should be the same for all sites, assuming we use the same api address every time
|
||||||
|
|
Loading…
Reference in New Issue