Merge pull request #988 from booklore-app/develop
Merge develop into master for release
This commit is contained in:
@@ -8,6 +8,9 @@ categories:
|
|||||||
- title: '✨ Enhancements'
|
- title: '✨ Enhancements'
|
||||||
labels:
|
labels:
|
||||||
- 'enhancement'
|
- 'enhancement'
|
||||||
|
- title: '🎨 UI Tweaks'
|
||||||
|
labels:
|
||||||
|
- 'ui-tweaks'
|
||||||
- title: '🐛 Bug Fixes'
|
- title: '🐛 Bug Fixes'
|
||||||
labels:
|
labels:
|
||||||
- 'bug'
|
- 'bug'
|
||||||
|
|||||||
+9
-7
@@ -6,14 +6,12 @@ import com.adityachandel.booklore.model.dto.kobo.KoboAuthentication;
|
|||||||
import com.adityachandel.booklore.model.dto.kobo.KoboReadingStateWrapper;
|
import com.adityachandel.booklore.model.dto.kobo.KoboReadingStateWrapper;
|
||||||
import com.adityachandel.booklore.model.dto.kobo.KoboResources;
|
import com.adityachandel.booklore.model.dto.kobo.KoboResources;
|
||||||
import com.adityachandel.booklore.model.dto.kobo.KoboTestResponse;
|
import com.adityachandel.booklore.model.dto.kobo.KoboTestResponse;
|
||||||
import com.adityachandel.booklore.service.BookService;
|
import com.adityachandel.booklore.service.*;
|
||||||
import com.adityachandel.booklore.service.KoboEntitlementService;
|
|
||||||
import com.adityachandel.booklore.service.KoboReadingStateService;
|
|
||||||
import com.adityachandel.booklore.service.ShelfService;
|
|
||||||
import com.adityachandel.booklore.service.kobo.*;
|
import com.adityachandel.booklore.service.kobo.*;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
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;
|
||||||
@@ -23,6 +21,9 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ public class KoboController {
|
|||||||
private final KoboLibrarySyncService koboLibrarySyncService;
|
private final KoboLibrarySyncService koboLibrarySyncService;
|
||||||
private final KoboThumbnailService koboThumbnailService;
|
private final KoboThumbnailService koboThumbnailService;
|
||||||
private final ShelfService shelfService;
|
private final ShelfService shelfService;
|
||||||
|
private final BookDownloadService bookDownloadService;
|
||||||
|
|
||||||
@ModelAttribute
|
@ModelAttribute
|
||||||
public void captureToken(@PathVariable("token") String token) {
|
public void captureToken(@PathVariable("token") String token) {
|
||||||
@@ -129,11 +131,11 @@ public class KoboController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/v1/books/{bookId}/download")
|
@GetMapping("/v1/books/{bookId}/download")
|
||||||
public ResponseEntity<?> downloadBook(@PathVariable String bookId) {
|
public void downloadBook(@PathVariable String bookId, HttpServletResponse response) throws IOException {
|
||||||
if (StringUtils.isNumeric(bookId)) {
|
if (StringUtils.isNumeric(bookId)) {
|
||||||
return bookService.downloadBook(Long.parseLong(bookId));
|
bookDownloadService.downloadKoboBook(Long.parseLong(bookId), response);
|
||||||
} else {
|
} else {
|
||||||
return koboServerProxy.proxyCurrentRequest(null, false);
|
koboServerProxy.proxyCurrentRequest(null, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -95,7 +95,7 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public ResponseEntity<ErrorResponse> handleGenericException(Exception ex) {
|
public ResponseEntity<ErrorResponse> handleGenericException(Exception ex) {
|
||||||
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "An unexpected error occurred.");
|
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage());
|
||||||
log.error(ex.getMessage(), ex);
|
log.error(ex.getMessage(), ex);
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -4,8 +4,9 @@ import lombok.Getter;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public enum AppSettingKey {
|
public enum AppSettingKey {
|
||||||
QUICK_BOOK_MATCH("quick_book_match", true, false),
|
|
||||||
OIDC_PROVIDER_DETAILS("oidc_provider_details", true, true),
|
OIDC_PROVIDER_DETAILS("oidc_provider_details", true, true),
|
||||||
|
|
||||||
|
QUICK_BOOK_MATCH("quick_book_match", true, false),
|
||||||
OIDC_AUTO_PROVISION_DETAILS("oidc_auto_provision_details", true, false),
|
OIDC_AUTO_PROVISION_DETAILS("oidc_auto_provision_details", true, false),
|
||||||
SIDEBAR_LIBRARY_SORTING("sidebar_library_sorting", true, false),
|
SIDEBAR_LIBRARY_SORTING("sidebar_library_sorting", true, false),
|
||||||
SIDEBAR_SHELF_SORTING("sidebar_shelf_sorting", true, false),
|
SIDEBAR_SHELF_SORTING("sidebar_shelf_sorting", true, false),
|
||||||
@@ -13,6 +14,7 @@ public enum AppSettingKey {
|
|||||||
METADATA_MATCH_WEIGHTS("metadata_match_weights", true, false),
|
METADATA_MATCH_WEIGHTS("metadata_match_weights", true, false),
|
||||||
METADATA_PERSISTENCE_SETTINGS("metadata_persistence_settings", true, false),
|
METADATA_PERSISTENCE_SETTINGS("metadata_persistence_settings", true, false),
|
||||||
METADATA_PUBLIC_REVIEWS_SETTINGS("metadata_public_reviews_settings", true, false),
|
METADATA_PUBLIC_REVIEWS_SETTINGS("metadata_public_reviews_settings", true, false),
|
||||||
|
KOBO_SETTINGS("kobo_settings", true, false),
|
||||||
|
|
||||||
AUTO_BOOK_SEARCH("auto_book_search", false, false),
|
AUTO_BOOK_SEARCH("auto_book_search", false, false),
|
||||||
COVER_IMAGE_RESOLUTION("cover_image_resolution", false, false),
|
COVER_IMAGE_RESOLUTION("cover_image_resolution", false, false),
|
||||||
|
|||||||
+1
@@ -30,4 +30,5 @@ public class AppSettings {
|
|||||||
private MetadataMatchWeights metadataMatchWeights;
|
private MetadataMatchWeights metadataMatchWeights;
|
||||||
private MetadataPersistenceSettings metadataPersistenceSettings;
|
private MetadataPersistenceSettings metadataPersistenceSettings;
|
||||||
private MetadataPublicReviewsSettings metadataPublicReviewsSettings;
|
private MetadataPublicReviewsSettings metadataPublicReviewsSettings;
|
||||||
|
private KoboSettings koboSettings;
|
||||||
}
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package com.adityachandel.booklore.model.dto.settings;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
public class KoboSettings {
|
||||||
|
private boolean convertToKepub;
|
||||||
|
private int conversionLimitInMb;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.adityachandel.booklore.model.enums;
|
||||||
|
|
||||||
|
public enum KoboBookFormat {
|
||||||
|
EPUB3,
|
||||||
|
KEPUB,
|
||||||
|
}
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.exception.ApiError;
|
||||||
|
import com.adityachandel.booklore.model.dto.settings.KoboSettings;
|
||||||
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
|
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||||
|
import com.adityachandel.booklore.repository.BookRepository;
|
||||||
|
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||||
|
import com.adityachandel.booklore.service.kobo.KepubConversionService;
|
||||||
|
import com.adityachandel.booklore.util.FileUtils;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.FileSystemUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class BookDownloadService {
|
||||||
|
|
||||||
|
private final BookRepository bookRepository;
|
||||||
|
private final KepubConversionService kepubConversionService;
|
||||||
|
private final AppSettingService appSettingService;
|
||||||
|
|
||||||
|
public ResponseEntity<Resource> downloadBook(Long bookId) {
|
||||||
|
try {
|
||||||
|
BookEntity bookEntity = bookRepository.findById(bookId)
|
||||||
|
.orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
|
||||||
|
Path file = Paths.get(FileUtils.getBookFullPath(bookEntity)).toAbsolutePath().normalize();
|
||||||
|
Resource resource = new UrlResource(file.toUri());
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFileName() + "\"")
|
||||||
|
.body(resource);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to download book {}: {}", bookId, e.getMessage(), e);
|
||||||
|
throw ApiError.FAILED_TO_DOWNLOAD_FILE.createException(bookId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void downloadKoboBook(Long bookId, HttpServletResponse response) {
|
||||||
|
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
|
||||||
|
if (bookEntity.getBookType() != BookFileType.EPUB) {
|
||||||
|
throw ApiError.GENERIC_BAD_REQUEST.createException("The requested book is not an EPUB file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
KoboSettings koboSettings = appSettingService.getAppSettings().getKoboSettings();
|
||||||
|
if (koboSettings == null) {
|
||||||
|
throw ApiError.GENERIC_BAD_REQUEST.createException("Kobo settings not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean asKepub = koboSettings.isConvertToKepub() && bookEntity.getFileSizeKb() <= (long) koboSettings.getConversionLimitInMb() * 1024;
|
||||||
|
|
||||||
|
Path tempDir = null;
|
||||||
|
try {
|
||||||
|
File inputFile = new File(FileUtils.getBookFullPath(bookEntity));
|
||||||
|
File fileToSend = inputFile;
|
||||||
|
|
||||||
|
if (asKepub) {
|
||||||
|
tempDir = Files.createTempDirectory("kepub-output");
|
||||||
|
fileToSend = kepubConversionService.convertEpubToKepub(inputFile, tempDir.toFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
setResponseHeaders(response, fileToSend);
|
||||||
|
streamFileToResponse(fileToSend, response);
|
||||||
|
|
||||||
|
log.info("Successfully streamed {} ({} bytes) to client", fileToSend.getName(), fileToSend.length());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to download kobo book {}: {}", bookId, e.getMessage(), e);
|
||||||
|
throw ApiError.FAILED_TO_DOWNLOAD_FILE.createException(bookId);
|
||||||
|
} finally {
|
||||||
|
cleanupTempDirectory(tempDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setResponseHeaders(HttpServletResponse response, File file) {
|
||||||
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||||
|
response.setContentLengthLong(file.length());
|
||||||
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void streamFileToResponse(File file, HttpServletResponse response) throws IOException {
|
||||||
|
try (InputStream in = Files.newInputStream(file.toPath())) {
|
||||||
|
in.transferTo(response.getOutputStream());
|
||||||
|
response.getOutputStream().flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanupTempDirectory(Path tempDir) {
|
||||||
|
if (tempDir != null) {
|
||||||
|
try {
|
||||||
|
FileSystemUtils.deleteRecursively(tempDir);
|
||||||
|
log.debug("Deleted temporary directory {}", tempDir);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to delete temporary directory {}: {}", tempDir, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@ public class BookService {
|
|||||||
private final AuthenticationService authenticationService;
|
private final AuthenticationService authenticationService;
|
||||||
private final BookQueryService bookQueryService;
|
private final BookQueryService bookQueryService;
|
||||||
private final UserProgressService userProgressService;
|
private final UserProgressService userProgressService;
|
||||||
|
private final BookDownloadService bookDownloadService;
|
||||||
|
|
||||||
|
|
||||||
private void setBookProgress(Book book, UserBookProgressEntity progress) {
|
private void setBookProgress(Book book, UserBookProgressEntity progress) {
|
||||||
@@ -453,18 +454,7 @@ public class BookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ResponseEntity<Resource> downloadBook(Long bookId) {
|
public ResponseEntity<Resource> downloadBook(Long bookId) {
|
||||||
try {
|
return bookDownloadService.downloadBook(bookId);
|
||||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
|
||||||
|
|
||||||
Path file = Paths.get(FileUtils.getBookFullPath(bookEntity)).toAbsolutePath().normalize();
|
|
||||||
Resource resource = new UrlResource(file.toUri());
|
|
||||||
return ResponseEntity.ok()
|
|
||||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
||||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFileName() + "\"")
|
|
||||||
.body(resource);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw ApiError.FAILED_TO_DOWNLOAD_FILE.createException(bookId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseEntity<ByteArrayResource> getBookContent(long bookId) throws IOException {
|
public ResponseEntity<ByteArrayResource> getBookContent(long bookId) throws IOException {
|
||||||
|
|||||||
+11
-1
@@ -1,12 +1,15 @@
|
|||||||
package com.adityachandel.booklore.service;
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
import com.adityachandel.booklore.model.dto.kobo.*;
|
import com.adityachandel.booklore.model.dto.kobo.*;
|
||||||
|
import com.adityachandel.booklore.model.dto.settings.KoboSettings;
|
||||||
import com.adityachandel.booklore.model.entity.AuthorEntity;
|
import com.adityachandel.booklore.model.entity.AuthorEntity;
|
||||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
import com.adityachandel.booklore.model.entity.BookMetadataEntity;
|
||||||
import com.adityachandel.booklore.model.entity.CategoryEntity;
|
import com.adityachandel.booklore.model.entity.CategoryEntity;
|
||||||
import com.adityachandel.booklore.model.enums.BookFileType;
|
import com.adityachandel.booklore.model.enums.BookFileType;
|
||||||
|
import com.adityachandel.booklore.model.enums.KoboBookFormat;
|
||||||
import com.adityachandel.booklore.model.enums.KoboReadStatus;
|
import com.adityachandel.booklore.model.enums.KoboReadStatus;
|
||||||
|
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||||
import com.adityachandel.booklore.util.kobo.KoboUrlBuilder;
|
import com.adityachandel.booklore.util.kobo.KoboUrlBuilder;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -25,6 +28,7 @@ public class KoboEntitlementService {
|
|||||||
|
|
||||||
private final KoboUrlBuilder koboUrlBuilder;
|
private final KoboUrlBuilder koboUrlBuilder;
|
||||||
private final BookQueryService bookQueryService;
|
private final BookQueryService bookQueryService;
|
||||||
|
private final AppSettingService appSettingService;
|
||||||
|
|
||||||
public List<NewEntitlement> generateNewEntitlements(Set<Long> bookIds, String token, boolean removed) {
|
public List<NewEntitlement> generateNewEntitlements(Set<Long> bookIds, String token, boolean removed) {
|
||||||
List<BookEntity> books = bookQueryService.findAllWithMetadataByIds(bookIds);
|
List<BookEntity> books = bookQueryService.findAllWithMetadataByIds(bookIds);
|
||||||
@@ -146,6 +150,12 @@ public class KoboEntitlementService {
|
|||||||
|
|
||||||
String downloadUrl = koboUrlBuilder.downloadUrl(token, book.getId());
|
String downloadUrl = koboUrlBuilder.downloadUrl(token, book.getId());
|
||||||
|
|
||||||
|
KoboBookFormat bookFormat = KoboBookFormat.EPUB3;
|
||||||
|
KoboSettings koboSettings = appSettingService.getAppSettings().getKoboSettings();
|
||||||
|
if (koboSettings != null && koboSettings.isConvertToKepub()) {
|
||||||
|
bookFormat = KoboBookFormat.KEPUB;
|
||||||
|
}
|
||||||
|
|
||||||
return KoboBookMetadata.builder()
|
return KoboBookMetadata.builder()
|
||||||
.crossRevisionId(String.valueOf(book.getId()))
|
.crossRevisionId(String.valueOf(book.getId()))
|
||||||
.revisionId(String.valueOf(book.getId()))
|
.revisionId(String.valueOf(book.getId()))
|
||||||
@@ -170,7 +180,7 @@ public class KoboEntitlementService {
|
|||||||
.downloadUrls(List.of(
|
.downloadUrls(List.of(
|
||||||
KoboBookMetadata.DownloadUrl.builder()
|
KoboBookMetadata.DownloadUrl.builder()
|
||||||
.url(downloadUrl)
|
.url(downloadUrl)
|
||||||
.format("EPUB3")
|
.format(bookFormat.toString())
|
||||||
.size(book.getFileSizeKb() * 1024)
|
.size(book.getFileSizeKb() * 1024)
|
||||||
.build()
|
.build()
|
||||||
))
|
))
|
||||||
|
|||||||
+1
@@ -89,6 +89,7 @@ public class AppSettingService {
|
|||||||
builder.metadataMatchWeights(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_MATCH_WEIGHTS, MetadataMatchWeights.class, settingPersistenceHelper.getDefaultMetadataMatchWeights(), true));
|
builder.metadataMatchWeights(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_MATCH_WEIGHTS, MetadataMatchWeights.class, settingPersistenceHelper.getDefaultMetadataMatchWeights(), true));
|
||||||
builder.metadataPersistenceSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PERSISTENCE_SETTINGS, MetadataPersistenceSettings.class, settingPersistenceHelper.getDefaultMetadataPersistenceSettings(), true));
|
builder.metadataPersistenceSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PERSISTENCE_SETTINGS, MetadataPersistenceSettings.class, settingPersistenceHelper.getDefaultMetadataPersistenceSettings(), true));
|
||||||
builder.metadataPublicReviewsSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, MetadataPublicReviewsSettings.class, settingPersistenceHelper.getDefaultMetadataPublicReviewsSettings(), true));
|
builder.metadataPublicReviewsSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.METADATA_PUBLIC_REVIEWS_SETTINGS, MetadataPublicReviewsSettings.class, settingPersistenceHelper.getDefaultMetadataPublicReviewsSettings(), true));
|
||||||
|
builder.koboSettings(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.KOBO_SETTINGS, KoboSettings.class, settingPersistenceHelper.getDefaultKoboSettings(), true));
|
||||||
|
|
||||||
builder.coverResolution(settingPersistenceHelper.getOrCreateSetting(AppSettingKey.COVER_IMAGE_RESOLUTION, "250x350"));
|
builder.coverResolution(settingPersistenceHelper.getOrCreateSetting(AppSettingKey.COVER_IMAGE_RESOLUTION, "250x350"));
|
||||||
builder.autoBookSearch(Boolean.parseBoolean(settingPersistenceHelper.getOrCreateSetting(AppSettingKey.AUTO_BOOK_SEARCH, "true")));
|
builder.autoBookSearch(Boolean.parseBoolean(settingPersistenceHelper.getOrCreateSetting(AppSettingKey.AUTO_BOOK_SEARCH, "true")));
|
||||||
|
|||||||
+7
@@ -200,4 +200,11 @@ public class SettingPersistenceHelper {
|
|||||||
))
|
))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KoboSettings getDefaultKoboSettings() {
|
||||||
|
return KoboSettings.builder()
|
||||||
|
.convertToKepub(false)
|
||||||
|
.conversionLimitInMb(100)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
package com.adityachandel.booklore.service.kobo;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class KepubConversionService {
|
||||||
|
|
||||||
|
private static final String KEPUBIFY_BINARY_MACOS_ARM64 = "/bin/kepubify-darwin-arm64";
|
||||||
|
private static final String KEPUBIFY_BINARY_LINUX_X64 = "/bin/kepubify-linux-64bit";
|
||||||
|
|
||||||
|
public File convertEpubToKepub(File epubFile, File tempDir) throws IOException, InterruptedException {
|
||||||
|
validateInputs(epubFile);
|
||||||
|
|
||||||
|
Path kepubifyBinary = setupKepubifyBinary(tempDir);
|
||||||
|
File outputFile = executeKepubifyConversion(epubFile, tempDir, kepubifyBinary);
|
||||||
|
|
||||||
|
log.info("Successfully converted {} to {} (size: {} bytes)", epubFile.getName(), outputFile.getName(), outputFile.length());
|
||||||
|
return outputFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateInputs(File epubFile) {
|
||||||
|
if (epubFile == null || !epubFile.isFile() || !epubFile.getName().endsWith(".epub")) {
|
||||||
|
throw new IllegalArgumentException("Invalid EPUB file: " + epubFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path setupKepubifyBinary(File tempDir) throws IOException {
|
||||||
|
Path tempKepubify = tempDir.toPath().resolve("kepubify");
|
||||||
|
String resourcePath = getKepubifyResourcePath();
|
||||||
|
|
||||||
|
try (InputStream in = getClass().getResourceAsStream(resourcePath)) {
|
||||||
|
if (in == null) {
|
||||||
|
throw new IOException("Resource not found: " + resourcePath);
|
||||||
|
}
|
||||||
|
Files.copy(in, tempKepubify, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
tempKepubify.toFile().setExecutable(true);
|
||||||
|
return tempKepubify;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getKepubifyResourcePath() {
|
||||||
|
String osName = System.getProperty("os.name").toLowerCase();
|
||||||
|
String osArch = System.getProperty("os.arch").toLowerCase();
|
||||||
|
|
||||||
|
log.debug("Detected OS: {} ({})", osName, osArch);
|
||||||
|
|
||||||
|
if (osName.contains("mac") || osName.contains("darwin")) {
|
||||||
|
return KEPUBIFY_BINARY_MACOS_ARM64;
|
||||||
|
} else if (osName.contains("linux")) {
|
||||||
|
return KEPUBIFY_BINARY_LINUX_X64;
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Unsupported operating system: " + osName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private File executeKepubifyConversion(File epubFile, File tempDir, Path kepubifyBinary) throws IOException, InterruptedException {
|
||||||
|
|
||||||
|
ProcessBuilder pb = new ProcessBuilder(kepubifyBinary.toAbsolutePath().toString(), "-o", tempDir.getAbsolutePath(), epubFile.getAbsolutePath());
|
||||||
|
pb.directory(tempDir);
|
||||||
|
|
||||||
|
log.info("Starting kepubify conversion for {} -> output dir: {}", epubFile.getAbsolutePath(), tempDir.getAbsolutePath());
|
||||||
|
|
||||||
|
Process process = pb.start();
|
||||||
|
|
||||||
|
String output = readProcessOutput(process.getInputStream());
|
||||||
|
String error = readProcessOutput(process.getErrorStream());
|
||||||
|
|
||||||
|
int exitCode = process.waitFor();
|
||||||
|
logProcessResults(exitCode, output, error);
|
||||||
|
|
||||||
|
if (exitCode != 0) {
|
||||||
|
throw new IOException(String.format("Kepubify conversion failed with exit code: %d. Error: %s", exitCode, error));
|
||||||
|
}
|
||||||
|
|
||||||
|
return findOutputFile(tempDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readProcessOutput(InputStream inputStream) {
|
||||||
|
return new BufferedReader(new InputStreamReader(inputStream))
|
||||||
|
.lines()
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logProcessResults(int exitCode, String output, String error) {
|
||||||
|
log.debug("Kepubify process exited with code {}", exitCode);
|
||||||
|
if (!output.isEmpty()) {
|
||||||
|
log.debug("Kepubify stdout: {}", output);
|
||||||
|
}
|
||||||
|
if (!error.isEmpty()) {
|
||||||
|
log.error("Kepubify stderr: {}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private File findOutputFile(File tempDir) throws IOException {
|
||||||
|
File[] kepubFiles = tempDir.listFiles((dir, name) -> name.endsWith(".kepub.epub"));
|
||||||
|
if (kepubFiles == null || kepubFiles.length == 0) {
|
||||||
|
throw new IOException("Kepubify conversion completed but no .kepub.epub file was created in: " + tempDir.getAbsolutePath());
|
||||||
|
}
|
||||||
|
return kepubFiles[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.adityachandel.booklore.util.kobo;
|
|||||||
import com.adityachandel.booklore.util.RequestUtils;
|
import com.adityachandel.booklore.util.RequestUtils;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
@@ -11,6 +12,9 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class KoboUrlBuilder {
|
public class KoboUrlBuilder {
|
||||||
|
|
||||||
|
@Value("${server.port}")
|
||||||
|
private int serverPort;
|
||||||
|
|
||||||
public UriComponentsBuilder baseBuilder() {
|
public UriComponentsBuilder baseBuilder() {
|
||||||
HttpServletRequest request = RequestUtils.getCurrentRequest();
|
HttpServletRequest request = RequestUtils.getCurrentRequest();
|
||||||
|
|
||||||
@@ -18,10 +22,9 @@ public class KoboUrlBuilder {
|
|||||||
.fromCurrentContextPath()
|
.fromCurrentContextPath()
|
||||||
.replacePath("")
|
.replacePath("")
|
||||||
.replaceQuery(null)
|
.replaceQuery(null)
|
||||||
.port(-1); // drop default port
|
.port(-1);
|
||||||
|
|
||||||
String host = builder.build().getHost();
|
String host = builder.build().getHost();
|
||||||
String scheme = builder.build().getScheme();
|
|
||||||
|
|
||||||
if (host == null) host = "";
|
if (host == null) host = "";
|
||||||
|
|
||||||
@@ -34,6 +37,7 @@ public class KoboUrlBuilder {
|
|||||||
}
|
}
|
||||||
log.info("Applied X-Forwarded-Port: {}", port);
|
log.info("Applied X-Forwarded-Port: {}", port);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
builder.port(serverPort);
|
||||||
log.warn("Invalid X-Forwarded-Port header: {}", xfPort);
|
log.warn("Invalid X-Forwarded-Port header: {}", xfPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -3,6 +3,7 @@ package com.adityachandel.booklore;
|
|||||||
import com.adityachandel.booklore.config.security.AuthenticationService;
|
import com.adityachandel.booklore.config.security.AuthenticationService;
|
||||||
import com.adityachandel.booklore.mapper.BookMapper;
|
import com.adityachandel.booklore.mapper.BookMapper;
|
||||||
import com.adityachandel.booklore.repository.*;
|
import com.adityachandel.booklore.repository.*;
|
||||||
|
import com.adityachandel.booklore.service.BookDownloadService;
|
||||||
import com.adityachandel.booklore.service.BookQueryService;
|
import com.adityachandel.booklore.service.BookQueryService;
|
||||||
import com.adityachandel.booklore.service.BookService;
|
import com.adityachandel.booklore.service.BookService;
|
||||||
import com.adityachandel.booklore.service.UserProgressService;
|
import com.adityachandel.booklore.service.UserProgressService;
|
||||||
@@ -46,6 +47,7 @@ class BookServiceDeleteTests {
|
|||||||
AuthenticationService authenticationService = Mockito.mock(AuthenticationService.class);
|
AuthenticationService authenticationService = Mockito.mock(AuthenticationService.class);
|
||||||
BookQueryService bookQueryService = Mockito.mock(BookQueryService.class);
|
BookQueryService bookQueryService = Mockito.mock(BookQueryService.class);
|
||||||
UserProgressService userProgressService = Mockito.mock(UserProgressService.class);
|
UserProgressService userProgressService = Mockito.mock(UserProgressService.class);
|
||||||
|
BookDownloadService bookDownloadService = Mockito.mock(BookDownloadService.class);
|
||||||
|
|
||||||
bookService = new BookService(
|
bookService = new BookService(
|
||||||
bookRepository,
|
bookRepository,
|
||||||
@@ -60,7 +62,8 @@ class BookServiceDeleteTests {
|
|||||||
userBookProgressRepository,
|
userBookProgressRepository,
|
||||||
authenticationService,
|
authenticationService,
|
||||||
bookQueryService,
|
bookQueryService,
|
||||||
userProgressService
|
userProgressService,
|
||||||
|
bookDownloadService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,8 @@
|
|||||||
<i
|
<i
|
||||||
class="pi pi-filter-slash"
|
class="pi pi-filter-slash"
|
||||||
pTooltip="Clear applied filters"
|
pTooltip="Clear applied filters"
|
||||||
tooltipPosition="top">
|
tooltipPosition="top"
|
||||||
|
style="color: orange;">
|
||||||
</i>
|
</i>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,6 @@
|
|||||||
</p-popover>
|
</p-popover>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a
|
<a
|
||||||
class="topbar-items topbar-item"
|
class="topbar-items topbar-item"
|
||||||
@@ -117,6 +117,15 @@
|
|||||||
{{ coverScalePreferenceService.scaleFactor.toFixed(2) }}x
|
{{ coverScalePreferenceService.scaleFactor.toFixed(2) }}x
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!--<div class="flex flex-col gap-2">
|
||||||
|
<label class="font-medium text-sm">Show Sidebar Filters:</label>
|
||||||
|
<div class="flex gap-4 justify-start">
|
||||||
|
<p-toggle-switch
|
||||||
|
[(ngModel)]="sidebarFilterTogglePrefService.selectedShowFilter"
|
||||||
|
(onChange)="sidebarFilterTogglePrefService.selectedShowFilter = $event.checked">
|
||||||
|
</p-toggle-switch>
|
||||||
|
</div>
|
||||||
|
</div>-->
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<label class="font-medium text-sm">Sidebar Filter Sort:</label>
|
<label class="font-medium text-sm">Sidebar Filter Sort:</label>
|
||||||
<div class="flex gap-4 justify-start">
|
<div class="flex gap-4 justify-start">
|
||||||
@@ -173,12 +182,12 @@
|
|||||||
<i class="pi pi-search"></i>
|
<i class="pi pi-search"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<p-popover #searchDropdown [dismissable]="true" appendTo="body" [style]="{ width: '18rem' }">
|
<p-popover #searchDropdown [dismissable]="true" appendTo="body" [style]="{ width: '24rem' }">
|
||||||
<div class="relative w-full">
|
<div class="relative w-full">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
pInputText
|
pInputText
|
||||||
placeholder="Title, Series or Author..."
|
placeholder="Title, Author, Series, Genre, or ISBN..."
|
||||||
[(ngModel)]="bookTitle"
|
[(ngModel)]="bookTitle"
|
||||||
(ngModelChange)="onSearchTermChange($event)"
|
(ngModelChange)="onSearchTermChange($event)"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
@@ -200,7 +209,7 @@
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
pInputText
|
pInputText
|
||||||
placeholder="Title, Series or Author..."
|
placeholder="Title, Author, Series, Genre, or ISBN..."
|
||||||
[(ngModel)]="bookTitle"
|
[(ngModel)]="bookTitle"
|
||||||
(ngModelChange)="onSearchTermChange($event)"
|
(ngModelChange)="onSearchTermChange($event)"
|
||||||
class="search-input"
|
class="search-input"
|
||||||
@@ -217,15 +226,13 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p-button
|
<a class="topbar-items topbar-item" (click)="toggleSidebar()">
|
||||||
class="pr-2"
|
<i
|
||||||
icon="pi pi-chevron-right"
|
[ngClass]="showFilter ? 'pi pi-angle-double-right' : 'pi pi-angle-double-left'"
|
||||||
[outlined]="true"
|
pTooltip="Toggle sidebar filters"
|
||||||
[rounded]="true"
|
tooltipPosition="top">
|
||||||
(click)="toggleFilterSidebar()"
|
</i>
|
||||||
pTooltip="Toggle filter sidebar"
|
</a>
|
||||||
tooltipPosition="top"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -396,19 +403,23 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@if (this.showFilter) {
|
@if (this.showFilter) {
|
||||||
<div
|
<div
|
||||||
class="mobile-filter-mask"
|
class="mobile-filter-mask"
|
||||||
(click)="this.showFilter = false">
|
(click)="this.showFilter = false">
|
||||||
</div>
|
</div>
|
||||||
|
<app-book-filter
|
||||||
|
[showFilter]="showFilter"
|
||||||
|
class="filter-overlay-container z-50 flex-shrink-0"
|
||||||
|
[ngClass]="{ 'active': showFilter, 'ml-4': showFilter }"
|
||||||
|
[entity$]="entity$"
|
||||||
|
[entityType$]="entityType$"
|
||||||
|
[resetFilter$]="resetFilterSubject"
|
||||||
|
(filterSelected)="onFilterSelected($event)"
|
||||||
|
(filterModeChanged)="onFilterModeChanged($event)">
|
||||||
|
</app-book-filter>
|
||||||
}
|
}
|
||||||
|
|
||||||
<app-book-filter
|
|
||||||
[showFilter]="showFilter"
|
|
||||||
class="filter-overlay-container z-50 flex-shrink-0"
|
|
||||||
[ngClass]="{ 'active': showFilter, 'ml-4': showFilter }"
|
|
||||||
[entity$]="entity$"
|
|
||||||
[entityType$]="entityType$"
|
|
||||||
[resetFilter$]="resetFilterSubject">
|
|
||||||
</app-book-filter>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -96,11 +96,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.search-input {
|
.search-input {
|
||||||
width: 100%;
|
min-width: 22rem;
|
||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
height: 2.5rem;
|
height: 2.5rem;
|
||||||
line-height: 2.5rem;
|
line-height: 2.5rem;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-filter-mask {
|
.mobile-filter-mask {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {AfterViewInit, ChangeDetectorRef, Component, inject, OnInit, ViewChild} from '@angular/core';
|
import {Component, inject, OnInit, ViewChild} from '@angular/core';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {ConfirmationService, MenuItem, MessageService, PrimeTemplate} from 'primeng/api';
|
import {ConfirmationService, MenuItem, MessageService, PrimeTemplate} from 'primeng/api';
|
||||||
import {LibraryService} from '../../service/library.service';
|
import {LibraryService} from '../../service/library.service';
|
||||||
@@ -46,6 +46,7 @@ import {BookMenuService} from '../../service/book-menu.service';
|
|||||||
import {MagicShelf, MagicShelfService} from '../../../magic-shelf.service';
|
import {MagicShelf, MagicShelfService} from '../../../magic-shelf.service';
|
||||||
import {BookRuleEvaluatorService} from '../../../book-rule-evaluator.service';
|
import {BookRuleEvaluatorService} from '../../../book-rule-evaluator.service';
|
||||||
import {GroupRule} from '../../../magic-shelf-component/magic-shelf-component';
|
import {GroupRule} from '../../../magic-shelf-component/magic-shelf-component';
|
||||||
|
import {SidebarFilterTogglePrefService} from './filters/sidebar-filter-toggle-pref-service';
|
||||||
|
|
||||||
export enum EntityType {
|
export enum EntityType {
|
||||||
LIBRARY = 'Library',
|
LIBRARY = 'Library',
|
||||||
@@ -87,18 +88,19 @@ const SORT_DIRECTION = {
|
|||||||
providers: [SeriesCollapseFilter],
|
providers: [SeriesCollapseFilter],
|
||||||
animations: [
|
animations: [
|
||||||
trigger('slideInOut', [
|
trigger('slideInOut', [
|
||||||
state('void', style({ transform: 'translateY(100%)' })),
|
state('void', style({transform: 'translateY(100%)'})),
|
||||||
state('*', style({ transform: 'translateY(0)' })),
|
state('*', style({transform: 'translateY(0)'})),
|
||||||
transition(':enter', [ animate('0.1s ease-in') ]),
|
transition(':enter', [animate('0.1s ease-in')]),
|
||||||
transition(':leave', [ animate('0.1s ease-out') ])
|
transition(':leave', [animate('0.1s ease-out')])
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BookBrowserComponent implements OnInit, AfterViewInit {
|
export class BookBrowserComponent implements OnInit {
|
||||||
protected userService = inject(UserService);
|
protected userService = inject(UserService);
|
||||||
protected coverScalePreferenceService = inject(CoverScalePreferenceService);
|
protected coverScalePreferenceService = inject(CoverScalePreferenceService);
|
||||||
protected filterSortPreferenceService = inject(FilterSortPreferenceService);
|
protected filterSortPreferenceService = inject(FilterSortPreferenceService);
|
||||||
protected columnPreferenceService = inject(TableColumnPreferenceService);
|
protected columnPreferenceService = inject(TableColumnPreferenceService);
|
||||||
|
protected sidebarFilterTogglePrefService = inject(SidebarFilterTogglePrefService);
|
||||||
private activatedRoute = inject(ActivatedRoute);
|
private activatedRoute = inject(ActivatedRoute);
|
||||||
private messageService = inject(MessageService);
|
private messageService = inject(MessageService);
|
||||||
private libraryService = inject(LibraryService);
|
private libraryService = inject(LibraryService);
|
||||||
@@ -108,7 +110,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
private bookMenuService = inject(BookMenuService);
|
private bookMenuService = inject(BookMenuService);
|
||||||
private sortService = inject(SortService);
|
private sortService = inject(SortService);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
private changeDetectorRef = inject(ChangeDetectorRef);
|
|
||||||
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
private libraryShelfMenuService = inject(LibraryShelfMenuService);
|
||||||
protected seriesCollapseFilter = inject(SeriesCollapseFilter);
|
protected seriesCollapseFilter = inject(SeriesCollapseFilter);
|
||||||
protected confirmationService = inject(ConfirmationService);
|
protected confirmationService = inject(ConfirmationService);
|
||||||
@@ -148,14 +149,30 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
private headerFilter = new HeaderFilter(this.searchTerm$);
|
private headerFilter = new HeaderFilter(this.searchTerm$);
|
||||||
protected bookSorter = new BookSorter(selectedSort => this.applySortOption(selectedSort));
|
protected bookSorter = new BookSorter(selectedSort => this.applySortOption(selectedSort));
|
||||||
|
|
||||||
@ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent;
|
@ViewChild(BookTableComponent)
|
||||||
@ViewChild(BookFilterComponent) bookFilterComponent!: BookFilterComponent;
|
bookTableComponent!: BookTableComponent;
|
||||||
|
@ViewChild(BookFilterComponent, { static: false })
|
||||||
|
bookFilterComponent!: BookFilterComponent;
|
||||||
|
|
||||||
get currentCardSize() { return this.coverScalePreferenceService.currentCardSize; }
|
get currentCardSize() {
|
||||||
get gridColumnMinWidth(): string { return this.coverScalePreferenceService.gridColumnMinWidth; }
|
return this.coverScalePreferenceService.currentCardSize;
|
||||||
get viewIcon(): string { return this.currentViewMode === VIEW_MODES.GRID ? 'pi pi-objects-column' : 'pi pi-table'; }
|
}
|
||||||
get hasSidebarFilters(): boolean { return !!this.selectedFilter.value && Object.keys(this.selectedFilter.value).length > 0; }
|
|
||||||
get isFilterActive(): boolean { return this.selectedFilter.value !== null; }
|
get gridColumnMinWidth(): string {
|
||||||
|
return this.coverScalePreferenceService.gridColumnMinWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
get viewIcon(): string {
|
||||||
|
return this.currentViewMode === VIEW_MODES.GRID ? 'pi pi-objects-column' : 'pi pi-table';
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasSidebarFilters(): boolean {
|
||||||
|
return !!this.selectedFilter.value && Object.keys(this.selectedFilter.value).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isFilterActive(): boolean {
|
||||||
|
return this.selectedFilter.value !== null;
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.coverScalePreferenceService.scaleChange$.pipe(debounceTime(1000)).subscribe();
|
this.coverScalePreferenceService.scaleChange$.pipe(debounceTime(1000)).subscribe();
|
||||||
@@ -197,23 +214,22 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
() => this.multiBookEditMetadata()
|
() => this.multiBookEditMetadata()
|
||||||
);
|
);
|
||||||
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
|
this.tieredMenuItems = this.bookMenuService.getTieredMenuItems(this.selectedBooks);
|
||||||
}
|
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
// --- NEW: Subscribe to query params + user changes for reactive updates ---
|
||||||
combineLatest({
|
combineLatest([
|
||||||
paramMap: this.activatedRoute.queryParamMap,
|
this.activatedRoute.paramMap,
|
||||||
user: this.userService.userState$.pipe(
|
this.activatedRoute.queryParamMap,
|
||||||
filter(userState => !!userState?.user && userState.loaded),
|
this.userService.userState$.pipe(filter(u => !!u?.user && u.loaded))
|
||||||
take(1)
|
]).subscribe(([paramMap, queryParamMap, user]) => {
|
||||||
)
|
|
||||||
}).subscribe(({paramMap, user}) => {
|
|
||||||
|
|
||||||
const viewParam = paramMap.get(QUERY_PARAMS.VIEW);
|
const viewParam = queryParamMap.get(QUERY_PARAMS.VIEW);
|
||||||
const sortParam = paramMap.get(QUERY_PARAMS.SORT);
|
const sortParam = queryParamMap.get(QUERY_PARAMS.SORT);
|
||||||
const directionParam = paramMap.get(QUERY_PARAMS.DIRECTION);
|
const directionParam = queryParamMap.get(QUERY_PARAMS.DIRECTION);
|
||||||
const filterParams = paramMap.get(QUERY_PARAMS.FILTER);
|
const filterParams = queryParamMap.get(QUERY_PARAMS.FILTER);
|
||||||
const sidebarParam = paramMap.get(QUERY_PARAMS.SIDEBAR);
|
|
||||||
this.showFilter = sidebarParam === null ? true : sidebarParam === 'true';
|
this.sidebarFilterTogglePrefService.showFilter$.subscribe(value => {
|
||||||
|
this.showFilter = value;
|
||||||
|
});
|
||||||
|
|
||||||
const parsedFilters: Record<string, string[]> = {};
|
const parsedFilters: Record<string, string[]> = {};
|
||||||
|
|
||||||
@@ -229,8 +245,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.selectedFilter.next(parsedFilters);
|
this.selectedFilter.next(parsedFilters);
|
||||||
this.bookFilterComponent.setFilters?.(parsedFilters);
|
if(this.bookFilterComponent) {
|
||||||
this.bookFilterComponent.onFiltersChanged?.();
|
this.bookFilterComponent.setFilters?.(parsedFilters);
|
||||||
|
this.bookFilterComponent.onFiltersChanged?.();
|
||||||
|
}
|
||||||
|
|
||||||
const firstFilter = filterParams.split(',')[0];
|
const firstFilter = filterParams.split(',')[0];
|
||||||
const [key, ...values] = firstFilter.split(':');
|
const [key, ...values] = firstFilter.split(':');
|
||||||
@@ -256,7 +274,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.columnPreferenceService.initPreferences(user.user?.userSettings?.tableColumnPreference);
|
this.columnPreferenceService.initPreferences(user.user?.userSettings?.tableColumnPreference);
|
||||||
this.visibleColumns = this.columnPreferenceService.visibleColumns;
|
this.visibleColumns = this.columnPreferenceService.visibleColumns;
|
||||||
|
|
||||||
|
|
||||||
const override = this.entityViewPreferences?.overrides?.find(o =>
|
const override = this.entityViewPreferences?.overrides?.find(o =>
|
||||||
o.entityType?.toUpperCase() === currentEntityTypeStr &&
|
o.entityType?.toUpperCase() === currentEntityTypeStr &&
|
||||||
o.entityId === this.entity?.id
|
o.entityId === this.entity?.id
|
||||||
@@ -289,7 +306,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
direction: SortDirection.DESCENDING
|
direction: SortDirection.DESCENDING
|
||||||
};
|
};
|
||||||
|
|
||||||
const fromParam = paramMap.get(QUERY_PARAMS.FROM);
|
const fromParam = queryParamMap.get(QUERY_PARAMS.FROM);
|
||||||
this.currentViewMode = fromParam === 'toggle'
|
this.currentViewMode = fromParam === 'toggle'
|
||||||
? (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID
|
? (viewParam === VIEW_MODES.TABLE || viewParam === VIEW_MODES.GRID
|
||||||
? viewParam
|
? viewParam
|
||||||
@@ -306,8 +323,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
const queryParams: any = {
|
const queryParams: any = {
|
||||||
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
[QUERY_PARAMS.VIEW]: this.currentViewMode,
|
||||||
[QUERY_PARAMS.SORT]: this.bookSorter.selectedSort.field,
|
[QUERY_PARAMS.SORT]: this.bookSorter.selectedSort.field,
|
||||||
[QUERY_PARAMS.DIRECTION]: this.bookSorter.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING,
|
[QUERY_PARAMS.DIRECTION]: this.bookSorter.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING
|
||||||
[QUERY_PARAMS.SIDEBAR]: this.showFilter.toString()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Object.keys(parsedFilters).length > 0) {
|
if (Object.keys(parsedFilters).length > 0) {
|
||||||
@@ -316,29 +332,13 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
|
|
||||||
const currentParams = this.activatedRoute.snapshot.queryParams;
|
const currentParams = this.activatedRoute.snapshot.queryParams;
|
||||||
const changed = Object.keys(queryParams).some(k => currentParams[k] !== queryParams[k]);
|
const changed = Object.keys(queryParams).some(k => currentParams[k] !== queryParams[k]);
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
const mergedParams = {...currentParams, ...queryParams};
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
queryParams,
|
queryParams: mergedParams,
|
||||||
replaceUrl: true
|
replaceUrl: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.changeDetectorRef.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.bookFilterComponent.filterSelected.subscribe((filters: Record<string, any> | null) => {
|
|
||||||
if (this.settingFiltersFromUrl) return;
|
|
||||||
|
|
||||||
this.selectedFilter.next(filters);
|
|
||||||
this.rawFilterParamFromUrl = null;
|
|
||||||
|
|
||||||
const hasSidebarFilters = !!filters && Object.keys(filters).length > 0;
|
|
||||||
this.currentFilterLabel = hasSidebarFilters ? 'All Books (Filtered)' : 'All Books';
|
|
||||||
});
|
|
||||||
|
|
||||||
this.bookFilterComponent.filterModeChanged.subscribe((mode: 'and' | 'or') => {
|
|
||||||
this.selectedFilterMode.next(mode);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.searchTerm$.subscribe(term => {
|
this.searchTerm$.subscribe(term => {
|
||||||
@@ -346,6 +346,25 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFilterSelected(filters: Record<string, any> | null): void {
|
||||||
|
if (this.settingFiltersFromUrl) return;
|
||||||
|
|
||||||
|
this.selectedFilter.next(filters);
|
||||||
|
this.rawFilterParamFromUrl = null;
|
||||||
|
|
||||||
|
const hasSidebarFilters = !!filters && Object.keys(filters).length > 0;
|
||||||
|
this.currentFilterLabel = hasSidebarFilters ? 'All Books (Filtered)' : 'All Books';
|
||||||
|
}
|
||||||
|
|
||||||
|
onFilterModeChanged(mode: 'and' | 'or'): void {
|
||||||
|
this.selectedFilterMode.next(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleSidebar(): void {
|
||||||
|
this.showFilter = !this.showFilter;
|
||||||
|
this.sidebarFilterTogglePrefService.selectedShowFilter = this.showFilter;
|
||||||
|
}
|
||||||
|
|
||||||
updateScale(): void {
|
updateScale(): void {
|
||||||
this.coverScalePreferenceService.setScale(this.coverScalePreferenceService.scaleFactor);
|
this.coverScalePreferenceService.setScale(this.coverScalePreferenceService.scaleFactor);
|
||||||
}
|
}
|
||||||
@@ -476,18 +495,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.clearSearch();
|
this.clearSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFilterSidebar() {
|
|
||||||
this.showFilter = !this.showFilter;
|
|
||||||
const currentParams = this.activatedRoute.snapshot.queryParams;
|
|
||||||
this.router.navigate([], {
|
|
||||||
queryParams: {
|
|
||||||
...currentParams,
|
|
||||||
[QUERY_PARAMS.SIDEBAR]: this.showFilter.toString()
|
|
||||||
},
|
|
||||||
replaceUrl: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleTableGrid(): void {
|
toggleTableGrid(): void {
|
||||||
this.currentViewMode = this.currentViewMode === VIEW_MODES.GRID ? VIEW_MODES.TABLE : VIEW_MODES.GRID;
|
this.currentViewMode = this.currentViewMode === VIEW_MODES.GRID ? VIEW_MODES.TABLE : VIEW_MODES.GRID;
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
|
|||||||
+2
-2
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<div class="flex-1 overflow-y-auto pb-4 pr-1" style="overscroll-behavior: contain;">
|
<div class="flex-1 overflow-y-auto pb-4 pr-1" style="overscroll-behavior: contain;">
|
||||||
<p-accordion [value]="expandedPanels">
|
<p-accordion [value]="expandedPanels">
|
||||||
@for (filterType of filterTypes; track filterType; let i = $index) {
|
@for (filterType of filterTypes; track trackByFilterType(i, filterType); let i = $index) {
|
||||||
<p-accordion-panel [value]="i">
|
<p-accordion-panel [value]="i">
|
||||||
<p-accordion-header>
|
<p-accordion-header>
|
||||||
<span class="inline-flex items-center gap-1">
|
<span class="inline-flex items-center gap-1">
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
<div
|
<div
|
||||||
class="max-h-[27.5rem] overflow-y-auto overscroll-contain pr-1"
|
class="max-h-[27.5rem] overflow-y-auto overscroll-contain pr-1"
|
||||||
style="overscroll-behavior: contain;">
|
style="overscroll-behavior: contain;">
|
||||||
@for (filter of filters; track filter) {
|
@for (filter of filters; track trackByFilter(j, filter); let j = $index) {
|
||||||
<div
|
<div
|
||||||
class="cursor-pointer transition-colors duration-200 ease-in-out pb-1 flex items-center gap-2"
|
class="cursor-pointer transition-colors duration-200 ease-in-out pb-1 flex items-center gap-2"
|
||||||
[ngClass]="{
|
[ngClass]="{
|
||||||
|
|||||||
+29
-13
@@ -1,6 +1,6 @@
|
|||||||
import {Component, EventEmitter, inject, Input, OnDestroy, OnInit, Output} from '@angular/core';
|
import {ChangeDetectionStrategy, Component, EventEmitter, inject, Input, OnDestroy, OnInit, Output} from '@angular/core';
|
||||||
import {combineLatest, Observable, of, Subject, takeUntil} from 'rxjs';
|
import {combineLatest, distinctUntilChanged, Observable, of, shareReplay, Subject, takeUntil} from 'rxjs';
|
||||||
import {distinctUntilChanged, map} from 'rxjs/operators';
|
import {map} from 'rxjs/operators';
|
||||||
import {BookService} from '../../../service/book.service';
|
import {BookService} from '../../../service/book.service';
|
||||||
import {Library} from '../../../model/library.model';
|
import {Library} from '../../../model/library.model';
|
||||||
import {Shelf} from '../../../model/shelf.model';
|
import {Shelf} from '../../../model/shelf.model';
|
||||||
@@ -133,6 +133,7 @@ function getReadStatusName(status?: ReadStatus | null): string {
|
|||||||
selector: 'app-book-filter',
|
selector: 'app-book-filter',
|
||||||
templateUrl: './book-filter.component.html',
|
templateUrl: './book-filter.component.html',
|
||||||
styleUrls: ['./book-filter.component.scss'],
|
styleUrls: ['./book-filter.component.scss'],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [
|
imports: [
|
||||||
Accordion,
|
Accordion,
|
||||||
@@ -148,6 +149,8 @@ function getReadStatusName(status?: ReadStatus | null): string {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BookFilterComponent implements OnInit, OnDestroy {
|
export class BookFilterComponent implements OnInit, OnDestroy {
|
||||||
|
private filterChangeSubject = new Subject<Record<string, any> | null>();
|
||||||
|
|
||||||
@Output() filterSelected = new EventEmitter<Record<string, any> | null>();
|
@Output() filterSelected = new EventEmitter<Record<string, any> | null>();
|
||||||
@Output() filterModeChanged = new EventEmitter<'and' | 'or'>();
|
@Output() filterModeChanged = new EventEmitter<'and' | 'or'>();
|
||||||
|
|
||||||
@@ -199,8 +202,9 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe(([sortMode]) => {
|
.subscribe(([sortMode]) => {
|
||||||
this.filterStreams = {
|
this.filterStreams = {
|
||||||
author: this.getFilterStream((book: Book) => book.metadata?.authors!.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
|
// Temporarily disabled until we can optimize for large libraries
|
||||||
category: this.getFilterStream((book: Book) => book.metadata?.categories!.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
|
/*author: this.getFilterStream((book: Book) => book.metadata?.authors!.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),
|
||||||
|
category: this.getFilterStream((book: Book) => book.metadata?.categories!.map(name => ({id: name, name})) || [], 'id', 'name', sortMode),*/
|
||||||
series: this.getFilterStream((book) => (book.metadata?.seriesName ? [{id: book.metadata.seriesName, name: book.metadata.seriesName}] : []), 'id', 'name', sortMode),
|
series: this.getFilterStream((book) => (book.metadata?.seriesName ? [{id: book.metadata.seriesName, name: book.metadata.seriesName}] : []), 'id', 'name', sortMode),
|
||||||
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name', sortMode),
|
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name', sortMode),
|
||||||
readStatus: this.getFilterStream((book: Book) => {
|
readStatus: this.getFilterStream((book: Book) => {
|
||||||
@@ -226,6 +230,10 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
this.setExpandedPanels();
|
this.setExpandedPanels();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.filterChangeSubject.pipe(
|
||||||
|
takeUntil(this.destroy$)
|
||||||
|
).subscribe(value => this.filterSelected.emit(value));
|
||||||
|
|
||||||
if (this.resetFilter$) {
|
if (this.resetFilter$) {
|
||||||
this.resetFilter$.pipe(takeUntil(this.destroy$)).subscribe(() => this.clearActiveFilter());
|
this.resetFilter$.pipe(takeUntil(this.destroy$)).subscribe(() => this.clearActiveFilter());
|
||||||
}
|
}
|
||||||
@@ -270,7 +278,8 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
a.value[nameKey].toString().localeCompare(b.value[nameKey].toString())
|
a.value[nameKey].toString().localeCompare(b.value[nameKey].toString())
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
})
|
}),
|
||||||
|
shareReplay({bufferSize: 1, refCount: true})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +290,9 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
set selectedFilterMode(mode: 'and' | 'or') {
|
set selectedFilterMode(mode: 'and' | 'or') {
|
||||||
this._selectedFilterMode = mode;
|
this._selectedFilterMode = mode;
|
||||||
this.filterModeChanged.emit(mode);
|
this.filterModeChanged.emit(mode);
|
||||||
|
this.filterChangeSubject.next(
|
||||||
|
Object.keys(this.activeFilters).length ? {...this.activeFilters} : null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private filterBooksByEntityType(books: Book[], entity: any, entityType: EntityType): Book[] {
|
private filterBooksByEntityType(books: Book[], entity: any, entityType: EntityType): Book[] {
|
||||||
@@ -320,11 +332,7 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
this.activeFilters[filterType].push(value);
|
this.activeFilters[filterType].push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(this.activeFilters).length === 0) {
|
this.filterChangeSubject.next(Object.keys(this.activeFilters).length ? {...this.activeFilters} : null);
|
||||||
this.filterSelected.emit(null);
|
|
||||||
} else {
|
|
||||||
this.filterSelected.emit({...this.activeFilters});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setFilters(filters: Record<string, any>) {
|
setFilters(filters: Record<string, any>) {
|
||||||
@@ -337,12 +345,12 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
this.activeFilters[key] = [value];
|
this.activeFilters[key] = [value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.filterSelected.emit({...this.activeFilters});
|
this.filterChangeSubject.next({...this.activeFilters});
|
||||||
}
|
}
|
||||||
|
|
||||||
clearActiveFilter() {
|
clearActiveFilter() {
|
||||||
this.activeFilters = {};
|
this.activeFilters = {};
|
||||||
this.filterSelected.emit(null);
|
this.filterChangeSubject.next(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
setExpandedPanels(): void {
|
setExpandedPanels(): void {
|
||||||
@@ -356,6 +364,14 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
this.setExpandedPanels();
|
this.setExpandedPanels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trackByFilterType(_: number, type: string): string {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
trackByFilter(_: number, filter: Filter<any>): any {
|
||||||
|
return filter.value.id ?? filter.value;
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {BookFilter} from './BookFilter';
|
import {BookFilter} from './BookFilter';
|
||||||
import {BookState} from '../../../model/state/book-state.model';
|
import {BookState} from '../../../model/state/book-state.model';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable, of} from 'rxjs';
|
||||||
import {map} from 'rxjs/operators';
|
import {map, debounceTime, distinctUntilChanged, switchMap} from 'rxjs/operators';
|
||||||
|
|
||||||
export class HeaderFilter implements BookFilter {
|
export class HeaderFilter implements BookFilter {
|
||||||
|
|
||||||
@@ -13,21 +13,35 @@ export class HeaderFilter implements BookFilter {
|
|||||||
str.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
|
str.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
|
||||||
|
|
||||||
return this.searchTerm$.pipe(
|
return this.searchTerm$.pipe(
|
||||||
map(term => {
|
distinctUntilChanged(),
|
||||||
const normalizedTerm = normalize(term || '');
|
switchMap(term => {
|
||||||
if (normalizedTerm && normalizedTerm.trim() !== '') {
|
const normalizedTerm = normalize(term || '').trim();
|
||||||
const filteredBooks = bookState.books?.filter(book => {
|
if (!normalizedTerm) {
|
||||||
const title = book.metadata?.title || '';
|
return of(bookState);
|
||||||
const series = book.metadata?.seriesName || '';
|
|
||||||
const authors = book.metadata?.authors || [];
|
|
||||||
const matchesTitle = normalize(title).includes(normalizedTerm);
|
|
||||||
const matchesSeries = normalize(series).includes(normalizedTerm);
|
|
||||||
const matchesAuthor = authors.some(author => normalize(author).includes(normalizedTerm));
|
|
||||||
return matchesTitle || matchesSeries || matchesAuthor;
|
|
||||||
}) || null;
|
|
||||||
return {...bookState, books: filteredBooks};
|
|
||||||
}
|
}
|
||||||
return bookState;
|
return of(normalizedTerm).pipe(
|
||||||
|
debounceTime(500),
|
||||||
|
map(nTerm => {
|
||||||
|
const filteredBooks = bookState.books?.filter(book => {
|
||||||
|
const title = book.metadata?.title || '';
|
||||||
|
const series = book.metadata?.seriesName || '';
|
||||||
|
const authors = book.metadata?.authors || [];
|
||||||
|
const categories = book.metadata?.categories || [];
|
||||||
|
const isbn = book.metadata?.isbn10 || '';
|
||||||
|
const isbn13 = book.metadata?.isbn13 || '';
|
||||||
|
|
||||||
|
const matchesTitle = normalize(title).includes(nTerm);
|
||||||
|
const matchesSeries = normalize(series).includes(nTerm);
|
||||||
|
const matchesAuthor = authors.some(author => normalize(author).includes(nTerm));
|
||||||
|
const matchesCategory = categories.some(category => normalize(category).includes(nTerm));
|
||||||
|
const matchesIsbn = normalize(isbn).includes(nTerm) || normalize(isbn13).includes(nTerm);
|
||||||
|
|
||||||
|
return matchesTitle || matchesSeries || matchesAuthor || matchesCategory || matchesIsbn;
|
||||||
|
}) || null;
|
||||||
|
|
||||||
|
return {...bookState, books: filteredBooks};
|
||||||
|
})
|
||||||
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
import {inject, Injectable} from '@angular/core';
|
||||||
|
import {BehaviorSubject} from 'rxjs';
|
||||||
|
import {MessageService} from 'primeng/api';
|
||||||
|
import {LocalStorageService} from '../../../../core/service/local-storage-service';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class SidebarFilterTogglePrefService {
|
||||||
|
|
||||||
|
private readonly STORAGE_KEY = 'showSidebarFilter';
|
||||||
|
private readonly messageService = inject(MessageService);
|
||||||
|
private readonly localStorageService = inject(LocalStorageService);
|
||||||
|
|
||||||
|
private readonly showFilterSubject = new BehaviorSubject<boolean>(true);
|
||||||
|
readonly showFilter$ = this.showFilterSubject.asObservable();
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.loadFromStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
get selectedShowFilter(): boolean {
|
||||||
|
return this.showFilterSubject.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set selectedShowFilter(value: boolean) {
|
||||||
|
if (this.showFilterSubject.value !== value) {
|
||||||
|
this.showFilterSubject.next(value);
|
||||||
|
this.savePreference(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle(): void {
|
||||||
|
this.selectedShowFilter = !this.selectedShowFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private savePreference(value: boolean): void {
|
||||||
|
try {
|
||||||
|
this.localStorageService.set(this.STORAGE_KEY, value);
|
||||||
|
} catch (e) {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: 'Save Failed',
|
||||||
|
detail: 'Could not save sidebar filter preference locally.',
|
||||||
|
life: 3000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadFromStorage(): void {
|
||||||
|
const saved = this.localStorageService.get<boolean>(this.STORAGE_KEY);
|
||||||
|
if (saved !== null) {
|
||||||
|
this.showFilterSubject.next(saved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
pInputText
|
pInputText
|
||||||
[(ngModel)]="searchQuery"
|
[(ngModel)]="searchQuery"
|
||||||
(input)="onSearchInputChange()"
|
(input)="onSearchInputChange()"
|
||||||
placeholder="Search books by title or author..."
|
placeholder="Title, Author, Series, Genre, or ISBN..."
|
||||||
class="w-full pr-10"
|
class="w-full pr-10"
|
||||||
/>
|
/>
|
||||||
@if (searchQuery) {
|
@if (searchQuery) {
|
||||||
@@ -22,29 +22,6 @@
|
|||||||
}
|
}
|
||||||
</p-iconfield>
|
</p-iconfield>
|
||||||
|
|
||||||
<!--<div class="sm:hidden flex items-center">
|
|
||||||
<p-button
|
|
||||||
icon="pi pi-search"
|
|
||||||
(click)="toggleSearchInputDropdown()"
|
|
||||||
[rounded]="true">
|
|
||||||
</p-button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!– Dropdown input for small screens –>
|
|
||||||
@if (isSearchDropdownOpen) {
|
|
||||||
<div class="absolute z-10 shadow-md rounded-md mt-2 w-56 sm:hidden">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
pInputText
|
|
||||||
[(ngModel)]="searchQuery"
|
|
||||||
(input)="onSearchInputChange()"
|
|
||||||
(blur)="closeSearchDropdown()"
|
|
||||||
placeholder="Search books..."
|
|
||||||
class="w-full"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
}-->
|
|
||||||
|
|
||||||
<!-- Search results below small screen search input -->
|
<!-- Search results below small screen search input -->
|
||||||
@if (books.length > 0 || searchQuery) {
|
@if (books.length > 0 || searchQuery) {
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {of, Subject, Subscription} from 'rxjs';
|
import {BehaviorSubject, of, Subject, Subscription} from 'rxjs';
|
||||||
import {catchError, debounceTime, distinctUntilChanged, switchMap} from 'rxjs/operators';
|
import {catchError, switchMap} from 'rxjs/operators';
|
||||||
import {Book} from '../../model/book.model';
|
import {Book} from '../../model/book.model';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {InputTextModule} from 'primeng/inputtext';
|
import {InputTextModule} from 'primeng/inputtext';
|
||||||
@@ -12,6 +12,7 @@ import {UrlHelperService} from '../../../utilities/service/url-helper.service';
|
|||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
import {IconField} from 'primeng/iconfield';
|
import {IconField} from 'primeng/iconfield';
|
||||||
import {InputIcon} from 'primeng/inputicon';
|
import {InputIcon} from 'primeng/inputicon';
|
||||||
|
import {HeaderFilter} from '../book-browser/filters/HeaderFilter';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-book-searcher',
|
selector: 'app-book-searcher',
|
||||||
@@ -31,41 +32,29 @@ import {InputIcon} from 'primeng/inputicon';
|
|||||||
export class BookSearcherComponent implements OnInit, OnDestroy {
|
export class BookSearcherComponent implements OnInit, OnDestroy {
|
||||||
searchQuery: string = '';
|
searchQuery: string = '';
|
||||||
books: Book[] = [];
|
books: Book[] = [];
|
||||||
#searchSubject = new Subject<string>();
|
#searchSubject = new BehaviorSubject<string>('');
|
||||||
#subscription!: Subscription;
|
#subscription!: Subscription;
|
||||||
|
|
||||||
private bookService = inject(BookService);
|
private bookService = inject(BookService);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
protected urlHelper = inject(UrlHelperService);
|
protected urlHelper = inject(UrlHelperService);
|
||||||
|
private headerFilter = new HeaderFilter(this.#searchSubject.asObservable());
|
||||||
isSearchDropdownOpen = false;
|
|
||||||
|
|
||||||
toggleSearchInputDropdown() {
|
|
||||||
this.isSearchDropdownOpen = !this.isSearchDropdownOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
closeSearchDropdown() {
|
|
||||||
this.isSearchDropdownOpen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.initializeSearch();
|
this.initializeSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeSearch(): void {
|
initializeSearch(): void {
|
||||||
this.#subscription = this.#searchSubject.pipe(
|
this.#subscription = this.bookService.bookState$.pipe(
|
||||||
debounceTime(350),
|
switchMap(bookState => this.headerFilter.filter(bookState)),
|
||||||
distinctUntilChanged(),
|
|
||||||
switchMap((query) => {
|
|
||||||
const result = this.bookService.searchBooks(query);
|
|
||||||
return of(result);
|
|
||||||
}),
|
|
||||||
catchError((error) => {
|
catchError((error) => {
|
||||||
console.error('Error while searching books:', error);
|
console.error('Error while searching books:', error);
|
||||||
return of([]);
|
return of({books: [], loaded: true, error: null});
|
||||||
})
|
})
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: (result: Book[]) => this.books = result,
|
next: (filteredState) => {
|
||||||
|
this.books = this.searchQuery.trim() ? (filteredState.books || []) : [];
|
||||||
|
},
|
||||||
error: (error) => console.error('Subscription error:', error)
|
error: (error) => console.error('Subscription error:', error)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +1,80 @@
|
|||||||
<div class="comic-reader-container">
|
<div class="comic-reader-container" tabindex="0">
|
||||||
<div class="navigation">
|
<div class="navigation">
|
||||||
<div class="goto-page-controls" style="display: flex; align-items: center; margin-right: auto;">
|
<div class="goto-page-controls">
|
||||||
<input
|
<div class="input-group">
|
||||||
type="number"
|
<input
|
||||||
[(ngModel)]="goToPageInput"
|
type="number"
|
||||||
[min]="1"
|
[(ngModel)]="goToPageInput"
|
||||||
[max]="pages.length"
|
[min]="1"
|
||||||
placeholder="Page"
|
[max]="pages.length"
|
||||||
/>
|
placeholder="Page"
|
||||||
<button
|
class="page-input"
|
||||||
(click)="goToPageInput !== null && goToPage(goToPageInput)"
|
/>
|
||||||
[disabled]="goToPageInput === null || goToPageInput < 1 || goToPageInput > pages.length">
|
<button
|
||||||
Go
|
class="go-button"
|
||||||
|
(click)="goToPageInput !== null && goToPage(goToPageInput)"
|
||||||
|
[disabled]="goToPageInput === null || goToPageInput < 1 || goToPageInput > pages.length">
|
||||||
|
Go
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="page-controls">
|
||||||
|
<button class="nav-button first-page" (click)="goToPage(1)" [disabled]="currentPage === 0" title="First Page">
|
||||||
|
<span>⟨⟨</span>
|
||||||
|
</button>
|
||||||
|
<button class="nav-button prev-page" (click)="previousPage()" [disabled]="currentPage === 0" title="Previous Page">
|
||||||
|
<span>⟨</span>
|
||||||
|
</button>
|
||||||
|
<div class="page-info">
|
||||||
|
<span class="current-page">{{ currentPage + 1 }}</span>
|
||||||
|
<span class="page-separator">{{ isTwoPageView && imageUrls.length > 1 ? '-' + (currentPage + 2) : '' }}</span>
|
||||||
|
<span class="total-pages"> of {{ pages.length }}</span>
|
||||||
|
</div>
|
||||||
|
<button class="nav-button next-page" (click)="nextPage()" [disabled]="currentPage >= pages.length - 1" title="Next Page">
|
||||||
|
<span>⟩</span>
|
||||||
|
</button>
|
||||||
|
<button class="nav-button last-page" (click)="goToPage(pages.length)" [disabled]="currentPage >= pages.length - 1" title="Last Page">
|
||||||
|
<span>⟩⟩</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page-controls" style="display: flex; align-items: center; justify-content: center; flex-grow: 1;">
|
<div class="spread-controls">
|
||||||
<button class="mr-2" (click)="goToPage(1)" [disabled]="currentPage === 0"><<</button>
|
|
||||||
<button (click)="previousPage()" [disabled]="currentPage === 0"><</button>
|
|
||||||
<span>
|
|
||||||
Page {{ currentPage + 1 }}
|
|
||||||
{{ isTwoPageView && imageUrls.length > 1 ? '-' + (currentPage + 2) : '' }} of {{ pages.length }}
|
|
||||||
</span>
|
|
||||||
<button (click)="nextPage()" [disabled]="currentPage >= pages.length - 1">></button>
|
|
||||||
<button class="ml-2" (click)="goToPage(pages.length)" [disabled]="currentPage >= pages.length - 1">>></button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="spread-controls" style="display: flex; align-items: center; margin-left: auto;">
|
|
||||||
@if (isTwoPageView) {
|
@if (isTwoPageView) {
|
||||||
<button (click)="toggleSpreadDirection()" title="Toggle Spread Direction">
|
<button class="view-button spread-toggle" (click)="toggleSpreadDirection()" title="Toggle Spread Direction">
|
||||||
{{ pageSpread === 'ODD' ? '⬅️' : '➡️' }}
|
<span>{{ pageSpread === 'ODD' ? '⬅️' : '➡️' }}</span>
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
<button (click)="toggleView()" title="Toggle View">
|
<button class="view-button layout-toggle" (click)="toggleView()" title="Toggle View">
|
||||||
{{ isTwoPageView ? '1️⃣' : '2️⃣' }}
|
<span>{{ isTwoPageView ? '📄' : '📖' }}</span>
|
||||||
|
</button>
|
||||||
|
<button class="view-button background-toggle" (click)="toggleBackground()" title="Toggle Background Color">
|
||||||
|
<span>{{ backgroundColorIcon }}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="image-container" [class.two-page-view]="isTwoPageView">
|
<div class="image-container"
|
||||||
|
[class.two-page-view]="isTwoPageView"
|
||||||
|
[class.bg-black]="backgroundColor === 'black'"
|
||||||
|
[class.bg-gray]="backgroundColor === 'gray'"
|
||||||
|
[class.bg-white]="backgroundColor === 'white'">
|
||||||
@if (!isLoading) {
|
@if (!isLoading) {
|
||||||
@if (pages.length > 0) {
|
@if (pages.length > 0) {
|
||||||
@for (url of imageUrls; track url) {
|
<div class="pages-wrapper">
|
||||||
<img [src]="url" alt="Page Image"/>
|
@for (url of imageUrls; track url) {
|
||||||
}
|
<img [src]="url" alt="Page Image" class="page-image"/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
} @else {
|
} @else {
|
||||||
<p>No pages available.</p>
|
<div class="no-pages">
|
||||||
|
<p>No pages available.</p>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
} @else {
|
} @else {
|
||||||
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%;">
|
<div class="loading-container">
|
||||||
<p-progressSpinner></p-progressSpinner>
|
<p-progressSpinner styleClass="custom-spinner"></p-progressSpinner>
|
||||||
<p style="margin-top: 1rem; color: #ccc;">Processing pages... This may take a few seconds on first load. Future loads will be significantly faster.</p>
|
<p class="loading-text">Processing pages... This may take a few seconds on first load. Future loads will be significantly faster.</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,115 +1,267 @@
|
|||||||
.comic-reader-container {
|
.comic-reader-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
|
||||||
height: 100dvh;
|
height: 100dvh;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
overflow-x: hidden;
|
overflow: hidden;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
background: #1a1a1a;
|
||||||
|
color: #ffffff;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
.navigation {
|
.navigation {
|
||||||
position: relative;
|
flex-shrink: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 1rem;
|
background: linear-gradient(135deg, #2d2d2d 0%, #1f1f1f 100%);
|
||||||
|
border-bottom: 1px solid #404040;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
z-index: 1000;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
.goto-page-controls {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
order: 1;
|
||||||
|
min-width: fit-content;
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.125rem;
|
||||||
|
background: rgba(51, 51, 51, 0.9);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 1px;
|
||||||
|
border: 1px solid #555;
|
||||||
|
|
||||||
|
.page-input {
|
||||||
|
width: 55px;
|
||||||
|
padding: 4px 6px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: #404040;
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 12px;
|
||||||
|
text-align: center;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: none;
|
||||||
|
background: #4a4a4a;
|
||||||
|
box-shadow: 0 0 0 1px rgba(74, 144, 226, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.go-button {
|
||||||
|
padding: 4px 8px;
|
||||||
|
background: #4a90e2;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
|
||||||
|
&:hover:not(:disabled) {
|
||||||
|
background: #357abd;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background: #666;
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.page-controls {
|
.page-controls {
|
||||||
position: absolute;
|
flex: 1;
|
||||||
left: 50%;
|
|
||||||
top: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
white-space: nowrap;
|
justify-content: center;
|
||||||
|
gap: 0.25rem;
|
||||||
|
order: 2;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
span {
|
.nav-button {
|
||||||
min-width: 8rem;
|
width: 24px;
|
||||||
display: inline-block;
|
height: 28px;
|
||||||
text-align: center;
|
border: 1px solid #555;
|
||||||
}
|
background: rgba(51, 51, 51, 0.9);
|
||||||
|
color: #ffffff;
|
||||||
button {
|
border-radius: 4px;
|
||||||
padding: 0 0.25rem;
|
|
||||||
text-align: center;
|
|
||||||
white-space: nowrap;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover:not(:disabled) {
|
||||||
|
background: #4a4a4a;
|
||||||
|
border-color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
&:disabled {
|
&:disabled {
|
||||||
cursor: default;
|
background: #2a2a2a;
|
||||||
color: #999;
|
color: #666;
|
||||||
|
cursor: not-allowed;
|
||||||
|
border-color: #333;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-info {
|
||||||
|
margin: 0 0.5rem;
|
||||||
|
padding: 2px 8px;
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 12px;
|
||||||
|
min-width: 80px;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
.current-page {
|
||||||
|
color: #4a90e2;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-separator {
|
||||||
|
color: #4a90e2;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.total-pages {
|
||||||
|
color: #ccc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.spread-controls {
|
.spread-controls {
|
||||||
position: absolute;
|
flex: 0 0 auto;
|
||||||
right: 0;
|
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.25rem;
|
||||||
align-items: center;
|
order: 3;
|
||||||
|
min-width: fit-content;
|
||||||
|
|
||||||
button {
|
.view-button {
|
||||||
padding-left: 0.5rem;
|
width: 28px;
|
||||||
padding-right: 0.5rem;
|
height: 28px;
|
||||||
|
border: 1px solid #555;
|
||||||
|
background: rgba(51, 51, 51, 0.9);
|
||||||
|
color: #ffffff;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: #4a4a4a;
|
||||||
|
border-color: #666;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-container {
|
.image-container {
|
||||||
flex-grow: 1;
|
flex: 1;
|
||||||
width: 100%;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 1rem;
|
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 0 1rem;
|
padding: 0.5rem;
|
||||||
box-sizing: border-box;
|
background: #0f0f0f;
|
||||||
|
min-height: 0;
|
||||||
|
|
||||||
|
&.bg-black {
|
||||||
|
background: #000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.bg-gray {
|
||||||
|
background: #0f0f0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.bg-white {
|
||||||
|
background: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pages-wrapper {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
&.two-page-view {
|
&.two-page-view {
|
||||||
img {
|
.page-image {
|
||||||
max-width: calc(50% - 0.5rem);
|
max-width: calc(50% - 0.5rem);
|
||||||
|
max-height: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&:not(.two-page-view) {
|
&:not(.two-page-view) {
|
||||||
img {
|
.page-image {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
.page-image {
|
||||||
max-height: 100%;
|
|
||||||
height: auto;
|
height: auto;
|
||||||
width: auto;
|
width: auto;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
|
||||||
flex-shrink: 1;
|
border-radius: 4px;
|
||||||
margin: 0;
|
transition: transform 0.2s ease;
|
||||||
display: block;
|
|
||||||
|
&:hover {
|
||||||
|
transform: scale(1.02);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-pages {
|
||||||
|
text-align: center;
|
||||||
|
color: #999;
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1.5rem;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
.loading-text {
|
||||||
|
color: #ccc;
|
||||||
|
font-size: 16px;
|
||||||
|
max-width: 400px;
|
||||||
|
line-height: 1.5;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.goto-page-controls {
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
display: flex;
|
|
||||||
gap: 0.5rem;
|
|
||||||
align-items: center;
|
|
||||||
padding-left: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.goto-page-controls input[type="number"] {
|
|
||||||
width: 40px;
|
|
||||||
border-radius: 0.25rem;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.goto-page-controls button:disabled {
|
|
||||||
cursor: default;
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import {Component, HostListener, inject, OnInit} from '@angular/core';
|
import {Component, HostListener, inject, OnInit} from '@angular/core';
|
||||||
|
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute} from '@angular/router';
|
||||||
import {CbxReaderService} from '../../service/cbx-reader.service';
|
import {CbxReaderService} from '../../service/cbx-reader.service';
|
||||||
import {BookService} from '../../service/book.service';
|
import {BookService} from '../../service/book.service';
|
||||||
@@ -31,6 +30,8 @@ export class CbxReaderComponent implements OnInit {
|
|||||||
pageSpread: CbxPageSpread | PdfPageSpread = CbxPageSpread.ODD;
|
pageSpread: CbxPageSpread | PdfPageSpread = CbxPageSpread.ODD;
|
||||||
pageViewMode: CbxPageViewMode | PdfPageViewMode = CbxPageViewMode.SINGLE_PAGE;
|
pageViewMode: CbxPageViewMode | PdfPageViewMode = CbxPageViewMode.SINGLE_PAGE;
|
||||||
|
|
||||||
|
backgroundColor: 'black' | 'gray' | 'white' = 'gray';
|
||||||
|
|
||||||
private touchStartX = 0;
|
private touchStartX = 0;
|
||||||
private touchEndX = 0;
|
private touchEndX = 0;
|
||||||
|
|
||||||
@@ -111,6 +112,29 @@ export class CbxReaderComponent implements OnInit {
|
|||||||
return this.pageViewMode === CbxPageViewMode.TWO_PAGE || this.pageViewMode === PdfPageViewMode.TWO_PAGE;
|
return this.pageViewMode === CbxPageViewMode.TWO_PAGE || this.pageViewMode === PdfPageViewMode.TWO_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get backgroundColorIcon(): string {
|
||||||
|
switch (this.backgroundColor) {
|
||||||
|
case 'black': return '⚫';
|
||||||
|
case 'gray': return '🔘';
|
||||||
|
case 'white': return '⚪';
|
||||||
|
default: return '🔘';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleBackground(): void {
|
||||||
|
switch (this.backgroundColor) {
|
||||||
|
case 'black':
|
||||||
|
this.backgroundColor = 'gray';
|
||||||
|
break;
|
||||||
|
case 'gray':
|
||||||
|
this.backgroundColor = 'white';
|
||||||
|
break;
|
||||||
|
case 'white':
|
||||||
|
this.backgroundColor = 'black';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toggleView() {
|
toggleView() {
|
||||||
if (!this.isTwoPageView && this.isPhonePortrait()) return;
|
if (!this.isTwoPageView && this.isPhonePortrait()) return;
|
||||||
this.pageViewMode = this.isTwoPageView ? (this.bookType === "CBX" ? CbxPageViewMode.SINGLE_PAGE : PdfPageViewMode.SINGLE_PAGE) : (this.bookType === "CBX" ? CbxPageViewMode.TWO_PAGE : PdfPageViewMode.TWO_PAGE);
|
this.pageViewMode = this.isTwoPageView ? (this.bookType === "CBX" ? CbxPageViewMode.SINGLE_PAGE : PdfPageViewMode.SINGLE_PAGE) : (this.bookType === "CBX" ? CbxPageViewMode.TWO_PAGE : PdfPageViewMode.TWO_PAGE);
|
||||||
@@ -222,7 +246,10 @@ export class CbxReaderComponent implements OnInit {
|
|||||||
get imageUrls(): string[] {
|
get imageUrls(): string[] {
|
||||||
if (!this.pages.length) return [];
|
if (!this.pages.length) return [];
|
||||||
|
|
||||||
const urls = [this.getPageImageUrl(this.currentPage)];
|
const urls: string[] = [];
|
||||||
|
|
||||||
|
urls.push(this.getPageImageUrl(this.currentPage));
|
||||||
|
|
||||||
if (this.isTwoPageView && this.currentPage + 1 < this.pages.length) {
|
if (this.isTwoPageView && this.currentPage + 1 < this.pages.length) {
|
||||||
urls.push(this.getPageImageUrl(this.currentPage + 1));
|
urls.push(this.getPageImageUrl(this.currentPage + 1));
|
||||||
}
|
}
|
||||||
@@ -233,17 +260,17 @@ export class CbxReaderComponent implements OnInit {
|
|||||||
private updateViewerSetting(): void {
|
private updateViewerSetting(): void {
|
||||||
const bookSetting: BookSetting = this.bookType === "CBX"
|
const bookSetting: BookSetting = this.bookType === "CBX"
|
||||||
? {
|
? {
|
||||||
cbxSettings: {
|
cbxSettings: {
|
||||||
pageSpread: this.pageSpread as CbxPageSpread,
|
pageSpread: this.pageSpread as CbxPageSpread,
|
||||||
pageViewMode: this.pageViewMode as CbxPageViewMode,
|
pageViewMode: this.pageViewMode as CbxPageViewMode,
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
: {
|
: {
|
||||||
newPdfSettings: {
|
newPdfSettings: {
|
||||||
pageSpread: this.pageSpread as PdfPageSpread,
|
pageSpread: this.pageSpread as PdfPageSpread,
|
||||||
pageViewMode: this.pageViewMode as PdfPageViewMode,
|
pageViewMode: this.pageViewMode as PdfPageViewMode,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
|
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,13 +279,14 @@ export class CbxReaderComponent implements OnInit {
|
|||||||
? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10
|
? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
if(this.bookType === 'CBX') {
|
if (this.bookType === 'CBX') {
|
||||||
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage).subscribe();
|
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage).subscribe();
|
||||||
}
|
}
|
||||||
if(this.bookType === 'PDF') {
|
if (this.bookType === 'PDF') {
|
||||||
this.bookService.savePdfProgress(this.bookId, this.currentPage + 1, percentage).subscribe();
|
this.bookService.savePdfProgress(this.bookId, this.currentPage + 1, percentage).subscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goToPage(page: number): void {
|
goToPage(page: number): void {
|
||||||
if (page < 1 || page > this.pages.length) return;
|
if (page < 1 || page > this.pages.length) return;
|
||||||
|
|
||||||
|
|||||||
@@ -191,21 +191,6 @@ export class BookService {
|
|||||||
this.updateLastReadTime(book.id);
|
this.updateLastReadTime(book.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
searchBooks(query: string): Book[] {
|
|
||||||
if (query.length < 2) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const normalize = (str: string): string => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
|
|
||||||
const normalizedQuery = normalize(query);
|
|
||||||
const state = this.bookStateSubject.value;
|
|
||||||
return (state.books || []).filter(book => {
|
|
||||||
const title = book.metadata?.title;
|
|
||||||
const authors = book.metadata?.authors || [];
|
|
||||||
return (title && normalize(title).includes(normalizedQuery)) ||
|
|
||||||
authors.some(author => normalize(author).includes(normalizedQuery));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getFileContent(bookId: number): Observable<Blob> {
|
getFileContent(bookId: number): Observable<Blob> {
|
||||||
return this.http.get<Blob>(`${this.url}/${bookId}/content`, {responseType: 'blob' as 'json'});
|
return this.http.get<Blob>(`${this.url}/${bookId}/content`, {responseType: 'blob' as 'json'});
|
||||||
}
|
}
|
||||||
@@ -331,7 +316,7 @@ export class BookService {
|
|||||||
if (currentState.books) {
|
if (currentState.books) {
|
||||||
const updatedBooks = currentState.books.map(book => {
|
const updatedBooks = currentState.books.map(book => {
|
||||||
if (book.id === bookId) {
|
if (book.id === bookId) {
|
||||||
return { ...book, dateFinished: dateFinished || undefined };
|
return {...book, dateFinished: dateFinished || undefined};
|
||||||
}
|
}
|
||||||
return book;
|
return book;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -90,6 +90,11 @@ export interface PublicReviewSettings {
|
|||||||
providers: ReviewProviderConfig[];
|
providers: ReviewProviderConfig[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface KoboSettings {
|
||||||
|
convertToKepub: boolean;
|
||||||
|
conversionLimitInMb: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface AppSettings {
|
export interface AppSettings {
|
||||||
autoBookSearch: boolean;
|
autoBookSearch: boolean;
|
||||||
similarBookRecommendation: boolean;
|
similarBookRecommendation: boolean;
|
||||||
@@ -107,6 +112,7 @@ export interface AppSettings {
|
|||||||
metadataMatchWeights: MetadataMatchWeights;
|
metadataMatchWeights: MetadataMatchWeights;
|
||||||
metadataPersistenceSettings: MetadataPersistenceSettings;
|
metadataPersistenceSettings: MetadataPersistenceSettings;
|
||||||
metadataPublicReviewsSettings: PublicReviewSettings;
|
metadataPublicReviewsSettings: PublicReviewSettings;
|
||||||
|
koboSettings: KoboSettings;
|
||||||
metadataDownloadOnBookdrop: boolean;
|
metadataDownloadOnBookdrop: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,5 +132,6 @@ export enum AppSettingKey {
|
|||||||
METADATA_MATCH_WEIGHTS = 'METADATA_MATCH_WEIGHTS',
|
METADATA_MATCH_WEIGHTS = 'METADATA_MATCH_WEIGHTS',
|
||||||
METADATA_PERSISTENCE_SETTINGS = 'METADATA_PERSISTENCE_SETTINGS',
|
METADATA_PERSISTENCE_SETTINGS = 'METADATA_PERSISTENCE_SETTINGS',
|
||||||
METADATA_DOWNLOAD_ON_BOOKDROP = 'METADATA_DOWNLOAD_ON_BOOKDROP',
|
METADATA_DOWNLOAD_ON_BOOKDROP = 'METADATA_DOWNLOAD_ON_BOOKDROP',
|
||||||
METADATA_PUBLIC_REVIEWS_SETTINGS = 'METADATA_PUBLIC_REVIEWS_SETTINGS'
|
METADATA_PUBLIC_REVIEWS_SETTINGS = 'METADATA_PUBLIC_REVIEWS_SETTINGS',
|
||||||
|
KOBO_SETTINGS = 'KOBO_SETTINGS'
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -129,9 +129,9 @@
|
|||||||
&::after {
|
&::after {
|
||||||
content: '';
|
content: '';
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: -12px;
|
bottom: -8px;
|
||||||
left: 15%;
|
left: 10%;
|
||||||
right: 15%;
|
right: 10%;
|
||||||
height: 5px;
|
height: 5px;
|
||||||
background: linear-gradient(
|
background: linear-gradient(
|
||||||
90deg,
|
90deg,
|
||||||
@@ -149,8 +149,8 @@
|
|||||||
@media (max-width: 767px) {
|
@media (max-width: 767px) {
|
||||||
|
|
||||||
.dashboard-scroller-card {
|
.dashboard-scroller-card {
|
||||||
height: 184px; /* 80% of 230px */
|
height: 184px;
|
||||||
width: 108px; /* 80% of 135px */
|
width: 108px;
|
||||||
flex-basis: 108px;
|
flex-basis: 108px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+32
-2
@@ -47,9 +47,40 @@
|
|||||||
|
|
||||||
.dashboard-scroller-card {
|
.dashboard-scroller-card {
|
||||||
width: 115px;
|
width: 115px;
|
||||||
|
flex-basis: 115px;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
flex-grow: 0;
|
flex-grow: 0;
|
||||||
flex-basis: 115px;
|
scroll-snap-align: start;
|
||||||
|
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
position: relative;
|
||||||
|
border-radius: 8px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-4px);
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 7%;
|
||||||
|
right: 7%;
|
||||||
|
height: 4px;
|
||||||
|
background: linear-gradient(
|
||||||
|
90deg,
|
||||||
|
transparent,
|
||||||
|
var(--p-primary-500),
|
||||||
|
transparent
|
||||||
|
);
|
||||||
|
border-radius: 50%;
|
||||||
|
opacity: 0;
|
||||||
|
transition: all 0.4s ease;
|
||||||
|
filter: blur(4px);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.description-container {
|
.description-container {
|
||||||
@@ -138,4 +169,3 @@
|
|||||||
::ng-deep .custom-tag-padding {
|
::ng-deep .custom-tag-padding {
|
||||||
padding: 0.1rem !important;
|
padding: 0.1rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+46
-2
@@ -1,7 +1,7 @@
|
|||||||
<p-confirmDialog></p-confirmDialog>
|
<p-confirmDialog></p-confirmDialog>
|
||||||
|
|
||||||
<p class="text-lg flex items-center gap-2 px-4 pt-4 pb-2">
|
<p class="text-lg flex items-center gap-2 px-4 pt-4 pb-2">
|
||||||
Kobo Sync Settings:
|
Kobo Integration Token:
|
||||||
<i class="pi pi-info-circle text-sky-600"
|
<i class="pi pi-info-circle text-sky-600"
|
||||||
pTooltip="Click to view Kobo setup documentation"
|
pTooltip="Click to view Kobo setup documentation"
|
||||||
tooltipPosition="right"
|
tooltipPosition="right"
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
</i>
|
</i>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@if (hasPermission) {
|
@if (hasKoboTokenPermission) {
|
||||||
<form #koboForm="ngForm" class="px-4 py-2">
|
<form #koboForm="ngForm" class="px-4 py-2">
|
||||||
<div class="flex flex-col px-4 py-4 space-y-4">
|
<div class="flex flex-col px-4 py-4 space-y-4">
|
||||||
<div class="flex flex-col gap-1 max-w-[33rem]">
|
<div class="flex flex-col gap-1 max-w-[33rem]">
|
||||||
@@ -50,6 +50,50 @@
|
|||||||
</p-button>
|
</p-button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@if (isAdmin) {
|
||||||
|
<div class="px-4 py-4">
|
||||||
|
<p class="text-lg mb-4">Kobo Settings (Admin Only):</p>
|
||||||
|
<div class="flex flex-col px-4 py-4 space-y-6 max-w-[75rem]">
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<p-toggle-switch
|
||||||
|
id="convertToKepub"
|
||||||
|
[(ngModel)]="koboSettings.convertToKepub"
|
||||||
|
(ngModelChange)="onToggleChange()">
|
||||||
|
</p-toggle-switch>
|
||||||
|
<label for="convertToKepub" class="font-medium">Convert to KEPUB</label>
|
||||||
|
</div>
|
||||||
|
<p class="text-zinc-400 text-sm">
|
||||||
|
<strong>Pros:</strong> KEPUB format enables enhanced Kobo features like better typography, reading stats, and faster page turns.
|
||||||
|
<br>
|
||||||
|
<strong>Cons:</strong> Conversion takes extra processing time and may occasionally fail for complex layouts.
|
||||||
|
Books over the size limit below will skip conversion automatically.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex items-center gap-6">
|
||||||
|
<label for="conversionLimit" class="font-medium">Conversion Size Limit: {{ koboSettings.conversionLimitInMb }} MB</label>
|
||||||
|
</div>
|
||||||
|
<p-slider
|
||||||
|
class="max-w-64"
|
||||||
|
id="conversionLimit"
|
||||||
|
[(ngModel)]="koboSettings.conversionLimitInMb"
|
||||||
|
[min]="1"
|
||||||
|
[max]="250"
|
||||||
|
[step]="1"
|
||||||
|
(ngModelChange)="onSliderChange()">
|
||||||
|
</p-slider>
|
||||||
|
<p class="text-zinc-400 text-sm">
|
||||||
|
Large files (100MB+) can cause conversion timeouts and server strain. Lower limits ensure faster syncing but may skip conversion of larger books.
|
||||||
|
<br>
|
||||||
|
<strong>Recommended:</strong> 50-100MB for most libraries. Very large books will sync as regular EPUB regardless of this setting.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
} @else {
|
} @else {
|
||||||
<div class="px-4 py-4 m-4 rounded-lg bg-red-700/30 border border-red-600 text-red-200 flex items-center gap-2 max-w-lg">
|
<div class="px-4 py-4 m-4 rounded-lg bg-red-700/30 border border-red-600 text-red-200 flex items-center gap-2 max-w-lg">
|
||||||
<i class="pi pi-lock text-red-400 text-xl"></i>
|
<i class="pi pi-lock text-red-400 text-xl"></i>
|
||||||
|
|||||||
+90
-14
@@ -8,15 +8,20 @@ import {InputText} from 'primeng/inputtext';
|
|||||||
import {ConfirmDialog} from 'primeng/confirmdialog';
|
import {ConfirmDialog} from 'primeng/confirmdialog';
|
||||||
import {UserService} from '../../user-management/user.service';
|
import {UserService} from '../../user-management/user.service';
|
||||||
import {Subject} from 'rxjs';
|
import {Subject} from 'rxjs';
|
||||||
import {filter, takeUntil} from 'rxjs/operators';
|
import {debounceTime, filter, take, takeUntil} from 'rxjs/operators';
|
||||||
import {Tooltip} from 'primeng/tooltip';
|
import {Tooltip} from 'primeng/tooltip';
|
||||||
|
import {ToggleSwitch} from 'primeng/toggleswitch';
|
||||||
|
import {Slider} from 'primeng/slider';
|
||||||
|
import {AppSettingsService} from '../../../core/service/app-settings.service';
|
||||||
|
import {SettingsHelperService} from '../../../core/service/settings-helper.service';
|
||||||
|
import {AppSettingKey, KoboSettings} from '../../../core/model/app-settings.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-kobo-sync-setting-component',
|
selector: 'app-kobo-sync-setting-component',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
templateUrl: './kobo-sync-settings-component.html',
|
templateUrl: './kobo-sync-settings-component.html',
|
||||||
styleUrl: './kobo-sync-settings-component.scss',
|
styleUrl: './kobo-sync-settings-component.scss',
|
||||||
imports: [FormsModule, Button, InputText, ConfirmDialog, Tooltip],
|
imports: [FormsModule, Button, InputText, ConfirmDialog, Tooltip, ToggleSwitch, Slider],
|
||||||
providers: [MessageService, ConfirmationService]
|
providers: [MessageService, ConfirmationService]
|
||||||
})
|
})
|
||||||
export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
||||||
@@ -25,34 +30,77 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
|||||||
private confirmationService = inject(ConfirmationService);
|
private confirmationService = inject(ConfirmationService);
|
||||||
private clipboard = inject(Clipboard);
|
private clipboard = inject(Clipboard);
|
||||||
protected userService = inject(UserService);
|
protected userService = inject(UserService);
|
||||||
|
protected appSettingsService = inject(AppSettingsService);
|
||||||
|
protected settingsHelperService = inject(SettingsHelperService);
|
||||||
|
|
||||||
private readonly destroy$ = new Subject<void>();
|
private readonly destroy$ = new Subject<void>();
|
||||||
hasPermission = false;
|
private readonly sliderChange$ = new Subject<void>();
|
||||||
|
|
||||||
|
hasKoboTokenPermission = false;
|
||||||
|
isAdmin = false;
|
||||||
koboToken = '';
|
koboToken = '';
|
||||||
credentialsSaved = false;
|
credentialsSaved = false;
|
||||||
showToken = false;
|
showToken = false;
|
||||||
|
|
||||||
|
koboSettings: KoboSettings = {
|
||||||
|
convertToKepub: false,
|
||||||
|
conversionLimitInMb: 100
|
||||||
|
};
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.setupSliderDebouncing();
|
||||||
|
this.setupUserStateSubscription();
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupSliderDebouncing() {
|
||||||
|
this.sliderChange$.pipe(
|
||||||
|
debounceTime(500),
|
||||||
|
takeUntil(this.destroy$)
|
||||||
|
).subscribe(() => {
|
||||||
|
this.saveSettings();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupUserStateSubscription() {
|
||||||
this.userService.userState$.pipe(
|
this.userService.userState$.pipe(
|
||||||
filter(userState => !!userState?.user && userState.loaded),
|
filter(userState => !!userState?.user && userState.loaded),
|
||||||
takeUntil(this.destroy$)
|
takeUntil(this.destroy$)
|
||||||
).subscribe(userState => {
|
).subscribe(userState => {
|
||||||
this.hasPermission = (userState.user?.permissions.canSyncKobo || userState.user?.permissions.admin) ?? false;
|
this.hasKoboTokenPermission = (userState.user?.permissions.canSyncKobo) ?? false;
|
||||||
if (this.hasPermission) {
|
this.isAdmin = userState.user?.permissions.admin ?? false;
|
||||||
this.koboService.getUser().subscribe({
|
if (this.hasKoboTokenPermission) {
|
||||||
next: (settings: KoboSyncSettings) => {
|
this.loadKoboToken();
|
||||||
this.koboToken = settings.token;
|
}
|
||||||
this.credentialsSaved = !!settings.token;
|
if (this.isAdmin) {
|
||||||
},
|
this.loadKoboSettings();
|
||||||
error: () => {
|
|
||||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load Kobo settings'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private loadKoboToken() {
|
||||||
|
this.koboService.getUser().subscribe({
|
||||||
|
next: (settings: KoboSyncSettings) => {
|
||||||
|
this.koboToken = settings.token;
|
||||||
|
this.credentialsSaved = !!settings.token;
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load Kobo settings'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadKoboSettings() {
|
||||||
|
this.appSettingsService.appSettings$
|
||||||
|
.pipe(
|
||||||
|
filter(settings => settings != null),
|
||||||
|
take(1),
|
||||||
|
)
|
||||||
|
.subscribe(settings => {
|
||||||
|
this.koboSettings.convertToKepub = settings?.koboSettings?.convertToKepub ?? true;
|
||||||
|
this.koboSettings.conversionLimitInMb = settings?.koboSettings?.conversionLimitInMb ?? 100;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
copyText(text: string) {
|
copyText(text: string) {
|
||||||
this.clipboard.copy(text);
|
this.clipboard.copy(text);
|
||||||
this.messageService.add({severity: 'success', summary: 'Copied', detail: 'Token copied to clipboard'});
|
this.messageService.add({severity: 'success', summary: 'Copied', detail: 'Token copied to clipboard'});
|
||||||
@@ -84,6 +132,34 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onToggleChange() {
|
||||||
|
this.saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
onSliderChange() {
|
||||||
|
this.sliderChange$.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSettings() {
|
||||||
|
this.settingsHelperService.saveSetting(AppSettingKey.KOBO_SETTINGS, this.koboSettings)
|
||||||
|
.subscribe({
|
||||||
|
next: () => {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Settings Saved',
|
||||||
|
detail: 'Kobo settings updated successfully'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'error',
|
||||||
|
summary: 'Save Failed',
|
||||||
|
detail: 'Failed to save Kobo settings'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
openKoboDocumentation(): void {
|
openKoboDocumentation(): void {
|
||||||
window.open('https://booklore-app.github.io/booklore-docs/docs/devices/kobo', '_blank');
|
window.open('https://booklore-app.github.io/booklore-docs/docs/devices/kobo', '_blank');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user