Reduce memory footprint during comic cover parsing
This commit is contained in:
committed by
Aditya Chandel
parent
a7b665e0ba
commit
e559efc2f7
+66
@@ -1,10 +1,17 @@
|
|||||||
package com.adityachandel.booklore.service;
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||||
|
import com.adityachandel.booklore.model.dto.settings.UserSettingKey;
|
||||||
import com.adityachandel.booklore.model.entity.AppMigrationEntity;
|
import com.adityachandel.booklore.model.entity.AppMigrationEntity;
|
||||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
|
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||||
|
import com.adityachandel.booklore.model.entity.UserSettingEntity;
|
||||||
import com.adityachandel.booklore.repository.AppMigrationRepository;
|
import com.adityachandel.booklore.repository.AppMigrationRepository;
|
||||||
import com.adityachandel.booklore.repository.BookRepository;
|
import com.adityachandel.booklore.repository.BookRepository;
|
||||||
|
import com.adityachandel.booklore.repository.UserRepository;
|
||||||
|
import com.adityachandel.booklore.service.user.UserProvisioningService;
|
||||||
import com.adityachandel.booklore.util.FileUtils;
|
import com.adityachandel.booklore.util.FileUtils;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -12,6 +19,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -20,6 +28,7 @@ public class AppMigrationService {
|
|||||||
|
|
||||||
private AppMigrationRepository migrationRepository;
|
private AppMigrationRepository migrationRepository;
|
||||||
private BookRepository bookRepository;
|
private BookRepository bookRepository;
|
||||||
|
private UserProvisioningService userProvisioningService;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void populateMissingFileSizesOnce() {
|
public void populateMissingFileSizesOnce() {
|
||||||
@@ -44,4 +53,61 @@ public class AppMigrationService {
|
|||||||
migrationRepository.save(migration);
|
migrationRepository.save(migration);
|
||||||
log.info("Migration 'populateFileSizes' executed successfully.");
|
log.info("Migration 'populateFileSizes' executed successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void addCbxReaderSettingToExistingUsers(UserRepository userRepository, ObjectMapper objectMapper) {
|
||||||
|
final String migrationKey = "addCbxReaderSetting";
|
||||||
|
|
||||||
|
if (migrationRepository.existsById(migrationKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<BookLoreUserEntity> users = userRepository.findAll();
|
||||||
|
int updatedCount = 0;
|
||||||
|
AtomicInteger perBookUpdatedCount = new AtomicInteger();
|
||||||
|
|
||||||
|
for (BookLoreUserEntity user : users) {
|
||||||
|
boolean hasCbxSetting = user.getSettings().stream().anyMatch(s -> s.getSettingKey().equals(UserSettingKey.CBX_READER_SETTING.getDbKey()));
|
||||||
|
|
||||||
|
if (!hasCbxSetting) {
|
||||||
|
try {
|
||||||
|
UserSettingEntity setting = UserSettingEntity.builder()
|
||||||
|
.user(user)
|
||||||
|
.settingKey(UserSettingKey.CBX_READER_SETTING.getDbKey())
|
||||||
|
.settingValue(objectMapper.writeValueAsString(userProvisioningService.buildDefaultCbxReaderSetting()))
|
||||||
|
.build();
|
||||||
|
user.getSettings().add(setting);
|
||||||
|
updatedCount++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to create CBX setting for user {}", user.getUsername(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
user.getSettings().stream()
|
||||||
|
.filter(s -> s.getSettingKey().equals(UserSettingKey.PER_BOOK_SETTING.getDbKey()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(setting -> {
|
||||||
|
try {
|
||||||
|
var current = objectMapper.readValue(setting.getSettingValue(), BookLoreUser.UserSettings.PerBookSetting.class);
|
||||||
|
if (current.getCbx() == null) {
|
||||||
|
current.setCbx(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual);
|
||||||
|
setting.setSettingValue(objectMapper.writeValueAsString(current));
|
||||||
|
perBookUpdatedCount.getAndIncrement();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to update PER_BOOK_SETTING for user {}", user.getUsername(), e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
userRepository.saveAll(users);
|
||||||
|
|
||||||
|
AppMigrationEntity migration = new AppMigrationEntity();
|
||||||
|
migration.setKey(migrationKey);
|
||||||
|
migration.setExecutedAt(LocalDateTime.now());
|
||||||
|
migration.setDescription("Add CBX reader setting and update PER_BOOK_SETTING to include CBX for existing users");
|
||||||
|
migrationRepository.save(migration);
|
||||||
|
|
||||||
|
log.info("Migration '{}' completed. Added CBX setting to {} users and updated PER_BOOK_SETTING for {} users.", migrationKey, updatedCount, perBookUpdatedCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.adityachandel.booklore.service;
|
package com.adityachandel.booklore.service;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.repository.UserRepository;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
@@ -10,9 +12,12 @@ import org.springframework.stereotype.Component;
|
|||||||
public class AppMigrationStartup {
|
public class AppMigrationStartup {
|
||||||
|
|
||||||
private final AppMigrationService appMigrationService;
|
private final AppMigrationService appMigrationService;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void runMigrationsOnce() {
|
public void runMigrationsOnce() {
|
||||||
appMigrationService.populateMissingFileSizesOnce();
|
appMigrationService.populateMissingFileSizesOnce();
|
||||||
|
appMigrationService.addCbxReaderSettingToExistingUsers(userRepository, objectMapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+59
-63
@@ -23,12 +23,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -46,7 +44,6 @@ public class CbxProcessor implements FileProcessor {
|
|||||||
public Book processFile(LibraryFile libraryFile, boolean forceProcess) {
|
public Book processFile(LibraryFile libraryFile, boolean forceProcess) {
|
||||||
File bookFile = new File(libraryFile.getFileName());
|
File bookFile = new File(libraryFile.getFileName());
|
||||||
String fileName = bookFile.getName();
|
String fileName = bookFile.getName();
|
||||||
|
|
||||||
if (!forceProcess) {
|
if (!forceProcess) {
|
||||||
Optional<BookEntity> bookOptional = bookRepository.findBookByFileNameAndLibraryId(fileName, libraryFile.getLibraryEntity().getId());
|
Optional<BookEntity> bookOptional = bookRepository.findBookByFileNameAndLibraryId(fileName, libraryFile.getLibraryEntity().getId());
|
||||||
return bookOptional.map(bookMapper::toBook).orElseGet(() -> processNewFile(libraryFile));
|
return bookOptional.map(bookMapper::toBook).orElseGet(() -> processNewFile(libraryFile));
|
||||||
@@ -71,129 +68,128 @@ public class CbxProcessor implements FileProcessor {
|
|||||||
public boolean generateCover(BookEntity bookEntity) {
|
public boolean generateCover(BookEntity bookEntity) {
|
||||||
File file = new File(FileUtils.getBookFullPath(bookEntity));
|
File file = new File(FileUtils.getBookFullPath(bookEntity));
|
||||||
try {
|
try {
|
||||||
List<BufferedImage> images = extractImagesFromArchive(file);
|
Optional<BufferedImage> imageOptional = extractImagesFromArchive(file);
|
||||||
if (images == null || images.isEmpty()) {
|
if (imageOptional.isPresent()) {
|
||||||
log.warn("No image entries found in archive: {}", file.getName());
|
BufferedImage firstImage = imageOptional.get();
|
||||||
return false;
|
boolean saved = fileProcessingUtils.saveCoverImage(firstImage, bookEntity.getId());
|
||||||
}
|
if (saved) {
|
||||||
BufferedImage coverImage = images.get(0);
|
|
||||||
boolean saved = fileProcessingUtils.saveCoverImage(coverImage, bookEntity.getId());
|
|
||||||
bookEntity.getMetadata().setCoverUpdatedOn(Instant.now());
|
bookEntity.getMetadata().setCoverUpdatedOn(Instant.now());
|
||||||
bookMetadataRepository.save(bookEntity.getMetadata());
|
bookMetadataRepository.save(bookEntity.getMetadata());
|
||||||
return saved;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error generating cover from archive {}, error: {}", bookEntity.getFileName(), e.getMessage());
|
log.error("Error generating cover from archive {}, error: {}", bookEntity.getFileName(), e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BufferedImage> extractImagesFromArchive(File file) {
|
private Optional<BufferedImage> extractImagesFromArchive(File file) {
|
||||||
String name = file.getName().toLowerCase();
|
String name = file.getName().toLowerCase();
|
||||||
if (name.endsWith(".cbz")) {
|
if (name.endsWith(".cbz")) {
|
||||||
return extractImagesFromZip(file);
|
return extractFirstImageFromZip(file);
|
||||||
} else if (name.endsWith(".cb7")) {
|
} else if (name.endsWith(".cb7")) {
|
||||||
return extractImagesFrom7z(file);
|
return extractFirstImageFrom7z(file);
|
||||||
} else if (name.endsWith(".cbr")) {
|
} else if (name.endsWith(".cbr")) {
|
||||||
return extractImagesFromRar(file);
|
return extractFirstImageFromRar(file);
|
||||||
} else {
|
} else {
|
||||||
log.warn("Unsupported archive format: {}", name);
|
log.warn("Unsupported archive format: {}", name);
|
||||||
return List.of();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BufferedImage> extractImagesFromRar(File file) {
|
private Optional<BufferedImage> extractFirstImageFromRar(File file) {
|
||||||
List<BufferedImage> images = new ArrayList<>();
|
|
||||||
try (Archive archive = new Archive(file)) {
|
try (Archive archive = new Archive(file)) {
|
||||||
List<FileHeader> headers = archive.getFileHeaders();
|
List<FileHeader> headers = archive.getFileHeaders();
|
||||||
headers.stream()
|
List<FileHeader> imageHeaders = headers.stream()
|
||||||
|
.filter(h -> !h.isDirectory())
|
||||||
.filter(h -> {
|
.filter(h -> {
|
||||||
if (h.isDirectory()) return false;
|
|
||||||
String fileName = h.getFileNameString().replace("\\", "/").toLowerCase();
|
String fileName = h.getFileNameString().replace("\\", "/").toLowerCase();
|
||||||
return fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(".png") || fileName.endsWith(".webp");
|
return fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(".png") || fileName.endsWith(".webp");
|
||||||
})
|
})
|
||||||
.sorted(Comparator.comparing(FileHeader::getFileNameString))
|
.sorted(Comparator.comparing(FileHeader::getFileNameString))
|
||||||
.forEach(header -> {
|
.toList();
|
||||||
|
|
||||||
|
for (FileHeader header : imageHeaders) {
|
||||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||||
archive.extractFile(header, baos);
|
archive.extractFile(header, baos);
|
||||||
byte[] imageData = baos.toByteArray();
|
byte[] imageData = baos.toByteArray();
|
||||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
|
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
|
||||||
if (img != null) {
|
if (img != null) {
|
||||||
images.add(img);
|
return Optional.of(img);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Failed to read image from RAR entry {}: {}", header.getFileNameString(), e.getMessage());
|
log.warn("Failed to read image from RAR entry {}: {}", header.getFileNameString(), e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error extracting images from RAR archive {}: {}", file.getName(), e.getMessage());
|
|
||||||
return List.of();
|
|
||||||
}
|
}
|
||||||
return images;
|
} catch (Exception e) {
|
||||||
|
log.error("Error extracting image from RAR archive {}: {}", file.getName(), e.getMessage());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private Optional<BufferedImage> extractFirstImageFromZip(File file) {
|
||||||
* Extracts image entries from a ZIP archive (.cbz), sorted by entry name.
|
|
||||||
*/
|
|
||||||
private List<BufferedImage> extractImagesFromZip(File file) {
|
|
||||||
List<BufferedImage> images = new ArrayList<>();
|
|
||||||
try (ZipFile zipFile = new ZipFile(file)) {
|
try (ZipFile zipFile = new ZipFile(file)) {
|
||||||
List<? extends ZipArchiveEntry> imageEntries = Collections.list(zipFile.getEntries()).stream()
|
return Collections.list(zipFile.getEntries()).stream()
|
||||||
.filter(e -> !e.isDirectory())
|
.filter(e -> !e.isDirectory())
|
||||||
.filter(e -> e.getName().matches("(?i).*\\.(jpg|jpeg|png|webp)"))
|
.filter(e -> e.getName().matches("(?i).*\\.(jpg|jpeg|png|webp)"))
|
||||||
.sorted(Comparator.comparing(ZipArchiveEntry::getName))
|
.min(Comparator.comparing(ZipArchiveEntry::getName))
|
||||||
.toList();
|
.map(entry -> {
|
||||||
for (ZipArchiveEntry entry : imageEntries) {
|
|
||||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||||
BufferedImage img = ImageIO.read(is);
|
return ImageIO.read(is);
|
||||||
if (img != null) {
|
|
||||||
images.add(img);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Failed to read image from ZIP entry {}: {}", entry.getName(), e.getMessage());
|
log.warn("Failed to read image from ZIP entry {}: {}", entry.getName(), e.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return images;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error extracting images from ZIP archive {}: {}", file.getName(), e.getMessage());
|
log.error("Error extracting image from ZIP archive {}: {}", file.getName(), e.getMessage());
|
||||||
return List.of();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BufferedImage> extractImagesFrom7z(File file) {
|
private Optional<BufferedImage> extractFirstImageFrom7z(File file) {
|
||||||
List<BufferedImage> images = new ArrayList<>();
|
|
||||||
try (SevenZFile sevenZFile = new SevenZFile(file)) {
|
try (SevenZFile sevenZFile = new SevenZFile(file)) {
|
||||||
List<SevenZArchiveEntry> entries = new ArrayList<>();
|
List<SevenZArchiveEntry> imageEntries = new ArrayList<>();
|
||||||
SevenZArchiveEntry entry;
|
SevenZArchiveEntry entry;
|
||||||
while ((entry = sevenZFile.getNextEntry()) != null) {
|
while ((entry = sevenZFile.getNextEntry()) != null) {
|
||||||
if (!entry.isDirectory() && entry.getName().matches("(?i).*\\.(jpg|jpeg|png|webp)")) {
|
if (!entry.isDirectory() && entry.getName().matches("(?i).*\\.(jpg|jpeg|png|webp)")) {
|
||||||
entries.add(entry);
|
imageEntries.add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entries.sort(Comparator.comparing(SevenZArchiveEntry::getName));
|
imageEntries.sort(Comparator.comparing(SevenZArchiveEntry::getName));
|
||||||
for (SevenZArchiveEntry e : entries) {
|
sevenZFile.close();
|
||||||
try {
|
|
||||||
byte[] content = new byte[(int) e.getSize()];
|
try (SevenZFile sevenZFileReset = new SevenZFile(file)) {
|
||||||
|
for (SevenZArchiveEntry imgEntry : imageEntries) {
|
||||||
|
SevenZArchiveEntry currentEntry;
|
||||||
|
while ((currentEntry = sevenZFileReset.getNextEntry()) != null) {
|
||||||
|
if (currentEntry.equals(imgEntry)) {
|
||||||
|
byte[] content = new byte[(int) currentEntry.getSize()];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
while (offset < content.length) {
|
while (offset < content.length) {
|
||||||
int bytesRead = sevenZFile.read(content, offset, content.length - offset);
|
int bytesRead = sevenZFileReset.read(content, offset, content.length - offset);
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
offset += bytesRead;
|
offset += bytesRead;
|
||||||
}
|
}
|
||||||
BufferedImage img = ImageIO.read(new java.io.ByteArrayInputStream(content));
|
BufferedImage img = ImageIO.read(new ByteArrayInputStream(content));
|
||||||
if (img != null) {
|
if (img != null) {
|
||||||
images.add(img);
|
return Optional.of(img);
|
||||||
}
|
} else {
|
||||||
} catch (Exception ex) {
|
break;
|
||||||
log.warn("Failed to read image from 7z entry {}: {}", e.getName(), ex.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error extracting images from 7z archive {}: {}", file.getName(), e.getMessage());
|
log.error("Error extracting image from 7z archive {}: {}", file.getName(), e.getMessage());
|
||||||
return List.of();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
return images;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMetadata(BookEntity bookEntity) {
|
private void setMetadata(BookEntity bookEntity) {
|
||||||
|
|||||||
+3
-2
@@ -181,7 +181,7 @@ public class UserProvisioningService {
|
|||||||
addUserSetting(user, UserSettingKey.PER_BOOK_SETTING, buildDefaultPerBookSetting());
|
addUserSetting(user, UserSettingKey.PER_BOOK_SETTING, buildDefaultPerBookSetting());
|
||||||
addUserSetting(user, UserSettingKey.PDF_READER_SETTING, buildDefaultPdfReaderSetting());
|
addUserSetting(user, UserSettingKey.PDF_READER_SETTING, buildDefaultPdfReaderSetting());
|
||||||
addUserSetting(user, UserSettingKey.EPUB_READER_SETTING, buildDefaultEpubReaderSetting());
|
addUserSetting(user, UserSettingKey.EPUB_READER_SETTING, buildDefaultEpubReaderSetting());
|
||||||
addUserSetting(user, UserSettingKey.CBX_READER_SETTING, buildDefaultEpubReaderSetting());
|
addUserSetting(user, UserSettingKey.CBX_READER_SETTING, buildDefaultCbxReaderSetting());
|
||||||
addUserSetting(user, UserSettingKey.SIDEBAR_LIBRARY_SORTING, buildDefaultSidebarLibrarySorting());
|
addUserSetting(user, UserSettingKey.SIDEBAR_LIBRARY_SORTING, buildDefaultSidebarLibrarySorting());
|
||||||
addUserSetting(user, UserSettingKey.SIDEBAR_SHELF_SORTING, buildDefaultSidebarShelfSorting());
|
addUserSetting(user, UserSettingKey.SIDEBAR_SHELF_SORTING, buildDefaultSidebarShelfSorting());
|
||||||
|
|
||||||
@@ -206,6 +206,7 @@ public class UserProvisioningService {
|
|||||||
return BookLoreUser.UserSettings.PerBookSetting.builder()
|
return BookLoreUser.UserSettings.PerBookSetting.builder()
|
||||||
.epub(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
.epub(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
||||||
.pdf(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
.pdf(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
||||||
|
.cbx(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +226,7 @@ public class UserProvisioningService {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BookLoreUser.UserSettings.CbxReaderSetting buildDefaultCbxReaderSetting() {
|
public BookLoreUser.UserSettings.CbxReaderSetting buildDefaultCbxReaderSetting() {
|
||||||
return BookLoreUser.UserSettings.CbxReaderSetting.builder()
|
return BookLoreUser.UserSettings.CbxReaderSetting.builder()
|
||||||
.pageViewMode(CbxPageViewMode.SINGLE_PAGE)
|
.pageViewMode(CbxPageViewMode.SINGLE_PAGE)
|
||||||
.pageSpread(CbxPageSpread.ODD)
|
.pageSpread(CbxPageSpread.ODD)
|
||||||
|
|||||||
@@ -1,13 +1,25 @@
|
|||||||
<div class="comic-reader-container">
|
<div class="comic-reader-container">
|
||||||
<div class="navigation">
|
<div class="navigation">
|
||||||
<div class="page-controls">
|
<div class="goto-page-controls" style="display: flex; align-items: center; margin-right: auto;">
|
||||||
<button (click)="previousPage()" [disabled]="currentPage === 0">←</button>
|
<input type="number" [(ngModel)]="goToPageInput" [min]="1" [max]="pages.length" placeholder="Page">
|
||||||
|
<button
|
||||||
|
(click)="goToPageInput !== null && goToPage(goToPageInput)"
|
||||||
|
[disabled]="goToPageInput === null || goToPageInput < 1 || goToPageInput > pages.length">
|
||||||
|
Go
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="page-controls" style="display: flex; align-items: center; justify-content: center; flex-grow: 1;">
|
||||||
|
<button class="mr-2" (click)="goToPage(1)" [disabled]="currentPage === 0"><<</button>
|
||||||
|
<button (click)="previousPage()" [disabled]="currentPage === 0"><</button>
|
||||||
<span>
|
<span>
|
||||||
Page {{ currentPage + 1 }}{{ isTwoPageView && imageUrls.length > 1 ? '-' + (currentPage + 2) : '' }} of {{ pages.length }}
|
Page {{ currentPage + 1 }}{{ isTwoPageView && imageUrls.length > 1 ? '-' + (currentPage + 2) : '' }} of {{ pages.length }}
|
||||||
</span>
|
</span>
|
||||||
<button (click)="nextPage()" [disabled]="currentPage >= pages.length - 1">→</button>
|
<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>
|
||||||
<div class="spread-controls">
|
|
||||||
|
<div class="spread-controls" style="display: flex; align-items: center; margin-left: auto;">
|
||||||
<button *ngIf="isTwoPageView" (click)="toggleSpreadDirection()" title="Toggle Spread Direction">
|
<button *ngIf="isTwoPageView" (click)="toggleSpreadDirection()" title="Toggle Spread Direction">
|
||||||
{{ pageSpread === 'ODD' ? '⬅️' : '➡️' }}
|
{{ pageSpread === 'ODD' ? '⬅️' : '➡️' }}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 1rem;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
||||||
@@ -26,12 +25,10 @@
|
|||||||
min-width: 8rem;
|
min-width: 8rem;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-variant-numeric: tabular-nums;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
min-width: 3rem;
|
padding: 0 0.25rem;
|
||||||
padding: 0 0.5rem;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -93,4 +90,26 @@
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,17 @@ import {MessageService} from 'primeng/api';
|
|||||||
import {forkJoin} from 'rxjs';
|
import {forkJoin} from 'rxjs';
|
||||||
import {BookSetting, CbxPageSpread, CbxPageViewMode} from '../../model/book.model';
|
import {BookSetting, CbxPageSpread, CbxPageViewMode} from '../../model/book.model';
|
||||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||||
|
import {FormsModule} from "@angular/forms";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-cbx-reader',
|
selector: 'app-cbx-reader',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [NgIf, NgFor, ProgressSpinner],
|
imports: [NgIf, NgFor, ProgressSpinner, FormsModule],
|
||||||
templateUrl: './cbx-reader.component.html',
|
templateUrl: './cbx-reader.component.html',
|
||||||
styleUrl: './cbx-reader.component.scss'
|
styleUrl: './cbx-reader.component.scss'
|
||||||
})
|
})
|
||||||
export class CbxReaderComponent implements OnInit {
|
export class CbxReaderComponent implements OnInit {
|
||||||
|
goToPageInput: number | null = null;
|
||||||
bookId!: number;
|
bookId!: number;
|
||||||
pages: number[] = [];
|
pages: number[] = [];
|
||||||
currentPage = 0;
|
currentPage = 0;
|
||||||
@@ -89,13 +91,22 @@ export class CbxReaderComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nextPage() {
|
nextPage() {
|
||||||
|
const previousPage = this.currentPage;
|
||||||
|
|
||||||
if (this.isTwoPageView) {
|
if (this.isTwoPageView) {
|
||||||
this.currentPage += (this.currentPage < this.pages.length - 2) ? 2 : 1;
|
if (this.currentPage + 2 < this.pages.length) {
|
||||||
|
this.currentPage += 2;
|
||||||
|
} else if (this.currentPage + 1 < this.pages.length) {
|
||||||
|
this.currentPage += 1;
|
||||||
|
}
|
||||||
} else if (this.currentPage < this.pages.length - 1) {
|
} else if (this.currentPage < this.pages.length - 1) {
|
||||||
this.currentPage++;
|
this.currentPage++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.currentPage !== previousPage) {
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
previousPage() {
|
previousPage() {
|
||||||
if (this.isTwoPageView) {
|
if (this.isTwoPageView) {
|
||||||
@@ -192,4 +203,14 @@ export class CbxReaderComponent implements OnInit {
|
|||||||
|
|
||||||
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage).subscribe();
|
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage).subscribe();
|
||||||
}
|
}
|
||||||
|
goToPage(page: number): void {
|
||||||
|
if (page < 1 || page > this.pages.length) return;
|
||||||
|
|
||||||
|
const targetIndex = page - 1;
|
||||||
|
if (targetIndex === this.currentPage) return;
|
||||||
|
|
||||||
|
this.currentPage = targetIndex;
|
||||||
|
this.alignCurrentPageToParity();
|
||||||
|
this.updateProgress();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user