Fix Camsoda thumbnails
This commit is contained in:
parent
68c68a126a
commit
91b82b16a9
|
@ -1,21 +1,5 @@
|
||||||
package ctbrec.ui.sites.camsoda;
|
package ctbrec.ui.sites.camsoda;
|
||||||
|
|
||||||
import static ctbrec.Model.State.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.StringUtil;
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
|
@ -25,14 +9,26 @@ import ctbrec.ui.SiteUiFactory;
|
||||||
import ctbrec.ui.tabs.PaginatedScheduledService;
|
import ctbrec.ui.tabs.PaginatedScheduledService;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static ctbrec.Model.State.OFFLINE;
|
||||||
|
import static ctbrec.Model.State.ONLINE;
|
||||||
|
|
||||||
public class CamsodaUpdateService extends PaginatedScheduledService {
|
public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(CamsodaUpdateService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(CamsodaUpdateService.class);
|
||||||
|
|
||||||
private String url;
|
private final String url;
|
||||||
private boolean loginRequired;
|
private final boolean loginRequired;
|
||||||
private Camsoda camsoda;
|
private final Camsoda camsoda;
|
||||||
int modelsPerPage = 50;
|
int modelsPerPage = 50;
|
||||||
|
|
||||||
private Predicate<CamsodaModel> filter;
|
private Predicate<CamsodaModel> filter;
|
||||||
|
@ -46,13 +42,13 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Task<List<Model>> createTask() {
|
protected Task<List<Model>> createTask() {
|
||||||
return new Task<List<Model>>() {
|
return new Task<>() {
|
||||||
@Override
|
@Override
|
||||||
public List<Model> call() throws IOException {
|
public List<Model> call() throws IOException {
|
||||||
return loadOnlineModels().stream()
|
return loadOnlineModels().stream()
|
||||||
.sorted((m1,m2) -> (int)(m2.getSortOrder() - m1.getSortOrder()))
|
.sorted((m1, m2) -> (int) (m2.getSortOrder() - m1.getSortOrder()))
|
||||||
.filter(filter)
|
.filter(filter)
|
||||||
.skip( (page-1) * (long)modelsPerPage)
|
.skip((page - 1) * (long) modelsPerPage)
|
||||||
.limit(modelsPerPage)
|
.limit(modelsPerPage)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
@ -70,7 +66,7 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
var request = new Request.Builder().url(url).build();
|
var request = new Request.Builder().url(url).build();
|
||||||
try (var response = camsoda.getHttpClient().execute(request)) {
|
try (var response = camsoda.getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
return parseModels(response.body().string());
|
return parseModels(Objects.requireNonNull(response.body(), "HTTP response body is null").string());
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
|
@ -105,8 +101,12 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
CamsodaModel model = (CamsodaModel) camsoda.createModel(name);
|
CamsodaModel model = (CamsodaModel) camsoda.createModel(name);
|
||||||
model.setSortOrder(tpl.getFloat(getTemplateIndex(template, "sort_value")));
|
model.setSortOrder(tpl.getFloat(getTemplateIndex(template, "sort_value")));
|
||||||
model.setDescription(tpl.getString(getTemplateIndex(template, "subject_html")));
|
model.setDescription(tpl.getString(getTemplateIndex(template, "subject_html")));
|
||||||
var preview = "https:" + tpl.getString(getTemplateIndex(template, "thumb"));
|
var preview = tpl.getString(getTemplateIndex(template, "thumb"));
|
||||||
|
if (preview.startsWith("//")) {
|
||||||
|
preview = "https:" + preview;
|
||||||
|
}
|
||||||
model.setPreview(preview);
|
model.setPreview(preview);
|
||||||
|
LOG.info("Preview: {}", preview);
|
||||||
model.setOnlineStateByStatus(tpl.getString(getTemplateIndex(template, "status")));
|
model.setOnlineStateByStatus(tpl.getString(getTemplateIndex(template, "status")));
|
||||||
var displayName = tpl.getString(getTemplateIndex(template, "display_name"));
|
var displayName = tpl.getString(getTemplateIndex(template, "display_name"));
|
||||||
model.setDisplayName(displayName.replaceAll("[^a-zA-Z0-9]", ""));
|
model.setDisplayName(displayName.replaceAll("[^a-zA-Z0-9]", ""));
|
||||||
|
@ -124,7 +124,10 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
model.setSortOrder(tpl.getFloat(Integer.toString(getTemplateIndex(template, "sort_value"))));
|
model.setSortOrder(tpl.getFloat(Integer.toString(getTemplateIndex(template, "sort_value"))));
|
||||||
model.setNew(result.optBoolean("new"));
|
model.setNew(result.optBoolean("new"));
|
||||||
model.setGender(tpl.getString(Integer.toString(getTemplateIndex(template, "gender"))));
|
model.setGender(tpl.getString(Integer.toString(getTemplateIndex(template, "gender"))));
|
||||||
var preview = "https:" + tpl.getString(Integer.toString(getTemplateIndex(template, "thumb")));
|
var preview = tpl.getString(Integer.toString(getTemplateIndex(template, "thumb")));
|
||||||
|
if (preview.startsWith("//")) {
|
||||||
|
preview = "https:" + preview;
|
||||||
|
}
|
||||||
model.setPreview(preview);
|
model.setPreview(preview);
|
||||||
var displayName = tpl.getString(Integer.toString(getTemplateIndex(template, "display_name")));
|
var displayName = tpl.getString(Integer.toString(getTemplateIndex(template, "display_name")));
|
||||||
model.setDisplayName(displayName.replaceAll("[^a-zA-Z0-9]", ""));
|
model.setDisplayName(displayName.replaceAll("[^a-zA-Z0-9]", ""));
|
||||||
|
@ -154,7 +157,7 @@ public class CamsodaUpdateService extends PaginatedScheduledService {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new NoSuchElementException(string + " not found in template: " + template.toString());
|
throw new NoSuchElementException(string + " not found in template: " + template);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFilter(Predicate<CamsodaModel> filter) {
|
public void setFilter(Predicate<CamsodaModel> filter) {
|
||||||
|
|
|
@ -461,7 +461,7 @@ public class ThumbCell extends StackPane {
|
||||||
throw new HttpException(resp.code(), resp.message());
|
throw new HttpException(resp.code(), resp.message());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warn("Error loading thumbnail: {}", e.getLocalizedMessage());
|
LOG.warn("Error loading thumbnail: {} {}", url, e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue