forked from j62/ctbrec
Fix retrieving the CSRF token for CamSoda
This commit is contained in:
parent
d330fabe36
commit
977cee5af0
|
@ -1,6 +1,7 @@
|
|||
4.1.2
|
||||
========================
|
||||
* Fixed bug, which caused recordings to get stuck
|
||||
* Fixed bug, which caused some recordings to get stuck
|
||||
* Fixed follow/unfollow for CamSoda
|
||||
* Ignore list is now saved as URLs only. The old format is not compatible
|
||||
anymore, so make sure, that you export them again, if you created a backup
|
||||
before.
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package ctbrec.sites.camsoda;
|
||||
|
||||
import static java.util.regex.Pattern.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.io.HtmlParser;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
import okhttp3.FormBody;
|
||||
|
@ -18,7 +20,8 @@ import okhttp3.Response;
|
|||
|
||||
public class CamsodaHttpClient extends HttpClient {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(CamsodaHttpClient.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CamsodaHttpClient.class);
|
||||
private static final Pattern CSRF_PATTERN = Pattern.compile("\"csrf\"\s*:\s*\"(.*?)\"", MULTILINE | DOTALL);
|
||||
private String csrfToken = null;
|
||||
|
||||
public CamsodaHttpClient() {
|
||||
|
@ -69,6 +72,7 @@ public class CamsodaHttpClient extends HttpClient {
|
|||
|
||||
/**
|
||||
* check, if the login worked
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean checkLoginSuccess() throws IOException {
|
||||
|
@ -90,8 +94,13 @@ public class CamsodaHttpClient extends HttpClient {
|
|||
Request request = new Request.Builder().url(url).build();
|
||||
try (Response response = execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
Element meta = HtmlParser.getTag(response.body().string(), "meta[name=\"_token\"]");
|
||||
csrfToken = meta.attr("content");
|
||||
String pageContent = response.body().string();
|
||||
Matcher m = CSRF_PATTERN.matcher(pageContent);
|
||||
if (m.find()) {
|
||||
csrfToken = m.group(1);
|
||||
} else {
|
||||
throw new IOException("Couldn't find csrf token");
|
||||
}
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ public class CamsodaModel extends AbstractModel {
|
|||
@Override
|
||||
public boolean unfollow() throws IOException {
|
||||
String url = Camsoda.BASE_URI + "/api/v1/unfollow/" + getName();
|
||||
LOG.debug("Sending follow request {}", url);
|
||||
LOG.debug("Sending unfollow request {}", url);
|
||||
String csrfToken = ((CamsodaHttpClient)site.getHttpClient()).getCsrfToken();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
|
|
Loading…
Reference in New Issue