From dc6b514d8f03a8e0641614e93b00f41f897e61d8 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Mon, 29 Oct 2018 13:49:04 +0100 Subject: [PATCH] Disable follow/unfollow for the time being --- .../sites/camsoda/CamsodaFollowedTab.java | 6 ++- .../camsoda/CamsodaFollowedUpdateService.java | 2 +- .../ctbrec/sites/camsoda/CamsodaModel.java | 44 +++++++++++-------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedTab.java b/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedTab.java index 8ef31c6f..bc95672b 100644 --- a/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedTab.java +++ b/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedTab.java @@ -54,7 +54,11 @@ public class CamsodaFollowedTab extends ThumbOverviewTab implements FollowedTab @Override protected void onFail(WorkerStateEvent event) { - status.setText("Login failed"); + String msg = ""; + if (event.getSource().getException() != null) { + msg = ": " + event.getSource().getException().getMessage(); + } + status.setText("Login failed" + msg); super.onFail(event); } diff --git a/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedUpdateService.java b/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedUpdateService.java index e9577906..20c4bbe0 100644 --- a/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedUpdateService.java +++ b/src/main/java/ctbrec/sites/camsoda/CamsodaFollowedUpdateService.java @@ -42,7 +42,7 @@ public class CamsodaFollowedUpdateService extends PaginatedScheduledService { JSONObject m = following.getJSONObject(i); CamsodaModel model = (CamsodaModel) camsoda.createModel(m.getString("followname")); boolean online = m.getInt("online") == 1; - model.setOnlineState(online ? "offline" : "online"); + model.setOnlineState(online ? "online" : "offline"); model.setPreview("https://md.camsoda.com/thumbs/" + model.getName() + ".jpg"); models.add(model); } diff --git a/src/main/java/ctbrec/sites/camsoda/CamsodaModel.java b/src/main/java/ctbrec/sites/camsoda/CamsodaModel.java index fcce75ae..1a6a6269 100644 --- a/src/main/java/ctbrec/sites/camsoda/CamsodaModel.java +++ b/src/main/java/ctbrec/sites/camsoda/CamsodaModel.java @@ -25,7 +25,6 @@ import ctbrec.AbstractModel; import ctbrec.recorder.download.StreamSource; import ctbrec.sites.Site; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; public class CamsodaModel extends AbstractModel { @@ -171,29 +170,36 @@ public class CamsodaModel extends AbstractModel { @Override public boolean follow() throws IOException { - String url = Camsoda.BASE_URI + "/api/v1/follow/" + getName(); - //RequestBody body = new FormBody.Builder().build(); - LOG.debug("Sending follow request {}", url); - Request request = new Request.Builder() - .url(url) - .post(RequestBody.create(null, "")) - .addHeader("Content-Lentgh", "0") - .addHeader("Referer", Camsoda.BASE_URI + '/' + getName()) - .build(); - Response resp = site.getHttpClient().execute(request, true); - if (resp.isSuccessful()) { - System.out.println(resp.body().string()); - return true; - } else { - resp.close(); - throw new IOException("HTTP status " + resp.code() + " " + resp.message()); - } + // FIXME follow and unfollow don't work yet, because the HTTP requests need to have + // the cross-site scripting prevention header (e.g. X-CSRF-Token: YDixu6rFg3ovqos9C1YuYpsVd7bxuXlpNnZnelKG), + // but i didn't find out yet, how to get the token (cookie, hmac calc, ?!?) + throw new RuntimeException("Not implemented, yet"); + + // String url = Camsoda.BASE_URI + "/api/v1/follow/" + getName(); + // //RequestBody body = new FormBody.Builder().build(); + // LOG.debug("Sending follow request {}", url); + // Request request = new Request.Builder() + // .url(url) + // .post(RequestBody.create(null, "")) + // .addHeader("Referer", Camsoda.BASE_URI + '/' + getName()) + // .addHeader("User-Agent", " Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0") + // .addHeader("Accept", " application/json, text/plain, */*") + // .addHeader("Accept-Language", " de,en-US;q=0.7,en;q=0.3") + // .build(); + // Response resp = site.getHttpClient().execute(request, false); + // if (resp.isSuccessful()) { + // System.out.println(resp.body().string()); + // return true; + // } else { + // resp.close(); + // throw new IOException("HTTP status " + resp.code() + " " + resp.message()); + // } } @Override public boolean unfollow() throws IOException { // TODO /api/v1/unfollow/" + n.slug - return false; + throw new RuntimeException("Not implemented, yet"); } @Override