feat(api): allow disable of kobo store proxy (#337)
* chore(api): fix typing for kobo sync service * feat(api): add more paths for grimmory/kobo API * fix(api): disable kobo features if kobo is unavailable * feat(api): add proxy flag to kobo setting * feat(api): adhere to kobo proxy enabled flag * feat(ui): add forward requests toggle * fix(ui): load setting * style: use assertNotNull * fix: reduce advertised routes this cuts down the advertised routes - in particular to reduce the number of auth-related requests we will be taking on. we may eventually want to do this but I want to reduce the amount of change in this PR * fix: undo disable of kobo features This reverts commit 1b242fa6614084b05c58ff3b24e142adb1bcf729.
This commit is contained in:
@@ -11,10 +11,12 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.booklore.exception.ApiError;
|
||||||
import org.booklore.model.dto.BookLoreUser;
|
import org.booklore.model.dto.BookLoreUser;
|
||||||
import org.booklore.model.dto.Shelf;
|
import org.booklore.model.dto.Shelf;
|
||||||
import org.booklore.model.dto.kobo.*;
|
import org.booklore.model.dto.kobo.*;
|
||||||
import org.booklore.service.ShelfService;
|
import org.booklore.service.ShelfService;
|
||||||
|
import org.booklore.service.appsettings.AppSettingService;
|
||||||
import org.booklore.service.book.BookDownloadService;
|
import org.booklore.service.book.BookDownloadService;
|
||||||
import org.booklore.service.book.BookService;
|
import org.booklore.service.book.BookService;
|
||||||
import org.booklore.service.kobo.*;
|
import org.booklore.service.kobo.*;
|
||||||
@@ -27,9 +29,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import tools.jackson.core.JacksonException;
|
import tools.jackson.core.JacksonException;
|
||||||
import tools.jackson.databind.JsonNode;
|
import tools.jackson.databind.JsonNode;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ public class KoboController {
|
|||||||
|
|
||||||
private static final Pattern KOBO_V1_PRODUCTS_NEXTREAD_PATTERN = Pattern.compile(".*/v1/products/\\d+/nextread.*");
|
private static final Pattern KOBO_V1_PRODUCTS_NEXTREAD_PATTERN = Pattern.compile(".*/v1/products/\\d+/nextread.*");
|
||||||
private String token;
|
private String token;
|
||||||
|
private final AppSettingService appSettingService;
|
||||||
private final KoboServerProxy koboServerProxy;
|
private final KoboServerProxy koboServerProxy;
|
||||||
private final KoboInitializationService koboInitializationService;
|
private final KoboInitializationService koboInitializationService;
|
||||||
private final BookService bookService;
|
private final BookService bookService;
|
||||||
@@ -53,6 +54,10 @@ public class KoboController {
|
|||||||
private final ShelfService shelfService;
|
private final ShelfService shelfService;
|
||||||
private final BookDownloadService bookDownloadService;
|
private final BookDownloadService bookDownloadService;
|
||||||
|
|
||||||
|
private boolean isForwardingToKoboStore() {
|
||||||
|
return appSettingService.getAppSettings().getKoboSettings().isForwardToKoboStore();
|
||||||
|
}
|
||||||
|
|
||||||
@ModelAttribute
|
@ModelAttribute
|
||||||
public void captureToken(@PathVariable("token") String token) {
|
public void captureToken(@PathVariable("token") String token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
@@ -68,7 +73,7 @@ public class KoboController {
|
|||||||
@Operation(summary = "Sync Kobo library", description = "Sync the user's Kobo library.")
|
@Operation(summary = "Sync Kobo library", description = "Sync the user's Kobo library.")
|
||||||
@ApiResponse(responseCode = "200", description = "Library synced successfully")
|
@ApiResponse(responseCode = "200", description = "Library synced successfully")
|
||||||
@GetMapping("/v1/library/sync")
|
@GetMapping("/v1/library/sync")
|
||||||
public ResponseEntity<?> syncLibrary(@AuthenticationPrincipal BookLoreUser user) {
|
public ResponseEntity<List<Entitlement>> syncLibrary(@AuthenticationPrincipal BookLoreUser user) {
|
||||||
return koboLibrarySyncService.syncLibrary(user, token);
|
return koboLibrarySyncService.syncLibrary(user, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +102,14 @@ public class KoboController {
|
|||||||
return koboThumbnailService.getThumbnail(imageId);
|
return koboThumbnailService.getThumbnail(imageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity
|
if (isForwardingToKoboStore()) {
|
||||||
.status(HttpStatus.TEMPORARY_REDIRECT)
|
return ResponseEntity
|
||||||
.location(koboServerProxy.getKoboCDNCoverUri(imageId, width, height, isGreyscale))
|
.status(HttpStatus.TEMPORARY_REDIRECT)
|
||||||
.build();
|
.location(koboServerProxy.getKoboCDNCoverUri(imageId, width, height, isGreyscale))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "Authenticate Kobo device", description = "Authenticate a Kobo device.")
|
@Operation(summary = "Authenticate Kobo device", description = "Authenticate a Kobo device.")
|
||||||
@@ -116,8 +125,10 @@ public class KoboController {
|
|||||||
public ResponseEntity<?> getBookMetadata(@Parameter(description = "Book ID") @PathVariable String bookId) {
|
public ResponseEntity<?> getBookMetadata(@Parameter(description = "Book ID") @PathVariable String bookId) {
|
||||||
if (StringUtils.isNumeric(bookId)) {
|
if (StringUtils.isNumeric(bookId)) {
|
||||||
return ResponseEntity.ok(List.of(koboEntitlementService.getMetadataForBook(Long.parseLong(bookId), token)));
|
return ResponseEntity.ok(List.of(koboEntitlementService.getMetadataForBook(Long.parseLong(bookId), token)));
|
||||||
} else {
|
} else if(isForwardingToKoboStore()) {
|
||||||
return koboServerProxy.proxyCurrentRequest(null, false);
|
return koboServerProxy.proxyCurrentRequest(null, false);
|
||||||
|
} else {
|
||||||
|
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,8 +138,10 @@ public class KoboController {
|
|||||||
public ResponseEntity<?> getState(@Parameter(description = "Book ID") @PathVariable String bookId) {
|
public ResponseEntity<?> getState(@Parameter(description = "Book ID") @PathVariable String bookId) {
|
||||||
if (StringUtils.isNumeric(bookId)) {
|
if (StringUtils.isNumeric(bookId)) {
|
||||||
return ResponseEntity.ok(new KoboReadingStateList(koboReadingStateService.getReadingState(bookId)));
|
return ResponseEntity.ok(new KoboReadingStateList(koboReadingStateService.getReadingState(bookId)));
|
||||||
} else {
|
} else if (isForwardingToKoboStore()) {
|
||||||
return koboServerProxy.proxyCurrentRequest(null, false);
|
return koboServerProxy.proxyCurrentRequest(null, false);
|
||||||
|
} else {
|
||||||
|
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +153,10 @@ public class KoboController {
|
|||||||
@Parameter(description = "Reading state update body") @RequestBody KoboReadingStateRequest body) {
|
@Parameter(description = "Reading state update body") @RequestBody KoboReadingStateRequest body) {
|
||||||
if (StringUtils.isNumeric(bookId)) {
|
if (StringUtils.isNumeric(bookId)) {
|
||||||
return ResponseEntity.ok(koboReadingStateService.saveReadingState(body.getReadingStates()));
|
return ResponseEntity.ok(koboReadingStateService.saveReadingState(body.getReadingStates()));
|
||||||
} else {
|
} else if (isForwardingToKoboStore()) {
|
||||||
return koboServerProxy.proxyCurrentRequest(body, false);
|
return koboServerProxy.proxyCurrentRequest(body, false);
|
||||||
|
} else {
|
||||||
|
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +176,10 @@ public class KoboController {
|
|||||||
public void downloadBook(@Parameter(description = "Book ID") @PathVariable String bookId, HttpServletResponse response) {
|
public void downloadBook(@Parameter(description = "Book ID") @PathVariable String bookId, HttpServletResponse response) {
|
||||||
if (StringUtils.isNumeric(bookId)) {
|
if (StringUtils.isNumeric(bookId)) {
|
||||||
bookDownloadService.downloadKoboBook(Long.parseLong(bookId), response);
|
bookDownloadService.downloadKoboBook(Long.parseLong(bookId), response);
|
||||||
} else {
|
} else if (isForwardingToKoboStore()) {
|
||||||
koboServerProxy.proxyCurrentRequest(null, false);
|
koboServerProxy.proxyCurrentRequest(null, false);
|
||||||
|
} else {
|
||||||
|
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,8 +193,10 @@ public class KoboController {
|
|||||||
bookService.assignShelvesToBooks(Set.of(Long.valueOf(bookId)), Set.of(), Set.of(userKoboShelf.getId()));
|
bookService.assignShelvesToBooks(Set.of(Long.valueOf(bookId)), Set.of(), Set.of(userKoboShelf.getId()));
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
} else {
|
} else if (isForwardingToKoboStore()) {
|
||||||
return koboServerProxy.proxyCurrentRequest(null, false);
|
return koboServerProxy.proxyCurrentRequest(null, false);
|
||||||
|
} else {
|
||||||
|
throw ApiError.GENERIC_NOT_FOUND.createException("Not Found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,12 +205,20 @@ public class KoboController {
|
|||||||
@RequestMapping(value = "/**", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.PATCH})
|
@RequestMapping(value = "/**", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.PATCH})
|
||||||
public ResponseEntity<JsonNode> catchAll(HttpServletRequest request, @RequestBody(required = false) Object body) {
|
public ResponseEntity<JsonNode> catchAll(HttpServletRequest request, @RequestBody(required = false) Object body) {
|
||||||
String path = request.getRequestURI();
|
String path = request.getRequestURI();
|
||||||
|
|
||||||
if (path.contains("/v1/analytics/event")) {
|
if (path.contains("/v1/analytics/event")) {
|
||||||
|
// Never pass along analytics events.
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KOBO_V1_PRODUCTS_NEXTREAD_PATTERN.matcher(path).matches()) {
|
if (KOBO_V1_PRODUCTS_NEXTREAD_PATTERN.matcher(path).matches()) {
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
return koboServerProxy.proxyCurrentRequest(body, false);
|
|
||||||
|
if (isForwardingToKoboStore()) {
|
||||||
|
return koboServerProxy.proxyCurrentRequest(body, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,6 @@ public class KoboSettings {
|
|||||||
private boolean forceEnableHyphenation = false;
|
private boolean forceEnableHyphenation = false;
|
||||||
@Builder.Default @JsonSetter(nulls = Nulls.SKIP)
|
@Builder.Default @JsonSetter(nulls = Nulls.SKIP)
|
||||||
private int conversionImageCompressionPercentage = 85;
|
private int conversionImageCompressionPercentage = 85;
|
||||||
|
@Builder.Default @JsonSetter(nulls = Nulls.SKIP)
|
||||||
|
private boolean forwardToKoboStore = false;
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-18
@@ -3,6 +3,7 @@ package org.booklore.service.kobo;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.booklore.model.dto.kobo.KoboResources;
|
import org.booklore.model.dto.kobo.KoboResources;
|
||||||
|
import org.booklore.service.appsettings.AppSettingService;
|
||||||
import org.booklore.util.kobo.KoboUrlBuilder;
|
import org.booklore.util.kobo.KoboUrlBuilder;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -11,39 +12,67 @@ import tools.jackson.core.JacksonException;
|
|||||||
import tools.jackson.databind.JsonNode;
|
import tools.jackson.databind.JsonNode;
|
||||||
import tools.jackson.databind.node.ObjectNode;
|
import tools.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class KoboInitializationService {
|
public class KoboInitializationService {
|
||||||
|
|
||||||
|
private final AppSettingService appSettingService;
|
||||||
private final KoboServerProxy koboServerProxy;
|
private final KoboServerProxy koboServerProxy;
|
||||||
private final KoboResourcesComponent koboResourcesComponent;
|
private final KoboResourcesComponent koboResourcesComponent;
|
||||||
private final KoboUrlBuilder koboUrlBuilder;
|
private final KoboUrlBuilder koboUrlBuilder;
|
||||||
|
|
||||||
|
private static final Map<String, String[]> initializationResources = Map.<String, String[]>ofEntries(
|
||||||
|
Map.entry("delete_entitlement", new String[]{"v1", "library", "{Ids}"}),
|
||||||
|
Map.entry("get_tests_request", new String[]{"v1", "analytics", "gettests"}),
|
||||||
|
Map.entry("library_book", new String[]{"v1", "user", "library", "books", "{LibraryItemId}"}),
|
||||||
|
Map.entry("library_metadata", new String[]{"v1", "library", "{Ids}", "metadata"}),
|
||||||
|
Map.entry("library_search", new String[]{"v1", "library", "search"}),
|
||||||
|
Map.entry("library_sync", new String[]{"v1", "library", "sync"}),
|
||||||
|
Map.entry("post_analytics_event", new String[]{"v1", "analytics", "event"}),
|
||||||
|
Map.entry("reading_state", new String[]{"v1", "library", "{Ids}", "state"})
|
||||||
|
);
|
||||||
|
|
||||||
|
private boolean isForwardingToKoboStore() {
|
||||||
|
return appSettingService.getAppSettings().getKoboSettings().isForwardToKoboStore();
|
||||||
|
}
|
||||||
|
|
||||||
public ResponseEntity<KoboResources> initialize(String token) throws JacksonException {
|
public ResponseEntity<KoboResources> initialize(String token) throws JacksonException {
|
||||||
JsonNode resources;
|
ObjectNode resources = null;
|
||||||
|
|
||||||
JsonNode body = null;
|
if (isForwardingToKoboStore()) {
|
||||||
try {
|
try {
|
||||||
var response = koboServerProxy.proxyCurrentRequest(null, false);
|
ResponseEntity<JsonNode> response = koboServerProxy.proxyCurrentRequest(null, false);
|
||||||
body = response != null ? response.getBody() : null;
|
JsonNode body = response.getBody();
|
||||||
} catch (Exception e) {
|
JsonNode bodyResources = body == null ? null : body.get("Resources");
|
||||||
log.warn("Failed to get response from Kobo /v1/initialization, fallback to noproxy", e);
|
|
||||||
|
if (bodyResources instanceof ObjectNode objectNode) {
|
||||||
|
resources = objectNode;
|
||||||
|
} else {
|
||||||
|
log.warn("Unexpected response from Kobo /v1/initialization, fallback to noproxy");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to get response from Kobo /v1/initialization, fallback to noproxy", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resources = (body != null && body.has("Resources"))
|
if (resources == null) {
|
||||||
? body.get("Resources")
|
resources = koboResourcesComponent.getResources();
|
||||||
: koboResourcesComponent.getResources();
|
|
||||||
|
|
||||||
if (resources instanceof ObjectNode objectNode) {
|
|
||||||
UriComponentsBuilder baseBuilder = koboUrlBuilder.baseBuilder();
|
|
||||||
|
|
||||||
objectNode.put("image_host", baseBuilder.build().toUriString());
|
|
||||||
objectNode.put("image_url_template", koboUrlBuilder.imageUrlTemplate(token));
|
|
||||||
objectNode.put("image_url_quality_template", koboUrlBuilder.imageUrlQualityTemplate(token));
|
|
||||||
objectNode.put("library_sync", koboUrlBuilder.librarySyncUrl(token));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UriComponentsBuilder baseBuilder = koboUrlBuilder.baseBuilder();
|
||||||
|
|
||||||
|
for (String name : initializationResources.keySet()) {
|
||||||
|
resources.put(name, koboUrlBuilder.withBaseUrl(token, initializationResources.get(name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build extra routes for CDN
|
||||||
|
resources.put("image_host", baseBuilder.build().toUriString());
|
||||||
|
resources.put("image_url_template", koboUrlBuilder.imageUrlTemplate(token));
|
||||||
|
resources.put("image_url_quality_template", koboUrlBuilder.imageUrlQualityTemplate(token));
|
||||||
|
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.header("x-kobo-apitoken", "e30=")
|
.header("x-kobo-apitoken", "e30=")
|
||||||
.body(new KoboResources(resources));
|
.body(new KoboResources(resources));
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.booklore.model.entity.KoboSnapshotBookEntity;
|
|||||||
import org.booklore.model.entity.UserBookProgressEntity;
|
import org.booklore.model.entity.UserBookProgressEntity;
|
||||||
import org.booklore.repository.KoboDeletedBookProgressRepository;
|
import org.booklore.repository.KoboDeletedBookProgressRepository;
|
||||||
import org.booklore.repository.UserBookProgressRepository;
|
import org.booklore.repository.UserBookProgressRepository;
|
||||||
|
import org.booklore.service.appsettings.AppSettingService;
|
||||||
import org.booklore.util.RequestUtils;
|
import org.booklore.util.RequestUtils;
|
||||||
import org.booklore.util.kobo.BookloreSyncTokenGenerator;
|
import org.booklore.util.kobo.BookloreSyncTokenGenerator;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
@@ -38,6 +39,7 @@ public class KoboLibrarySyncService {
|
|||||||
private final KoboServerProxy koboServerProxy;
|
private final KoboServerProxy koboServerProxy;
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
private final KoboSettingsService koboSettingsService;
|
private final KoboSettingsService koboSettingsService;
|
||||||
|
private final AppSettingService appSettingService;
|
||||||
|
|
||||||
private Collection<Entitlement> getEntitlementsFromKoboStoreResponse(ResponseEntity<JsonNode> koboStoreResponse) {
|
private Collection<Entitlement> getEntitlementsFromKoboStoreResponse(ResponseEntity<JsonNode> koboStoreResponse) {
|
||||||
return Optional.ofNullable(koboStoreResponse.getBody())
|
return Optional.ofNullable(koboStoreResponse.getBody())
|
||||||
@@ -64,8 +66,13 @@ public class KoboLibrarySyncService {
|
|||||||
.orElse(Collections.emptyList());
|
.orElse(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isForwardingToKoboStore() {
|
||||||
|
return appSettingService.getAppSettings().getKoboSettings().isForwardToKoboStore();
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<?> syncLibrary(BookLoreUser user, String token) {
|
public ResponseEntity<List<Entitlement>> syncLibrary(BookLoreUser user, String token) {
|
||||||
HttpServletRequest request = RequestUtils.getCurrentRequest();
|
HttpServletRequest request = RequestUtils.getCurrentRequest();
|
||||||
BookloreSyncToken syncToken = Optional.ofNullable(tokenGenerator.fromRequestHeaders(request)).orElse(new BookloreSyncToken());
|
BookloreSyncToken syncToken = Optional.ofNullable(tokenGenerator.fromRequestHeaders(request)).orElse(new BookloreSyncToken());
|
||||||
|
|
||||||
@@ -134,7 +141,7 @@ public class KoboLibrarySyncService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shouldContinueSync) {
|
if (!shouldContinueSync && isForwardingToKoboStore()) {
|
||||||
ResponseEntity<JsonNode> koboStoreResponse = null;
|
ResponseEntity<JsonNode> koboStoreResponse = null;
|
||||||
try {
|
try {
|
||||||
koboStoreResponse = koboServerProxy.proxyCurrentRequest(null, true);
|
koboStoreResponse = koboServerProxy.proxyCurrentRequest(null, true);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package org.booklore.service.kobo;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import tools.jackson.core.JacksonException;
|
import tools.jackson.core.JacksonException;
|
||||||
import tools.jackson.databind.JsonNode;
|
|
||||||
import tools.jackson.databind.ObjectMapper;
|
import tools.jackson.databind.ObjectMapper;
|
||||||
|
import tools.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Component
|
@Component
|
||||||
@@ -12,8 +12,8 @@ public class KoboResourcesComponent {
|
|||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
public JsonNode getResources() throws JacksonException {
|
public ObjectNode getResources() throws JacksonException {
|
||||||
return objectMapper.readTree(
|
return (ObjectNode) objectMapper.readTree(
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"account_page": "https://www.kobo.com/account/settings",
|
"account_page": "https://www.kobo.com/account/settings",
|
||||||
|
|||||||
@@ -44,31 +44,28 @@ public class KoboUrlBuilder {
|
|||||||
return ("http".equals(scheme) && port == 80) || ("https".equals(scheme) && port == 443);
|
return ("http".equals(scheme) && port == 80) || ("https".equals(scheme) && port == 443);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String downloadUrl(String token, Long bookId) {
|
public String withBaseUrl(String token, String... pathSegments) {
|
||||||
return baseBuilder()
|
UriComponentsBuilder builder = baseBuilder()
|
||||||
.pathSegment("api", "kobo", token, "v1", "books", "{bookId}", "download")
|
.pathSegment("api", "kobo", token);
|
||||||
.buildAndExpand(bookId)
|
|
||||||
|
for (String p : pathSegments) {
|
||||||
|
builder.pathSegment(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder
|
||||||
|
.build()
|
||||||
.toUriString();
|
.toUriString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String downloadUrl(String token, Long bookId) {
|
||||||
|
return withBaseUrl(token, "v1", "books", bookId.toString(), "download");
|
||||||
|
}
|
||||||
|
|
||||||
public String imageUrlTemplate(String token) {
|
public String imageUrlTemplate(String token) {
|
||||||
return baseBuilder()
|
return withBaseUrl( token, "v1", "books", "{ImageId}", "thumbnail", "{Width}", "{Height}", "false", "image.jpg");
|
||||||
.pathSegment("api", "kobo", token, "v1", "books", "{ImageId}", "thumbnail", "{Width}", "{Height}", "false", "image.jpg")
|
|
||||||
.build()
|
|
||||||
.toUriString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String imageUrlQualityTemplate(String token) {
|
public String imageUrlQualityTemplate(String token) {
|
||||||
return baseBuilder()
|
return withBaseUrl( token, "v1", "books", "{ImageId}", "thumbnail", "{Width}", "{Height}", "{Quality}", "{IsGreyscale}", "image.jpg");
|
||||||
.pathSegment("api", "kobo", token, "v1", "books", "{ImageId}", "thumbnail", "{Width}", "{Height}", "{Quality}", "{IsGreyscale}", "image.jpg")
|
|
||||||
.build()
|
|
||||||
.toUriString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String librarySyncUrl(String token) {
|
|
||||||
return baseBuilder()
|
|
||||||
.pathSegment("api", "kobo", token, "v1", "library", "sync")
|
|
||||||
.build()
|
|
||||||
.toUriString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+53
-6
@@ -1,6 +1,9 @@
|
|||||||
package org.booklore.service.kobo;
|
package org.booklore.service.kobo;
|
||||||
|
|
||||||
import org.booklore.model.dto.kobo.KoboResources;
|
import org.booklore.model.dto.kobo.KoboResources;
|
||||||
|
import org.booklore.model.dto.settings.AppSettings;
|
||||||
|
import org.booklore.model.dto.settings.KoboSettings;
|
||||||
|
import org.booklore.service.appsettings.AppSettingService;
|
||||||
import org.booklore.util.kobo.KoboUrlBuilder;
|
import org.booklore.util.kobo.KoboUrlBuilder;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
@@ -10,6 +13,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
import tools.jackson.databind.JsonNode;
|
import tools.jackson.databind.JsonNode;
|
||||||
@@ -20,10 +25,14 @@ import tools.jackson.databind.node.ObjectNode;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
@DisplayName("KoboInitializationService Tests")
|
@DisplayName("KoboInitializationService Tests")
|
||||||
class KoboInitializationServiceTest {
|
class KoboInitializationServiceTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AppSettingService appSettingService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private KoboServerProxy koboServerProxy;
|
private KoboServerProxy koboServerProxy;
|
||||||
|
|
||||||
@@ -38,12 +47,25 @@ class KoboInitializationServiceTest {
|
|||||||
|
|
||||||
private final ObjectMapper objectMapper = JsonMapper.builder().build();
|
private final ObjectMapper objectMapper = JsonMapper.builder().build();
|
||||||
|
|
||||||
|
void mockWithForwardingToKoboStore(boolean enabled) {
|
||||||
|
KoboSettings koboSettings = KoboSettings.builder()
|
||||||
|
.forwardToKoboStore(enabled)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
AppSettings appSettings = AppSettings.builder()
|
||||||
|
.koboSettings(koboSettings)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
when(koboUrlBuilder.baseBuilder()).thenReturn(UriComponentsBuilder.fromUriString("http://localhost:8080"));
|
when(koboUrlBuilder.baseBuilder()).thenReturn(UriComponentsBuilder.fromUriString("http://localhost:8080"));
|
||||||
|
when(koboUrlBuilder.withBaseUrl(eq("test-token"), any())).thenReturn("http://localhost:8080/with-base-url");
|
||||||
when(koboUrlBuilder.imageUrlTemplate("test-token")).thenReturn("http://localhost:8080/kobo/test-token/image/{ImageId}/{Width}/{Height}/false/image.jpg");
|
when(koboUrlBuilder.imageUrlTemplate("test-token")).thenReturn("http://localhost:8080/kobo/test-token/image/{ImageId}/{Width}/{Height}/false/image.jpg");
|
||||||
when(koboUrlBuilder.imageUrlQualityTemplate("test-token")).thenReturn("http://localhost:8080/kobo/test-token/image/{ImageId}/{Width}/{Height}/{Quality}/{IsGreyscale}/image.jpg");
|
when(koboUrlBuilder.imageUrlQualityTemplate("test-token")).thenReturn("http://localhost:8080/kobo/test-token/image/{ImageId}/{Width}/{Height}/{Quality}/{IsGreyscale}/image.jpg");
|
||||||
when(koboUrlBuilder.librarySyncUrl("test-token")).thenReturn("http://localhost:8080/kobo/test-token/v1/library/sync");
|
mockWithForwardingToKoboStore(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
@@ -54,7 +76,7 @@ class KoboInitializationServiceTest {
|
|||||||
@DisplayName("Should use Resources from Kobo proxy response")
|
@DisplayName("Should use Resources from Kobo proxy response")
|
||||||
void initialize_usesProxyResources() throws Exception {
|
void initialize_usesProxyResources() throws Exception {
|
||||||
ObjectNode resources = objectMapper.createObjectNode();
|
ObjectNode resources = objectMapper.createObjectNode();
|
||||||
resources.put("library_sync", "https://storeapi.kobo.com/v1/library/sync");
|
resources.put("example", "https://storeapi.kobo.com/v1/library/sync");
|
||||||
resources.put("image_host", "https://cdn.kobo.com/book-images/");
|
resources.put("image_host", "https://cdn.kobo.com/book-images/");
|
||||||
|
|
||||||
ObjectNode body = objectMapper.createObjectNode();
|
ObjectNode body = objectMapper.createObjectNode();
|
||||||
@@ -68,7 +90,7 @@ class KoboInitializationServiceTest {
|
|||||||
assertEquals(200, response.getStatusCode().value());
|
assertEquals(200, response.getStatusCode().value());
|
||||||
assertNotNull(response.getBody());
|
assertNotNull(response.getBody());
|
||||||
JsonNode result = response.getBody().getResources();
|
JsonNode result = response.getBody().getResources();
|
||||||
assertEquals("http://localhost:8080/kobo/test-token/v1/library/sync", result.get("library_sync").asText());
|
assertEquals("https://storeapi.kobo.com/v1/library/sync", result.get("example").asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -128,6 +150,31 @@ class KoboInitializationServiceTest {
|
|||||||
verify(koboResourcesComponent).getResources();
|
verify(koboResourcesComponent).getResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Should fall back to local resources when proxy is disabled")
|
||||||
|
void initialize_fallsBackOnProxyDisabled() throws Exception {
|
||||||
|
mockWithForwardingToKoboStore(false);
|
||||||
|
|
||||||
|
ObjectNode resources = objectMapper.createObjectNode();
|
||||||
|
resources.put("example", "https://storeapi.kobo.com/v1/library/sync");
|
||||||
|
ObjectNode requestBody = objectMapper.createObjectNode();
|
||||||
|
requestBody.set("Resources", resources);
|
||||||
|
|
||||||
|
when(koboServerProxy.proxyCurrentRequest(null, false))
|
||||||
|
.thenReturn(ResponseEntity.ok(requestBody));
|
||||||
|
|
||||||
|
ObjectNode fallbackResources = objectMapper.createObjectNode();
|
||||||
|
fallbackResources.put("example", "http://127.0.0.1/v1/library/sync");
|
||||||
|
when(koboResourcesComponent.getResources()).thenReturn(fallbackResources);
|
||||||
|
|
||||||
|
ResponseEntity<KoboResources> response = service.initialize("test-token");
|
||||||
|
|
||||||
|
var body = response.getBody();
|
||||||
|
|
||||||
|
assertNotNull(body);
|
||||||
|
assertEquals("http://127.0.0.1/v1/library/sync", body.getResources().get("example").asText());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Should fall back to local resources when proxy throws exception")
|
@DisplayName("Should fall back to local resources when proxy throws exception")
|
||||||
void initialize_fallsBackOnProxyException() throws Exception {
|
void initialize_fallsBackOnProxyException() throws Exception {
|
||||||
@@ -154,14 +201,14 @@ class KoboInitializationServiceTest {
|
|||||||
.thenReturn(ResponseEntity.ok(body));
|
.thenReturn(ResponseEntity.ok(body));
|
||||||
|
|
||||||
ObjectNode fallbackResources = objectMapper.createObjectNode();
|
ObjectNode fallbackResources = objectMapper.createObjectNode();
|
||||||
fallbackResources.put("library_sync", "https://storeapi.kobo.com/v1/library/sync");
|
fallbackResources.put("example", "https://storeapi.kobo.com/v1/example");
|
||||||
when(koboResourcesComponent.getResources()).thenReturn(fallbackResources);
|
when(koboResourcesComponent.getResources()).thenReturn(fallbackResources);
|
||||||
|
|
||||||
ResponseEntity<KoboResources> response = service.initialize("test-token");
|
ResponseEntity<KoboResources> response = service.initialize("test-token");
|
||||||
|
|
||||||
verify(koboResourcesComponent).getResources();
|
verify(koboResourcesComponent).getResources();
|
||||||
assertEquals("http://localhost:8080/kobo/test-token/v1/library/sync",
|
assertEquals("https://storeapi.kobo.com/v1/example",
|
||||||
response.getBody().getResources().get("library_sync").asText());
|
response.getBody().getResources().get("example").asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -33,64 +33,29 @@ class KoboUrlBuilderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDownloadUrl() {
|
void testDownloadUrl() {
|
||||||
String token = "testToken";
|
String expected = "http://localhost:6060/api/kobo/testToken/v1/books/123/download";
|
||||||
Long bookId = 123L;
|
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl(token, bookId);
|
String actual = koboUrlBuilder.downloadUrl("testToken", 123L);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertEquals(expected, actual);
|
||||||
assertTrue(result.contains("/api/kobo/" + token + "/v1/books/" + bookId + "/download"));
|
|
||||||
assertTrue(result.startsWith("http://"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDownloadUrlPreservesPort() {
|
|
||||||
String token = "testToken";
|
|
||||||
Long bookId = 123L;
|
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl(token, bookId);
|
|
||||||
|
|
||||||
assertTrue(result.startsWith("http://localhost:6060/"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testImageUrlTemplate() {
|
void testImageUrlTemplate() {
|
||||||
String token = "testToken";
|
String expected = "http://localhost:6060/api/kobo/testToken/v1/books/{ImageId}/thumbnail/{Width}/{Height}/false/image.jpg";
|
||||||
|
|
||||||
String result = koboUrlBuilder.imageUrlTemplate(token);
|
String actual = koboUrlBuilder.imageUrlTemplate("testToken");
|
||||||
|
|
||||||
assertNotNull(result);
|
assertEquals(expected, actual);
|
||||||
assertTrue(result.contains("/api/kobo/" + token + "/v1/books/"));
|
|
||||||
assertTrue(result.contains("{ImageId}"));
|
|
||||||
assertTrue(result.contains("{Width}"));
|
|
||||||
assertTrue(result.contains("{Height}"));
|
|
||||||
assertTrue(result.contains("image.jpg"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testImageUrlQualityTemplate() {
|
void testImageUrlQualityTemplate() {
|
||||||
String token = "testToken";
|
String expected = "http://localhost:6060/api/kobo/testToken/v1/books/{ImageId}/thumbnail/{Width}/{Height}/{Quality}/{IsGreyscale}/image.jpg";
|
||||||
|
|
||||||
String result = koboUrlBuilder.imageUrlQualityTemplate(token);
|
String actual = koboUrlBuilder.imageUrlQualityTemplate("testToken");
|
||||||
|
|
||||||
assertNotNull(result);
|
assertEquals(expected, actual);
|
||||||
assertTrue(result.contains("/api/kobo/" + token + "/v1/books/"));
|
|
||||||
assertTrue(result.contains("{ImageId}"));
|
|
||||||
assertTrue(result.contains("{Width}"));
|
|
||||||
assertTrue(result.contains("{Height}"));
|
|
||||||
assertTrue(result.contains("{Quality}"));
|
|
||||||
assertTrue(result.contains("{IsGreyscale}"));
|
|
||||||
assertTrue(result.contains("image.jpg"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testLibrarySyncUrl() {
|
|
||||||
String token = "testToken";
|
|
||||||
|
|
||||||
String result = koboUrlBuilder.librarySyncUrl(token);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
|
||||||
assertTrue(result.contains("/api/kobo/" + token + "/v1/library/sync"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -98,13 +63,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setServerName("192.168.1.100");
|
mockRequest.setServerName("192.168.1.100");
|
||||||
mockRequest.setServerPort(6060);
|
mockRequest.setServerPort(6060);
|
||||||
|
|
||||||
String token = "testToken";
|
String expected = "http://192.168.1.100:6060/api/kobo/testToken";
|
||||||
Long bookId = 123L;
|
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl(token, bookId);
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
|
|
||||||
assertTrue(result.startsWith("http://192.168.1.100:6060/"));
|
assertEquals(expected, actual);
|
||||||
assertTrue(result.contains("/api/kobo/" + token + "/v1/books/" + bookId + "/download"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -112,15 +75,13 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setScheme("https");
|
mockRequest.setScheme("https");
|
||||||
mockRequest.setServerName("books.example.com");
|
mockRequest.setServerName("books.example.com");
|
||||||
mockRequest.setServerPort(443);
|
mockRequest.setServerPort(443);
|
||||||
|
mockRequest.setLocalPort(443);
|
||||||
|
|
||||||
String token = "testToken";
|
String expected = "https://books.example.com/api/kobo/testToken";
|
||||||
Long bookId = 123L;
|
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl(token, bookId);
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
|
|
||||||
assertTrue(result.startsWith("https://books.example.com"));
|
assertEquals(expected, actual);
|
||||||
assertFalse(result.contains(":443"));
|
|
||||||
assertTrue(result.contains("/api/kobo/" + token + "/v1/books/" + bookId + "/download"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -132,10 +93,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setServerPort(80);
|
mockRequest.setServerPort(80);
|
||||||
mockRequest.setLocalPort(6060);
|
mockRequest.setLocalPort(6060);
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
String expected = "http://192.168.1.100:6060/api/kobo/testToken";
|
||||||
|
|
||||||
assertTrue(result.startsWith("http://192.168.1.100:6060/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
assertTrue(result.contains("/api/kobo/testToken/v1/books/123/download"));
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -144,9 +106,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setServerPort(80);
|
mockRequest.setServerPort(80);
|
||||||
mockRequest.setLocalPort(6060);
|
mockRequest.setLocalPort(6060);
|
||||||
|
|
||||||
assertTrue(koboUrlBuilder.imageUrlTemplate("t").startsWith("http://192.168.1.100:6060/"));
|
String expected = "http://192.168.1.100:6060/api/kobo/testToken";
|
||||||
assertTrue(koboUrlBuilder.imageUrlQualityTemplate("t").startsWith("http://192.168.1.100:6060/"));
|
|
||||||
assertTrue(koboUrlBuilder.librarySyncUrl("t").startsWith("http://192.168.1.100:6060/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -157,10 +121,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setLocalPort(6060);
|
mockRequest.setLocalPort(6060);
|
||||||
mockRequest.addHeader("X-Forwarded-Proto", "https");
|
mockRequest.addHeader("X-Forwarded-Proto", "https");
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
String expected = "https://books.example.com/api/kobo/testToken";
|
||||||
|
|
||||||
assertTrue(result.startsWith("https://books.example.com/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
assertFalse(result.contains(":6060"));
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -171,10 +136,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setLocalPort(6060);
|
mockRequest.setLocalPort(6060);
|
||||||
mockRequest.addHeader("X-Forwarded-Host", "books.example.com");
|
mockRequest.addHeader("X-Forwarded-Host", "books.example.com");
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
String expected = "https://books.example.com/api/kobo/testToken";
|
||||||
|
|
||||||
assertTrue(result.startsWith("https://books.example.com/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
assertFalse(result.contains(":6060"));
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -185,10 +151,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setLocalPort(6060);
|
mockRequest.setLocalPort(6060);
|
||||||
mockRequest.addHeader("X-Forwarded-Port", "443");
|
mockRequest.addHeader("X-Forwarded-Port", "443");
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
String expected = "https://books.example.com/api/kobo/testToken";
|
||||||
|
|
||||||
assertTrue(result.startsWith("https://books.example.com/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
assertFalse(result.contains(":6060"));
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -199,10 +166,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setLocalPort(6060);
|
mockRequest.setLocalPort(6060);
|
||||||
mockRequest.addHeader("Forwarded", "proto=https;host=books.example.com");
|
mockRequest.addHeader("Forwarded", "proto=https;host=books.example.com");
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
String expected = "https://books.example.com/api/kobo/testToken";
|
||||||
|
|
||||||
assertTrue(result.startsWith("https://books.example.com/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
assertFalse(result.contains(":6060"));
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -213,9 +181,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setLocalPort(6060);
|
mockRequest.setLocalPort(6060);
|
||||||
mockRequest.addHeader("X-Forwarded-Port", "8443");
|
mockRequest.addHeader("X-Forwarded-Port", "8443");
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
String expected = "https://books.example.com:8443/api/kobo/testToken";
|
||||||
|
|
||||||
assertTrue(result.startsWith("https://books.example.com:8443/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -224,10 +194,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setServerPort(80);
|
mockRequest.setServerPort(80);
|
||||||
mockRequest.setLocalPort(80);
|
mockRequest.setLocalPort(80);
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
String expected = "http://192.168.1.100/api/kobo/testToken";
|
||||||
|
|
||||||
assertTrue(result.startsWith("http://192.168.1.100/"));
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
assertFalse(result.contains(":80"));
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -237,9 +208,11 @@ class KoboUrlBuilderTest {
|
|||||||
mockRequest.setServerPort(443);
|
mockRequest.setServerPort(443);
|
||||||
mockRequest.setLocalPort(443);
|
mockRequest.setLocalPort(443);
|
||||||
|
|
||||||
String result = koboUrlBuilder.downloadUrl("testToken", 123L);
|
|
||||||
|
|
||||||
assertTrue(result.startsWith("https://192.168.1.100/"));
|
String expected = "https://192.168.1.100/api/kobo/testToken";
|
||||||
assertFalse(result.contains(":443"));
|
|
||||||
|
String actual = koboUrlBuilder.withBaseUrl("testToken");
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
@@ -309,6 +309,24 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p-divider></p-divider>
|
||||||
|
|
||||||
|
<div class="setting-item">
|
||||||
|
<div class="setting-info">
|
||||||
|
<div class="setting-label-row">
|
||||||
|
<span class="setting-label">{{ t('kobo.forwardToKoboStore') }}</span>
|
||||||
|
<p-toggle-switch
|
||||||
|
id="forwardToKoboStore"
|
||||||
|
[(ngModel)]="koboSettings.forwardToKoboStore"
|
||||||
|
(ngModelChange)="onToggleChange()">
|
||||||
|
</p-toggle-switch>
|
||||||
|
</div>
|
||||||
|
<p class="setting-description">
|
||||||
|
{{ t('kobo.forwardToKoboStoreDesc') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -52,7 +52,8 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
|||||||
convertCbxToEpub: false,
|
convertCbxToEpub: false,
|
||||||
conversionImageCompressionPercentage: 85,
|
conversionImageCompressionPercentage: 85,
|
||||||
conversionLimitInMbForCbx: 100,
|
conversionLimitInMbForCbx: 100,
|
||||||
forceEnableHyphenation: false
|
forceEnableHyphenation: false,
|
||||||
|
forwardToKoboStore: false
|
||||||
};
|
};
|
||||||
|
|
||||||
koboSyncSettings: KoboSyncSettings = {
|
koboSyncSettings: KoboSyncSettings = {
|
||||||
@@ -138,6 +139,7 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
|||||||
this.koboSettings.conversionLimitInMbForCbx = settings.koboSettings?.conversionLimitInMbForCbx ?? 100;
|
this.koboSettings.conversionLimitInMbForCbx = settings.koboSettings?.conversionLimitInMbForCbx ?? 100;
|
||||||
this.koboSettings.forceEnableHyphenation = settings.koboSettings?.forceEnableHyphenation ?? false;
|
this.koboSettings.forceEnableHyphenation = settings.koboSettings?.forceEnableHyphenation ?? false;
|
||||||
this.koboSettings.conversionImageCompressionPercentage = settings.koboSettings?.conversionImageCompressionPercentage ?? 85;
|
this.koboSettings.conversionImageCompressionPercentage = settings.koboSettings?.conversionImageCompressionPercentage ?? 85;
|
||||||
|
this.koboSettings.forwardToKoboStore = settings.koboSettings?.forwardToKoboStore ?? false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ export interface KoboSettings {
|
|||||||
convertCbxToEpub: boolean;
|
convertCbxToEpub: boolean;
|
||||||
conversionLimitInMbForCbx: number;
|
conversionLimitInMbForCbx: number;
|
||||||
forceEnableHyphenation: boolean;
|
forceEnableHyphenation: boolean;
|
||||||
|
forwardToKoboStore: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CoverCroppingSettings {
|
export interface CoverCroppingSettings {
|
||||||
|
|||||||
@@ -102,7 +102,9 @@
|
|||||||
"autoAddEnabled": "New books will be automatically added to Kobo shelf",
|
"autoAddEnabled": "New books will be automatically added to Kobo shelf",
|
||||||
"autoAddDisabled": "Auto-add to Kobo shelf disabled",
|
"autoAddDisabled": "Auto-add to Kobo shelf disabled",
|
||||||
"pros": "Pros:",
|
"pros": "Pros:",
|
||||||
"cons": "Cons:"
|
"cons": "Cons:",
|
||||||
|
"forwardToKoboStore": "Forward to Rakuten Kobo Store",
|
||||||
|
"forwardToKoboStoreDesc": "Combines your Grimmory requests with requests from the Rakuten Kobo Store, so users can still access purchased books and get recommendations."
|
||||||
},
|
},
|
||||||
"hardcover": {
|
"hardcover": {
|
||||||
"title": "Hardcover Integration",
|
"title": "Hardcover Integration",
|
||||||
|
|||||||
Reference in New Issue
Block a user