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;
|
||||
|
||||
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.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.BookRepository;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import com.adityachandel.booklore.service.user.UserProvisioningService;
|
||||
import com.adityachandel.booklore.util.FileUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -12,6 +19,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@@ -20,6 +28,7 @@ public class AppMigrationService {
|
||||
|
||||
private AppMigrationRepository migrationRepository;
|
||||
private BookRepository bookRepository;
|
||||
private UserProvisioningService userProvisioningService;
|
||||
|
||||
@Transactional
|
||||
public void populateMissingFileSizesOnce() {
|
||||
@@ -44,4 +53,61 @@ public class AppMigrationService {
|
||||
migrationRepository.save(migration);
|
||||
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;
|
||||
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -10,9 +12,12 @@ import org.springframework.stereotype.Component;
|
||||
public class AppMigrationStartup {
|
||||
|
||||
private final AppMigrationService appMigrationService;
|
||||
private final UserRepository userRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void runMigrationsOnce() {
|
||||
appMigrationService.populateMissingFileSizesOnce();
|
||||
appMigrationService.addCbxReaderSettingToExistingUsers(userRepository, objectMapper);
|
||||
}
|
||||
}
|
||||
|
||||
+82
-86
@@ -23,12 +23,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -46,7 +44,6 @@ public class CbxProcessor implements FileProcessor {
|
||||
public Book processFile(LibraryFile libraryFile, boolean forceProcess) {
|
||||
File bookFile = new File(libraryFile.getFileName());
|
||||
String fileName = bookFile.getName();
|
||||
|
||||
if (!forceProcess) {
|
||||
Optional<BookEntity> bookOptional = bookRepository.findBookByFileNameAndLibraryId(fileName, libraryFile.getLibraryEntity().getId());
|
||||
return bookOptional.map(bookMapper::toBook).orElseGet(() -> processNewFile(libraryFile));
|
||||
@@ -71,129 +68,128 @@ public class CbxProcessor implements FileProcessor {
|
||||
public boolean generateCover(BookEntity bookEntity) {
|
||||
File file = new File(FileUtils.getBookFullPath(bookEntity));
|
||||
try {
|
||||
List<BufferedImage> images = extractImagesFromArchive(file);
|
||||
if (images == null || images.isEmpty()) {
|
||||
log.warn("No image entries found in archive: {}", file.getName());
|
||||
return false;
|
||||
Optional<BufferedImage> imageOptional = extractImagesFromArchive(file);
|
||||
if (imageOptional.isPresent()) {
|
||||
BufferedImage firstImage = imageOptional.get();
|
||||
boolean saved = fileProcessingUtils.saveCoverImage(firstImage, bookEntity.getId());
|
||||
if (saved) {
|
||||
bookEntity.getMetadata().setCoverUpdatedOn(Instant.now());
|
||||
bookMetadataRepository.save(bookEntity.getMetadata());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
BufferedImage coverImage = images.get(0);
|
||||
boolean saved = fileProcessingUtils.saveCoverImage(coverImage, bookEntity.getId());
|
||||
bookEntity.getMetadata().setCoverUpdatedOn(Instant.now());
|
||||
bookMetadataRepository.save(bookEntity.getMetadata());
|
||||
return saved;
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("Error generating cover from archive {}, error: {}", bookEntity.getFileName(), e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private List<BufferedImage> extractImagesFromArchive(File file) {
|
||||
private Optional<BufferedImage> extractImagesFromArchive(File file) {
|
||||
String name = file.getName().toLowerCase();
|
||||
if (name.endsWith(".cbz")) {
|
||||
return extractImagesFromZip(file);
|
||||
return extractFirstImageFromZip(file);
|
||||
} else if (name.endsWith(".cb7")) {
|
||||
return extractImagesFrom7z(file);
|
||||
return extractFirstImageFrom7z(file);
|
||||
} else if (name.endsWith(".cbr")) {
|
||||
return extractImagesFromRar(file);
|
||||
return extractFirstImageFromRar(file);
|
||||
} else {
|
||||
log.warn("Unsupported archive format: {}", name);
|
||||
return List.of();
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private List<BufferedImage> extractImagesFromRar(File file) {
|
||||
List<BufferedImage> images = new ArrayList<>();
|
||||
private Optional<BufferedImage> extractFirstImageFromRar(File file) {
|
||||
try (Archive archive = new Archive(file)) {
|
||||
List<FileHeader> headers = archive.getFileHeaders();
|
||||
headers.stream()
|
||||
List<FileHeader> imageHeaders = headers.stream()
|
||||
.filter(h -> !h.isDirectory())
|
||||
.filter(h -> {
|
||||
if (h.isDirectory()) return false;
|
||||
String fileName = h.getFileNameString().replace("\\", "/").toLowerCase();
|
||||
return fileName.endsWith(".jpg") || fileName.endsWith(".jpeg") || fileName.endsWith(".png") || fileName.endsWith(".webp");
|
||||
})
|
||||
.sorted(Comparator.comparing(FileHeader::getFileNameString))
|
||||
.forEach(header -> {
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
archive.extractFile(header, baos);
|
||||
byte[] imageData = baos.toByteArray();
|
||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
|
||||
if (img != null) {
|
||||
images.add(img);
|
||||
}
|
||||
.toList();
|
||||
|
||||
for (FileHeader header : imageHeaders) {
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
archive.extractFile(header, baos);
|
||||
byte[] imageData = baos.toByteArray();
|
||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
|
||||
if (img != null) {
|
||||
return Optional.of(img);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to read image from RAR entry {}: {}", header.getFileNameString(), e.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error extracting image from RAR archive {}: {}", file.getName(), e.getMessage());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<BufferedImage> extractFirstImageFromZip(File file) {
|
||||
try (ZipFile zipFile = new ZipFile(file)) {
|
||||
return Collections.list(zipFile.getEntries()).stream()
|
||||
.filter(e -> !e.isDirectory())
|
||||
.filter(e -> e.getName().matches("(?i).*\\.(jpg|jpeg|png|webp)"))
|
||||
.min(Comparator.comparing(ZipArchiveEntry::getName))
|
||||
.map(entry -> {
|
||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||
return ImageIO.read(is);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to read image from RAR entry {}: {}", header.getFileNameString(), e.getMessage());
|
||||
log.warn("Failed to read image from ZIP entry {}: {}", entry.getName(), e.getMessage());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("Error extracting images from RAR archive {}: {}", file.getName(), e.getMessage());
|
||||
return List.of();
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)) {
|
||||
List<? extends ZipArchiveEntry> imageEntries = Collections.list(zipFile.getEntries()).stream()
|
||||
.filter(e -> !e.isDirectory())
|
||||
.filter(e -> e.getName().matches("(?i).*\\.(jpg|jpeg|png|webp)"))
|
||||
.sorted(Comparator.comparing(ZipArchiveEntry::getName))
|
||||
.toList();
|
||||
for (ZipArchiveEntry entry : imageEntries) {
|
||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||
BufferedImage img = ImageIO.read(is);
|
||||
if (img != null) {
|
||||
images.add(img);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to read image from ZIP entry {}: {}", entry.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
return images;
|
||||
} catch (Exception e) {
|
||||
log.error("Error extracting images from ZIP archive {}: {}", file.getName(), e.getMessage());
|
||||
return List.of();
|
||||
log.error("Error extracting image from ZIP archive {}: {}", file.getName(), e.getMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private List<BufferedImage> extractImagesFrom7z(File file) {
|
||||
List<BufferedImage> images = new ArrayList<>();
|
||||
private Optional<BufferedImage> extractFirstImageFrom7z(File file) {
|
||||
try (SevenZFile sevenZFile = new SevenZFile(file)) {
|
||||
List<SevenZArchiveEntry> entries = new ArrayList<>();
|
||||
List<SevenZArchiveEntry> imageEntries = new ArrayList<>();
|
||||
SevenZArchiveEntry entry;
|
||||
while ((entry = sevenZFile.getNextEntry()) != null) {
|
||||
if (!entry.isDirectory() && entry.getName().matches("(?i).*\\.(jpg|jpeg|png|webp)")) {
|
||||
entries.add(entry);
|
||||
imageEntries.add(entry);
|
||||
}
|
||||
}
|
||||
entries.sort(Comparator.comparing(SevenZArchiveEntry::getName));
|
||||
for (SevenZArchiveEntry e : entries) {
|
||||
try {
|
||||
byte[] content = new byte[(int) e.getSize()];
|
||||
int offset = 0;
|
||||
while (offset < content.length) {
|
||||
int bytesRead = sevenZFile.read(content, offset, content.length - offset);
|
||||
if (bytesRead < 0) {
|
||||
break;
|
||||
imageEntries.sort(Comparator.comparing(SevenZArchiveEntry::getName));
|
||||
sevenZFile.close();
|
||||
|
||||
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;
|
||||
while (offset < content.length) {
|
||||
int bytesRead = sevenZFileReset.read(content, offset, content.length - offset);
|
||||
if (bytesRead < 0) {
|
||||
break;
|
||||
}
|
||||
offset += bytesRead;
|
||||
}
|
||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(content));
|
||||
if (img != null) {
|
||||
return Optional.of(img);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset += bytesRead;
|
||||
}
|
||||
BufferedImage img = ImageIO.read(new java.io.ByteArrayInputStream(content));
|
||||
if (img != null) {
|
||||
images.add(img);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.warn("Failed to read image from 7z entry {}: {}", e.getName(), ex.getMessage());
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
} catch (Exception e) {
|
||||
log.error("Error extracting images from 7z archive {}: {}", file.getName(), e.getMessage());
|
||||
return List.of();
|
||||
log.error("Error extracting image from 7z archive {}: {}", file.getName(), e.getMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
return images;
|
||||
}
|
||||
|
||||
private void setMetadata(BookEntity bookEntity) {
|
||||
|
||||
+3
-2
@@ -181,7 +181,7 @@ public class UserProvisioningService {
|
||||
addUserSetting(user, UserSettingKey.PER_BOOK_SETTING, buildDefaultPerBookSetting());
|
||||
addUserSetting(user, UserSettingKey.PDF_READER_SETTING, buildDefaultPdfReaderSetting());
|
||||
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_SHELF_SORTING, buildDefaultSidebarShelfSorting());
|
||||
|
||||
@@ -206,6 +206,7 @@ public class UserProvisioningService {
|
||||
return BookLoreUser.UserSettings.PerBookSetting.builder()
|
||||
.epub(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
||||
.pdf(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
||||
.cbx(BookLoreUser.UserSettings.PerBookSetting.GlobalOrIndividual.Individual)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -225,7 +226,7 @@ public class UserProvisioningService {
|
||||
.build();
|
||||
}
|
||||
|
||||
private BookLoreUser.UserSettings.CbxReaderSetting buildDefaultCbxReaderSetting() {
|
||||
public BookLoreUser.UserSettings.CbxReaderSetting buildDefaultCbxReaderSetting() {
|
||||
return BookLoreUser.UserSettings.CbxReaderSetting.builder()
|
||||
.pageViewMode(CbxPageViewMode.SINGLE_PAGE)
|
||||
.pageSpread(CbxPageSpread.ODD)
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
<div class="comic-reader-container">
|
||||
<div class="navigation">
|
||||
<div class="page-controls">
|
||||
<button (click)="previousPage()" [disabled]="currentPage === 0">←</button>
|
||||
<div class="goto-page-controls" style="display: flex; align-items: center; margin-right: auto;">
|
||||
<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>
|
||||
Page {{ currentPage + 1 }}{{ isTwoPageView && imageUrls.length > 1 ? '-' + (currentPage + 2) : '' }} of {{ pages.length }}
|
||||
</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 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">
|
||||
{{ pageSpread === 'ODD' ? '⬅️' : '➡️' }}
|
||||
</button>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -26,12 +25,10 @@
|
||||
min-width: 8rem;
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
button {
|
||||
min-width: 3rem;
|
||||
padding: 0 0.5rem;
|
||||
padding: 0 0.25rem;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
@@ -93,4 +90,26 @@
|
||||
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 {BookSetting, CbxPageSpread, CbxPageViewMode} from '../../model/book.model';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {FormsModule} from "@angular/forms";
|
||||
|
||||
@Component({
|
||||
selector: 'app-cbx-reader',
|
||||
standalone: true,
|
||||
imports: [NgIf, NgFor, ProgressSpinner],
|
||||
imports: [NgIf, NgFor, ProgressSpinner, FormsModule],
|
||||
templateUrl: './cbx-reader.component.html',
|
||||
styleUrl: './cbx-reader.component.scss'
|
||||
})
|
||||
export class CbxReaderComponent implements OnInit {
|
||||
goToPageInput: number | null = null;
|
||||
bookId!: number;
|
||||
pages: number[] = [];
|
||||
currentPage = 0;
|
||||
@@ -89,12 +91,21 @@ export class CbxReaderComponent implements OnInit {
|
||||
}
|
||||
|
||||
nextPage() {
|
||||
const previousPage = this.currentPage;
|
||||
|
||||
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) {
|
||||
this.currentPage++;
|
||||
}
|
||||
this.updateProgress();
|
||||
|
||||
if (this.currentPage !== previousPage) {
|
||||
this.updateProgress();
|
||||
}
|
||||
}
|
||||
|
||||
previousPage() {
|
||||
@@ -192,4 +203,14 @@ export class CbxReaderComponent implements OnInit {
|
||||
|
||||
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