feat(reader): add PDF annotations, Range streaming, and optimized chunk loading (#2701)
This commit is contained in:
@@ -240,8 +240,8 @@ public class SecurityConfig {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
configuration.setAllowedOriginPatterns(List.of("*"));
|
||||
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
|
||||
configuration.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type"));
|
||||
configuration.setExposedHeaders(List.of("Content-Disposition"));
|
||||
configuration.setAllowedHeaders(List.of("Authorization", "Cache-Control", "Content-Type", "Range"));
|
||||
configuration.setExposedHeaders(List.of("Content-Disposition", "Accept-Ranges", "Content-Range", "Content-Length"));
|
||||
configuration.setAllowCredentials(true);
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class ImageCachingFilter extends OncePerRequestFilter {
|
||||
String uri = request.getRequestURI();
|
||||
if (uri.startsWith("/api/v1/media/book/") &&
|
||||
(uri.contains("/cover") || uri.contains("/thumbnail") || uri.contains("/backup-cover") ||
|
||||
uri.contains("/pdf/pages/") || uri.contains("/cbx/pages/"))) {
|
||||
uri.contains("/cbx/pages/"))) {
|
||||
response.setHeader(HttpHeaders.CACHE_CONTROL, "public, max-age=3600");
|
||||
response.setHeader(HttpHeaders.EXPIRES, String.valueOf(System.currentTimeMillis() + 3600_000));
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Max;
|
||||
@@ -119,14 +120,19 @@ public class BookController {
|
||||
return ResponseEntity.ok(bookMetadataService.getComicInfoMetadata(bookId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get book content", description = "Retrieve the binary content of a book for reading.")
|
||||
@ApiResponse(responseCode = "200", description = "Book content returned successfully")
|
||||
@Operation(summary = "Get book content", description = "Retrieve the binary content of a book for reading. Supports HTTP Range requests for partial content streaming.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Full book content returned"),
|
||||
@ApiResponse(responseCode = "206", description = "Partial content returned for Range request")
|
||||
})
|
||||
@GetMapping("/{bookId}/content")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Resource> getBookContent(
|
||||
public void getBookContent(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId,
|
||||
@Parameter(description = "Optional book type for alternative format (e.g., EPUB, PDF, MOBI)") @RequestParam(required = false) String bookType) {
|
||||
return bookService.getBookContent(bookId, bookType);
|
||||
@Parameter(description = "Optional book type for alternative format (e.g., EPUB, PDF, MOBI)") @RequestParam(required = false) String bookType,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response) throws java.io.IOException {
|
||||
bookService.streamBookContent(bookId, bookType, request, response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Download book", description = "Download the book file. Requires download permission or admin.")
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.booklore.controller;
|
||||
import org.booklore.service.book.BookService;
|
||||
import org.booklore.service.bookdrop.BookDropService;
|
||||
import org.booklore.service.reader.CbxReaderService;
|
||||
import org.booklore.service.reader.PdfReaderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
@@ -25,7 +24,6 @@ import java.io.IOException;
|
||||
public class BookMediaController {
|
||||
|
||||
private final BookService bookService;
|
||||
private final PdfReaderService pdfReaderService;
|
||||
private final CbxReaderService cbxReaderService;
|
||||
private final BookDropService bookDropService;
|
||||
|
||||
@@ -57,18 +55,6 @@ public class BookMediaController {
|
||||
return ResponseEntity.ok(bookService.getAudiobookCover(bookId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get PDF page as image", description = "Retrieve a specific page from a PDF book as an image.")
|
||||
@ApiResponse(responseCode = "200", description = "PDF page image returned successfully")
|
||||
@GetMapping("/book/{bookId}/pdf/pages/{pageNumber}")
|
||||
public void getPdfPage(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId,
|
||||
@Parameter(description = "Page number to retrieve") @PathVariable int pageNumber,
|
||||
@Parameter(description = "Optional book type for alternative format (e.g., PDF, CBX)") @RequestParam(required = false) String bookType,
|
||||
HttpServletResponse response) throws IOException {
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
pdfReaderService.streamPageImage(bookId, bookType, pageNumber, response.getOutputStream());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get CBX page as image", description = "Retrieve a specific page from a CBX book as an image.")
|
||||
@ApiResponse(responseCode = "200", description = "CBX page image returned successfully")
|
||||
@GetMapping("/book/{bookId}/cbx/pages/{pageNumber}")
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.booklore.controller;
|
||||
|
||||
import org.booklore.config.security.annotation.CheckBookAccess;
|
||||
import org.booklore.service.book.PdfAnnotationService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/pdf-annotations")
|
||||
@Tag(name = "PDF Annotations", description = "Endpoints for managing PDF annotation data")
|
||||
public class PdfAnnotationController {
|
||||
|
||||
private final PdfAnnotationService pdfAnnotationService;
|
||||
|
||||
@Operation(summary = "Get PDF annotations for a book", description = "Retrieve serialized PDF annotations for a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "Annotations returned successfully")
|
||||
@ApiResponse(responseCode = "204", description = "No annotations found")
|
||||
@GetMapping("/book/{bookId}")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Map<String, String>> getAnnotations(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
return pdfAnnotationService.getAnnotations(bookId)
|
||||
.map(data -> ResponseEntity.ok(Map.of("data", data)))
|
||||
.orElse(ResponseEntity.noContent().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "Save PDF annotations for a book", description = "Save or update serialized PDF annotations for a specific book.")
|
||||
@ApiResponse(responseCode = "204", description = "Annotations saved successfully")
|
||||
@PutMapping("/book/{bookId}")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Void> saveAnnotations(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId,
|
||||
@RequestBody Map<String, String> body) {
|
||||
pdfAnnotationService.saveAnnotations(bookId, body.get("data"));
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete PDF annotations for a book", description = "Delete all PDF annotations for a specific book.")
|
||||
@ApiResponse(responseCode = "204", description = "Annotations deleted successfully")
|
||||
@DeleteMapping("/book/{bookId}")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Void> deleteAnnotations(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
pdfAnnotationService.deleteAnnotations(bookId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.booklore.model.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table(name = "pdf_annotations")
|
||||
public class PdfAnnotationEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private BookLoreUserEntity user;
|
||||
|
||||
@Column(name = "user_id", insertable = false, updatable = false)
|
||||
private Long userId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "book_id", nullable = false)
|
||||
private BookEntity book;
|
||||
|
||||
@Column(name = "book_id", insertable = false, updatable = false)
|
||||
private Long bookId;
|
||||
|
||||
@Lob
|
||||
@Column(name = "data", nullable = false, columnDefinition = "LONGTEXT")
|
||||
private String data;
|
||||
|
||||
@jakarta.persistence.Version
|
||||
@Column(name = "version", nullable = false)
|
||||
private Long version;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
@Column(name = "updated_at", nullable = false)
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.booklore.repository;
|
||||
|
||||
import org.booklore.model.entity.PdfAnnotationEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PdfAnnotationRepository extends JpaRepository<PdfAnnotationEntity, Long> {
|
||||
|
||||
Optional<PdfAnnotationEntity> findByBookIdAndUserId(Long bookId, Long userId);
|
||||
|
||||
void deleteByBookIdAndUserId(Long bookId, Long userId);
|
||||
}
|
||||
@@ -18,8 +18,10 @@ import org.booklore.repository.BookFileRepository;
|
||||
import org.booklore.service.metadata.sidecar.SidecarMetadataWriter;
|
||||
import org.booklore.service.monitoring.MonitoringRegistrationService;
|
||||
import org.booklore.service.progress.ReadingProgressService;
|
||||
import org.booklore.service.FileStreamingService;
|
||||
import org.booklore.util.FileService;
|
||||
import org.booklore.util.FileUtils;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -63,6 +65,7 @@ public class BookService {
|
||||
private final BookUpdateService bookUpdateService;
|
||||
private final EbookViewerPreferenceRepository ebookViewerPreferencesRepository;
|
||||
private final SidecarMetadataWriter sidecarMetadataWriter;
|
||||
private final FileStreamingService fileStreamingService;
|
||||
|
||||
|
||||
public List<Book> getBookDTOs(boolean includeDescription) {
|
||||
@@ -320,6 +323,36 @@ public class BookService {
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
public void streamBookContent(long bookId, String bookType, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
String filePath;
|
||||
if (bookType != null) {
|
||||
BookFileType requestedType = BookFileType.valueOf(bookType.toUpperCase());
|
||||
BookFileEntity bookFile = bookEntity.getBookFiles().stream()
|
||||
.filter(bf -> bf.getBookType() == requestedType)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> ApiError.FILE_NOT_FOUND.createException("No file of type " + bookType + " found for book"));
|
||||
filePath = bookFile.getFullFilePath().toString();
|
||||
} else {
|
||||
filePath = FileUtils.getBookFullPath(bookEntity);
|
||||
}
|
||||
|
||||
Path path = Paths.get(filePath);
|
||||
String fileName = path.getFileName().toString();
|
||||
String extension = fileName.contains(".") ? fileName.substring(fileName.lastIndexOf('.') + 1) : "";
|
||||
String contentType = switch (extension.toLowerCase()) {
|
||||
case "pdf" -> "application/pdf";
|
||||
case "epub" -> "application/epub+zip";
|
||||
case "mobi", "azw3" -> "application/x-mobipocket-ebook";
|
||||
case "cbz" -> "application/vnd.comicbook+zip";
|
||||
case "cbr" -> "application/vnd.comicbook-rar";
|
||||
case "fb2" -> "application/x-fictionbook+xml";
|
||||
default -> "application/octet-stream";
|
||||
};
|
||||
|
||||
fileStreamingService.streamWithRangeSupport(path, contentType, request, response);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public ResponseEntity<BookDeletionResponse> deleteBooks(Set<Long> ids) {
|
||||
List<BookEntity> books = bookQueryService.findAllWithMetadataByIds(ids);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package org.booklore.service.book;
|
||||
|
||||
import org.booklore.config.security.service.AuthenticationService;
|
||||
import org.booklore.model.entity.BookEntity;
|
||||
import org.booklore.model.entity.BookLoreUserEntity;
|
||||
import org.booklore.model.entity.PdfAnnotationEntity;
|
||||
import org.booklore.repository.BookRepository;
|
||||
import org.booklore.repository.PdfAnnotationRepository;
|
||||
import org.booklore.repository.UserRepository;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class PdfAnnotationService {
|
||||
|
||||
private final PdfAnnotationRepository pdfAnnotationRepository;
|
||||
private final BookRepository bookRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final AuthenticationService authenticationService;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public Optional<String> getAnnotations(Long bookId) {
|
||||
Long userId = getCurrentUserId();
|
||||
return pdfAnnotationRepository.findByBookIdAndUserId(bookId, userId)
|
||||
.map(PdfAnnotationEntity::getData);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void saveAnnotations(Long bookId, String data) {
|
||||
Long userId = getCurrentUserId();
|
||||
Optional<PdfAnnotationEntity> existing = pdfAnnotationRepository.findByBookIdAndUserId(bookId, userId);
|
||||
|
||||
if (existing.isPresent()) {
|
||||
PdfAnnotationEntity entity = existing.get();
|
||||
entity.setData(data);
|
||||
pdfAnnotationRepository.save(entity);
|
||||
log.info("Updated PDF annotations for book {} by user {}", bookId, userId);
|
||||
} else {
|
||||
PdfAnnotationEntity entity = PdfAnnotationEntity.builder()
|
||||
.book(findBook(bookId))
|
||||
.user(findUser(userId))
|
||||
.data(data)
|
||||
.build();
|
||||
pdfAnnotationRepository.save(entity);
|
||||
log.info("Created PDF annotations for book {} by user {}", bookId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAnnotations(Long bookId) {
|
||||
Long userId = getCurrentUserId();
|
||||
pdfAnnotationRepository.deleteByBookIdAndUserId(bookId, userId);
|
||||
log.info("Deleted PDF annotations for book {} by user {}", bookId, userId);
|
||||
}
|
||||
|
||||
private Long getCurrentUserId() {
|
||||
return authenticationService.getAuthenticatedUser().getId();
|
||||
}
|
||||
|
||||
private BookEntity findBook(Long bookId) {
|
||||
return bookRepository.findById(bookId)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Book not found: " + bookId));
|
||||
}
|
||||
|
||||
private BookLoreUserEntity findUser(Long userId) {
|
||||
return userRepository.findById(userId)
|
||||
.orElseThrow(() -> new EntityNotFoundException("User not found: " + userId));
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
package org.booklore.service.reader;
|
||||
|
||||
import org.booklore.exception.ApiError;
|
||||
import org.booklore.model.dto.response.PdfBookInfo;
|
||||
import org.booklore.model.dto.response.PdfOutlineItem;
|
||||
import org.booklore.model.entity.BookEntity;
|
||||
import org.booklore.model.entity.BookFileEntity;
|
||||
import org.booklore.model.enums.BookFileType;
|
||||
import org.booklore.repository.BookRepository;
|
||||
import org.booklore.util.FileUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.pdfbox.Loader;
|
||||
@@ -18,6 +10,14 @@ import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocume
|
||||
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
|
||||
import org.apache.pdfbox.rendering.ImageType;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.booklore.exception.ApiError;
|
||||
import org.booklore.model.dto.response.PdfBookInfo;
|
||||
import org.booklore.model.dto.response.PdfOutlineItem;
|
||||
import org.booklore.model.entity.BookEntity;
|
||||
import org.booklore.model.entity.BookFileEntity;
|
||||
import org.booklore.model.enums.BookFileType;
|
||||
import org.booklore.repository.BookRepository;
|
||||
import org.booklore.util.FileUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -27,7 +27,10 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -57,8 +60,8 @@ public class PdfReaderService {
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getAvailablePages(Long bookId) {
|
||||
return getAvailablePages(bookId, null);
|
||||
public void getAvailablePages(Long bookId) {
|
||||
getAvailablePages(bookId, null);
|
||||
}
|
||||
|
||||
public List<Integer> getAvailablePages(Long bookId, String bookType) {
|
||||
@@ -74,10 +77,6 @@ public class PdfReaderService {
|
||||
}
|
||||
}
|
||||
|
||||
public PdfBookInfo getBookInfo(Long bookId) {
|
||||
return getBookInfo(bookId, null);
|
||||
}
|
||||
|
||||
public PdfBookInfo getBookInfo(Long bookId, String bookType) {
|
||||
Path pdfPath = getBookPath(bookId, bookType);
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
CREATE TABLE IF NOT EXISTS pdf_annotations
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
book_id BIGINT NOT NULL,
|
||||
data LONGTEXT NOT NULL,
|
||||
version BIGINT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL,
|
||||
updated_at DATETIME NOT NULL,
|
||||
UNIQUE (user_id, book_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_pdf_annotations_user_id ON pdf_annotations (user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_pdf_annotations_book_id ON pdf_annotations (book_id);
|
||||
|
||||
ALTER TABLE pdf_annotations
|
||||
ADD CONSTRAINT fk_pdf_annotations_user
|
||||
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE pdf_annotations
|
||||
ADD CONSTRAINT fk_pdf_annotations_book
|
||||
FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE;
|
||||
@@ -10,6 +10,7 @@ import org.booklore.service.book.BookUpdateService;
|
||||
import org.booklore.service.progress.ReadingProgressService;
|
||||
import org.booklore.service.metadata.sidecar.SidecarMetadataWriter;
|
||||
import org.booklore.service.monitoring.MonitoringRegistrationService;
|
||||
import org.booklore.service.FileStreamingService;
|
||||
import org.booklore.util.FileService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -53,6 +54,7 @@ class BookServiceDeleteTests {
|
||||
MonitoringRegistrationService monitoringRegistrationService = Mockito.mock(MonitoringRegistrationService.class);
|
||||
BookUpdateService bookUpdateService = Mockito.mock(BookUpdateService.class);
|
||||
SidecarMetadataWriter sidecarMetadataWriter = Mockito.mock(SidecarMetadataWriter.class);
|
||||
FileStreamingService fileStreamingService = Mockito.mock(FileStreamingService.class);
|
||||
|
||||
bookService = new BookService(
|
||||
bookRepository,
|
||||
@@ -70,7 +72,8 @@ class BookServiceDeleteTests {
|
||||
monitoringRegistrationService,
|
||||
bookUpdateService,
|
||||
ebookViewerPreferenceRepository,
|
||||
sidecarMetadataWriter
|
||||
sidecarMetadataWriter,
|
||||
fileStreamingService
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ export class BookService {
|
||||
|
||||
/*------------------ Reading & Viewer Settings ------------------*/
|
||||
|
||||
readBook(bookId: number, reader?: 'pdf-streaming' | 'epub-streaming', explicitBookType?: BookType): void {
|
||||
readBook(bookId: number, reader?: 'epub-streaming', explicitBookType?: BookType): void {
|
||||
const book = this.bookStateService
|
||||
.getCurrentBookState()
|
||||
.books?.find(b => b.id === bookId);
|
||||
@@ -289,7 +289,7 @@ export class BookService {
|
||||
|
||||
switch (bookType) {
|
||||
case 'PDF':
|
||||
baseUrl = reader === 'pdf-streaming' ? 'cbx-reader' : 'pdf-reader';
|
||||
baseUrl = 'pdf-reader';
|
||||
break;
|
||||
|
||||
case 'EPUB':
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {AuthService} from '../../../shared/service/auth.service';
|
||||
|
||||
export interface PdfInfoPage {
|
||||
pageNumber: number;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export interface PdfOutlineItem {
|
||||
title: string;
|
||||
pageNumber: number;
|
||||
children: PdfOutlineItem[] | null;
|
||||
}
|
||||
|
||||
export interface PdfInfo {
|
||||
pageCount: number;
|
||||
outline: PdfOutlineItem[] | null;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NewPdfReaderService {
|
||||
|
||||
private readonly pagesUrl = `${API_CONFIG.BASE_URL}/api/v1/pdf`;
|
||||
private readonly imageUrl = `${API_CONFIG.BASE_URL}/api/v1/media/book`;
|
||||
private authService = inject(AuthService);
|
||||
private http = inject(HttpClient);
|
||||
|
||||
private getToken(): string | null {
|
||||
return this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
|
||||
}
|
||||
|
||||
private appendToken(url: string): string {
|
||||
const token = this.getToken();
|
||||
return token ? `${url}${url.includes('?') ? '&' : '?'}token=${token}` : url;
|
||||
}
|
||||
|
||||
getAvailablePages(bookId: number, bookType?: string) {
|
||||
let url = `${this.pagesUrl}/${bookId}/pages`;
|
||||
if (bookType) {
|
||||
url += `?bookType=${bookType}`;
|
||||
}
|
||||
return this.http.get<number[]>(this.appendToken(url));
|
||||
}
|
||||
|
||||
getPageInfo(bookId: number, bookType?: string) {
|
||||
let url = `${this.pagesUrl}/${bookId}/info`;
|
||||
if (bookType) {
|
||||
url += `?bookType=${bookType}`;
|
||||
}
|
||||
return this.http.get<PdfInfo>(this.appendToken(url));
|
||||
}
|
||||
|
||||
getPageImageUrl(bookId: number, page: number, bookType?: string): string {
|
||||
let url = `${this.imageUrl}/${bookId}/pdf/pages/${page}`;
|
||||
if (bookType) {
|
||||
url += `?bookType=${bookType}`;
|
||||
}
|
||||
return this.appendToken(url);
|
||||
}
|
||||
}
|
||||
+5
-24
@@ -145,26 +145,7 @@
|
||||
<span class="file-size">{{ getFileSizeInMB(book.primaryFile) }}</span>
|
||||
</div>
|
||||
<div class="file-actions">
|
||||
@if (book.primaryFile.bookType === 'PDF') {
|
||||
<p-button
|
||||
icon="pi pi-book"
|
||||
size="small"
|
||||
text
|
||||
severity="primary"
|
||||
[pTooltip]="t('readTooltip')"
|
||||
tooltipPosition="top"
|
||||
(onClick)="read(book.id)">
|
||||
</p-button>
|
||||
<p-button
|
||||
icon="pi pi-play"
|
||||
size="small"
|
||||
text
|
||||
severity="info"
|
||||
[pTooltip]="t('streamingReaderTooltip')"
|
||||
tooltipPosition="top"
|
||||
(onClick)="read(book.id, 'pdf-streaming')">
|
||||
</p-button>
|
||||
} @else if (book.primaryFile.bookType === 'EPUB') {
|
||||
@if (book.primaryFile.bookType === 'EPUB') {
|
||||
<p-button
|
||||
icon="pi pi-book"
|
||||
size="small"
|
||||
@@ -183,7 +164,7 @@
|
||||
tooltipPosition="top"
|
||||
(onClick)="read(book.id, 'epub-streaming')">
|
||||
</p-button>
|
||||
} @else if (book.primaryFile.bookType && ['FB2', 'MOBI', 'AZW3', 'CBX'].includes(book.primaryFile.bookType)) {
|
||||
} @else if (book.primaryFile.bookType && ['PDF', 'FB2', 'MOBI', 'AZW3', 'CBX'].includes(book.primaryFile.bookType)) {
|
||||
<p-button
|
||||
icon="pi pi-book"
|
||||
size="small"
|
||||
@@ -241,7 +222,7 @@
|
||||
<span class="file-size">{{ getFileSizeInMB(format) }}</span>
|
||||
</div>
|
||||
<div class="file-actions">
|
||||
@if (format.bookType === 'PDF' || format.bookType === 'EPUB') {
|
||||
@if (format.bookType === 'EPUB') {
|
||||
<p-button
|
||||
icon="pi pi-book"
|
||||
size="small"
|
||||
@@ -258,9 +239,9 @@
|
||||
severity="info"
|
||||
[pTooltip]="t('streamingReaderTooltip')"
|
||||
tooltipPosition="top"
|
||||
(onClick)="read(book.id, format.bookType === 'PDF' ? 'pdf-streaming' : 'epub-streaming', format.bookType)">
|
||||
(onClick)="read(book.id, 'epub-streaming', format.bookType)">
|
||||
</p-button>
|
||||
} @else if (format.bookType && ['FB2', 'MOBI', 'AZW3', 'CBX'].includes(format.bookType)) {
|
||||
} @else if (format.bookType && ['PDF', 'FB2', 'MOBI', 'AZW3', 'CBX'].includes(format.bookType)) {
|
||||
<p-button
|
||||
icon="pi pi-book"
|
||||
size="small"
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ import {TranslocoDirective} from '@jsverse/transloco';
|
||||
|
||||
export interface ReadEvent {
|
||||
bookId: number;
|
||||
reader?: 'pdf-streaming' | 'epub-streaming';
|
||||
reader?: 'epub-streaming';
|
||||
bookType?: BookType;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export class MetadataTabsComponent {
|
||||
return this.bookInSeries && this.bookInSeries.length > 1 ? 'series' : 'similar';
|
||||
}
|
||||
|
||||
read(bookId: number, reader?: 'pdf-streaming' | 'epub-streaming', bookType?: BookType): void {
|
||||
read(bookId: number, reader?: 'epub-streaming', bookType?: BookType): void {
|
||||
this.readBook.emit({ bookId, reader, bookType });
|
||||
}
|
||||
|
||||
|
||||
+5
-11
@@ -105,13 +105,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
map((book): MenuItem[] => {
|
||||
const items: MenuItem[] = [];
|
||||
const primaryType = book.primaryFile?.bookType;
|
||||
if (primaryType === 'PDF') {
|
||||
items.push({
|
||||
label: this.t.translate('metadata.viewer.menuStreamingReader'),
|
||||
icon: 'pi pi-play',
|
||||
command: () => this.read(book.id, 'pdf-streaming')
|
||||
});
|
||||
} else if (primaryType === 'EPUB') {
|
||||
if (primaryType === 'EPUB') {
|
||||
items.push({
|
||||
label: this.t.translate('metadata.viewer.menuStreamingReader'),
|
||||
icon: 'pi pi-play',
|
||||
@@ -133,8 +127,8 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
uniqueAltTypes.forEach(formatType => {
|
||||
if (formatType === 'PDF' || formatType === 'EPUB') {
|
||||
// For PDF/EPUB, offer both standard and streaming readers
|
||||
if (formatType === 'EPUB') {
|
||||
// For EPUB, offer both standard and streaming readers
|
||||
items.push({
|
||||
label: formatType,
|
||||
icon: this.getFileIcon(formatType),
|
||||
@@ -147,7 +141,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
{
|
||||
label: this.t.translate('metadata.viewer.menuStreamingReader'),
|
||||
icon: 'pi pi-play',
|
||||
command: () => this.read(book.id, formatType === 'PDF' ? 'pdf-streaming' : 'epub-streaming', formatType)
|
||||
command: () => this.read(book.id, 'epub-streaming', formatType)
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -474,7 +468,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
|
||||
this.isExpanded = !this.isExpanded;
|
||||
}
|
||||
|
||||
read(bookId: number | undefined, reader?: "pdf-streaming" | "epub-streaming", bookType?: BookType): void {
|
||||
read(bookId: number | undefined, reader?: "epub-streaming", bookType?: BookType): void {
|
||||
if (bookId) this.bookService.readBook(bookId, reader, bookType);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@ import {filter, first, map, switchMap, takeUntil, timeout} from 'rxjs/operators'
|
||||
import {PageTitleService} from "../../../shared/service/page-title.service";
|
||||
import {CbxReaderService} from '../../book/service/cbx-reader.service';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode, UserService} from '../../settings/user-management/user.service';
|
||||
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, UserService} from '../../settings/user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Book, BookSetting, BookType} from '../../book/model/book.model';
|
||||
import {BookState} from '../../book/model/state/book-state.model';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {NewPdfReaderService} from '../../book/service/new-pdf-reader.service';
|
||||
import {ReadingSessionService} from '../../../shared/service/reading-session.service';
|
||||
import {ReaderHeaderFooterVisibilityManager} from '../ebook-reader';
|
||||
|
||||
@@ -63,11 +62,11 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
currentPage = 0;
|
||||
isLoading = true;
|
||||
|
||||
pageSpread: CbxPageSpread | PdfPageSpread = CbxPageSpread.ODD;
|
||||
pageViewMode: CbxPageViewMode | PdfPageViewMode = CbxPageViewMode.SINGLE_PAGE;
|
||||
backgroundColor: CbxBackgroundColor | PdfBackgroundColor = CbxBackgroundColor.GRAY;
|
||||
fitMode: CbxFitMode | PdfFitMode = CbxFitMode.FIT_PAGE;
|
||||
scrollMode: CbxScrollMode | PdfScrollMode = CbxScrollMode.PAGINATED;
|
||||
pageSpread: CbxPageSpread = CbxPageSpread.ODD;
|
||||
pageViewMode: CbxPageViewMode = CbxPageViewMode.SINGLE_PAGE;
|
||||
backgroundColor: CbxBackgroundColor = CbxBackgroundColor.GRAY;
|
||||
fitMode: CbxFitMode = CbxFitMode.FIT_PAGE;
|
||||
scrollMode: CbxScrollMode = CbxScrollMode.PAGINATED;
|
||||
|
||||
private touchStartX = 0;
|
||||
private touchEndX = 0;
|
||||
@@ -110,7 +109,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
|
||||
// Double-tap zoom
|
||||
private lastTapTime = 0;
|
||||
private originalFitMode: CbxFitMode | PdfFitMode | null = null;
|
||||
private originalFitMode: CbxFitMode | null = null;
|
||||
|
||||
// Shortcuts help dialog
|
||||
showShortcutsHelp = false;
|
||||
@@ -124,7 +123,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private cbxReaderService = inject(CbxReaderService);
|
||||
private pdfReaderService = inject(NewPdfReaderService);
|
||||
private bookService = inject(BookService);
|
||||
private userService = inject(UserService);
|
||||
private messageService = inject(MessageService);
|
||||
@@ -141,7 +139,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
protected readonly CbxPageViewMode = CbxPageViewMode;
|
||||
protected readonly CbxPageSpread = CbxPageSpread;
|
||||
|
||||
private static readonly TYPE_PDF = 'PDF';
|
||||
private static readonly TYPE_CBX = 'CBX';
|
||||
private static readonly SETTING_GLOBAL = 'Global';
|
||||
|
||||
@@ -203,9 +200,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
this.loadSeriesNavigationAsync(book);
|
||||
}
|
||||
|
||||
const pagesObservable = this.bookType === CbxReaderComponent.TYPE_PDF
|
||||
? this.pdfReaderService.getAvailablePages(this.bookId, this.altBookType)
|
||||
: this.cbxReaderService.getAvailablePages(this.bookId, this.altBookType);
|
||||
const pagesObservable = this.cbxReaderService.getAvailablePages(this.bookId, this.altBookType);
|
||||
|
||||
pagesObservable.subscribe({
|
||||
next: (pages) => {
|
||||
@@ -239,30 +234,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.bookType === CbxReaderComponent.TYPE_PDF) {
|
||||
const global = userSettings.perBookSetting.pdf === CbxReaderComponent.SETTING_GLOBAL;
|
||||
this.pageViewMode = global
|
||||
? PdfPageViewMode[userSettings.newPdfReaderSetting.pageViewMode as keyof typeof PdfPageViewMode] || PdfPageViewMode.SINGLE_PAGE
|
||||
: PdfPageViewMode[bookSettings.newPdfSettings?.pageViewMode as keyof typeof PdfPageViewMode] || PdfPageViewMode[userSettings.newPdfReaderSetting.pageViewMode as keyof typeof PdfPageViewMode] || PdfPageViewMode.SINGLE_PAGE;
|
||||
|
||||
this.pageSpread = global
|
||||
? PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD
|
||||
: PdfPageSpread[bookSettings.newPdfSettings?.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD;
|
||||
|
||||
this.fitMode = global
|
||||
? PdfFitMode[userSettings.newPdfReaderSetting.fitMode as keyof typeof PdfFitMode] || PdfFitMode.FIT_PAGE
|
||||
: PdfFitMode[bookSettings.newPdfSettings?.fitMode as keyof typeof PdfFitMode] || PdfFitMode[userSettings.newPdfReaderSetting.fitMode as keyof typeof PdfFitMode] || PdfFitMode.FIT_PAGE;
|
||||
|
||||
this.scrollMode = global
|
||||
? PdfScrollMode[userSettings.newPdfReaderSetting.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode.PAGINATED
|
||||
: PdfScrollMode[bookSettings.newPdfSettings?.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode[userSettings.newPdfReaderSetting.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode.PAGINATED;
|
||||
|
||||
this.backgroundColor = global
|
||||
? PdfBackgroundColor[userSettings.newPdfReaderSetting.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor.GRAY
|
||||
: PdfBackgroundColor[bookSettings.newPdfSettings?.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor[userSettings.newPdfReaderSetting.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor.GRAY;
|
||||
|
||||
this.currentPage = (book.pdfProgress?.page || 1) - 1;
|
||||
}
|
||||
this.alignCurrentPageToParity();
|
||||
this.updateServiceStates();
|
||||
this.updateBookmarkState();
|
||||
@@ -610,7 +581,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
get isTwoPageView(): boolean {
|
||||
return this.pageViewMode === this.CbxPageViewMode.TWO_PAGE || this.pageViewMode === PdfPageViewMode.TWO_PAGE;
|
||||
return this.pageViewMode === this.CbxPageViewMode.TWO_PAGE;
|
||||
}
|
||||
|
||||
get hasSeries(): boolean {
|
||||
@@ -688,7 +659,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
private alignCurrentPageToParity() {
|
||||
if (!this.pages.length || !this.isTwoPageView) return;
|
||||
|
||||
const desiredOdd = this.pageSpread === CbxPageSpread.ODD || this.pageSpread === PdfPageSpread.ODD;
|
||||
const desiredOdd = this.pageSpread === CbxPageSpread.ODD;
|
||||
for (let i = this.currentPage; i >= 0; i--) {
|
||||
if ((this.pages[i] % 2 === 1) === desiredOdd) {
|
||||
this.currentPage = i;
|
||||
@@ -813,9 +784,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private getPageImageUrl(pageIndex: number): string {
|
||||
return this.bookType === CbxReaderComponent.TYPE_PDF
|
||||
? this.pdfReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex], this.altBookType)
|
||||
: this.cbxReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex], this.altBookType);
|
||||
return this.cbxReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex], this.altBookType);
|
||||
}
|
||||
|
||||
get infiniteScrollImageUrls(): string[] {
|
||||
@@ -823,25 +792,15 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private updateViewerSetting(): void {
|
||||
const bookSetting: BookSetting = this.bookType === CbxReaderComponent.TYPE_CBX
|
||||
? {
|
||||
cbxSettings: {
|
||||
pageSpread: this.pageSpread as CbxPageSpread,
|
||||
pageViewMode: this.pageViewMode as CbxPageViewMode,
|
||||
fitMode: this.fitMode as CbxFitMode,
|
||||
scrollMode: this.scrollMode as CbxScrollMode,
|
||||
backgroundColor: this.backgroundColor as CbxBackgroundColor,
|
||||
}
|
||||
const bookSetting: BookSetting = {
|
||||
cbxSettings: {
|
||||
pageSpread: this.pageSpread,
|
||||
pageViewMode: this.pageViewMode,
|
||||
fitMode: this.fitMode,
|
||||
scrollMode: this.scrollMode,
|
||||
backgroundColor: this.backgroundColor,
|
||||
}
|
||||
: {
|
||||
newPdfSettings: {
|
||||
pageSpread: this.pageSpread as PdfPageSpread,
|
||||
pageViewMode: this.pageViewMode as PdfPageViewMode,
|
||||
fitMode: this.fitMode as PdfFitMode,
|
||||
scrollMode: this.scrollMode as PdfScrollMode,
|
||||
backgroundColor: this.backgroundColor as PdfBackgroundColor,
|
||||
}
|
||||
};
|
||||
};
|
||||
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
|
||||
}
|
||||
|
||||
@@ -850,12 +809,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10
|
||||
: 0;
|
||||
|
||||
if (this.bookType === CbxReaderComponent.TYPE_CBX) {
|
||||
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage, this.bookFileId).subscribe();
|
||||
}
|
||||
if (this.bookType === CbxReaderComponent.TYPE_PDF) {
|
||||
this.bookService.savePdfProgress(this.bookId, this.currentPage + 1, percentage, this.bookFileId).subscribe();
|
||||
}
|
||||
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage, this.bookFileId).subscribe();
|
||||
}
|
||||
|
||||
private updateSessionProgress(): void {
|
||||
@@ -1049,7 +1003,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
||||
|
||||
private enforcePortraitSinglePageView() {
|
||||
if (this.isPhonePortrait() && this.isTwoPageView) {
|
||||
this.pageViewMode = this.bookType === CbxReaderComponent.TYPE_CBX ? CbxPageViewMode.SINGLE_PAGE : PdfPageViewMode.SINGLE_PAGE;
|
||||
this.pageViewMode = CbxPageViewMode.SINGLE_PAGE;
|
||||
this.quickSettingsService.setPageViewMode(this.pageViewMode);
|
||||
this.footerService.setTwoPageView(false);
|
||||
this.updateViewerSetting();
|
||||
|
||||
+2
-4
@@ -9,9 +9,7 @@ import {
|
||||
CbxPageSpread,
|
||||
CbxBackgroundColor,
|
||||
CbxReadingDirection,
|
||||
CbxSlideshowInterval,
|
||||
PdfPageViewMode,
|
||||
PdfPageSpread
|
||||
CbxSlideshowInterval
|
||||
} from '../../../../settings/user-management/user.service';
|
||||
import {ReaderIconComponent, ReaderIconName} from '../../../ebook-reader/shared/icon.component';
|
||||
import {CbxQuickSettingsService, CbxQuickSettingsState} from './cbx-quick-settings.service';
|
||||
@@ -85,7 +83,7 @@ export class CbxQuickSettingsComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
get isTwoPageView(): boolean {
|
||||
return this.state.pageViewMode === CbxPageViewMode.TWO_PAGE || this.state.pageViewMode === PdfPageViewMode.TWO_PAGE;
|
||||
return this.state.pageViewMode === CbxPageViewMode.TWO_PAGE;
|
||||
}
|
||||
|
||||
get isPaginated(): boolean {
|
||||
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Subject} from 'rxjs';
|
||||
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode} from '../../../../settings/user-management/user.service';
|
||||
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval} from '../../../../settings/user-management/user.service';
|
||||
|
||||
export interface CbxQuickSettingsState {
|
||||
fitMode: CbxFitMode | PdfFitMode;
|
||||
scrollMode: CbxScrollMode | PdfScrollMode;
|
||||
pageViewMode: CbxPageViewMode | PdfPageViewMode;
|
||||
pageSpread: CbxPageSpread | PdfPageSpread;
|
||||
backgroundColor: CbxBackgroundColor | PdfBackgroundColor;
|
||||
fitMode: CbxFitMode;
|
||||
scrollMode: CbxScrollMode;
|
||||
pageViewMode: CbxPageViewMode;
|
||||
pageSpread: CbxPageSpread;
|
||||
backgroundColor: CbxBackgroundColor;
|
||||
readingDirection: CbxReadingDirection;
|
||||
slideshowInterval: CbxSlideshowInterval;
|
||||
}
|
||||
@@ -77,11 +77,11 @@ export class CbxQuickSettingsService {
|
||||
this.updateState({scrollMode: mode});
|
||||
}
|
||||
|
||||
setPageViewMode(mode: CbxPageViewMode | PdfPageViewMode): void {
|
||||
setPageViewMode(mode: CbxPageViewMode): void {
|
||||
this.updateState({pageViewMode: mode});
|
||||
}
|
||||
|
||||
setPageSpread(spread: CbxPageSpread | PdfPageSpread): void {
|
||||
setPageSpread(spread: CbxPageSpread): void {
|
||||
this.updateState({pageSpread: spread});
|
||||
}
|
||||
|
||||
|
||||
+17
-52
@@ -50,59 +50,24 @@
|
||||
<div class="content">
|
||||
@switch (activeTab) {
|
||||
@case ('pages') {
|
||||
@if (isPdf && hasOutline) {
|
||||
<ul class="outline-list">
|
||||
<ng-container *ngTemplateOutlet="outlineTemplate; context: { items: pdfOutline, depth: 0 }"></ng-container>
|
||||
</ul>
|
||||
|
||||
<ng-template #outlineTemplate let-items="items" let-depth="depth">
|
||||
@for (item of items; track item.title + item.pageNumber) {
|
||||
<li class="outline-item">
|
||||
<button
|
||||
class="outline-row"
|
||||
[class.active]="isOutlineItemActive(item, items)"
|
||||
[class.has-children]="item.children && item.children.length > 0"
|
||||
[style.padding-left.px]="16 + depth * 16"
|
||||
(click)="onOutlineItemClick(item)">
|
||||
@if (item.children && item.children.length > 0) {
|
||||
<span
|
||||
class="expand-icon"
|
||||
[class.expanded]="isOutlineItemExpanded(item)"
|
||||
(click)="toggleOutlineItem(item); $event.stopPropagation()">
|
||||
<app-reader-icon name="chevron-right" [size]="14"></app-reader-icon>
|
||||
</span>
|
||||
}
|
||||
<span class="outline-title">{{ item.title }}</span>
|
||||
<span class="outline-page">{{ item.pageNumber }}</span>
|
||||
</button>
|
||||
@if (item.children && item.children.length > 0 && isOutlineItemExpanded(item)) {
|
||||
<ul class="outline-children">
|
||||
<ng-container *ngTemplateOutlet="outlineTemplate; context: { items: item.children, depth: depth + 1 }"></ng-container>
|
||||
</ul>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ng-template>
|
||||
} @else {
|
||||
<ul class="page-list">
|
||||
@for (page of pages; track page.pageNumber) {
|
||||
<li>
|
||||
<button
|
||||
class="page-row"
|
||||
[class.active]="isPageActive(page.pageNumber)"
|
||||
(click)="onPageClick(page.pageNumber)">
|
||||
<span class="page-number">{{ page.pageNumber }}</span>
|
||||
<span class="page-label">{{ page.displayName }}</span>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@if (pages.length === 0 && !hasOutline) {
|
||||
<div class="empty-state">
|
||||
<app-reader-icon name="book" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
|
||||
<p>No pages found</p>
|
||||
</div>
|
||||
<ul class="page-list">
|
||||
@for (page of pages; track page.pageNumber) {
|
||||
<li>
|
||||
<button
|
||||
class="page-row"
|
||||
[class.active]="isPageActive(page.pageNumber)"
|
||||
(click)="onPageClick(page.pageNumber)">
|
||||
<span class="page-number">{{ page.pageNumber }}</span>
|
||||
<span class="page-label">{{ page.displayName }}</span>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
@if (pages.length === 0) {
|
||||
<div class="empty-state">
|
||||
<app-reader-icon name="book" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
|
||||
<p>No pages found</p>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@case ('bookmarks') {
|
||||
|
||||
+1
-88
@@ -5,7 +5,6 @@ import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {CbxSidebarService, CbxSidebarTab, SidebarBookInfo} from './cbx-sidebar.service';
|
||||
import {CbxPageInfo} from '../../../../book/service/cbx-reader.service';
|
||||
import {PdfOutlineItem} from '../../../../book/service/new-pdf-reader.service';
|
||||
import {BookMark} from '../../../../../shared/service/book-mark.service';
|
||||
import {BookNoteV2} from '../../../../../shared/service/book-note-v2.service';
|
||||
import {ReaderIconComponent} from '../../../ebook-reader';
|
||||
@@ -26,9 +25,6 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
|
||||
activeTab: CbxSidebarTab = 'pages';
|
||||
bookInfo: SidebarBookInfo = { id: null, title: '', authors: '', coverUrl: null };
|
||||
pages: CbxPageInfo[] = [];
|
||||
pdfOutline: PdfOutlineItem[] | null = null;
|
||||
pdfPageCount = 0;
|
||||
expandedOutlineItems = new Set<string>();
|
||||
currentPage = 1;
|
||||
bookmarks: BookMark[] = [];
|
||||
notes: BookNoteV2[] = [];
|
||||
@@ -58,23 +54,9 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(pages => this.pages = pages);
|
||||
|
||||
this.sidebarService.pdfOutline$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(outline => {
|
||||
this.pdfOutline = outline;
|
||||
this.autoExpandToCurrentPage();
|
||||
});
|
||||
|
||||
this.sidebarService.pdfPageCount$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(count => this.pdfPageCount = count);
|
||||
|
||||
this.sidebarService.currentPage$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(page => {
|
||||
this.currentPage = page;
|
||||
this.autoExpandToCurrentPage();
|
||||
});
|
||||
.subscribe(page => this.currentPage = page);
|
||||
|
||||
this.sidebarService.bookmarks$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
@@ -114,75 +96,6 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
|
||||
return this.currentPage === pageNumber;
|
||||
}
|
||||
|
||||
get isPdf(): boolean {
|
||||
return this.sidebarService.isPdf;
|
||||
}
|
||||
|
||||
get hasOutline(): boolean {
|
||||
return this.pdfOutline !== null && this.pdfOutline.length > 0;
|
||||
}
|
||||
|
||||
toggleOutlineItem(item: PdfOutlineItem): void {
|
||||
const key = `${item.title}-${item.pageNumber}`;
|
||||
if (this.expandedOutlineItems.has(key)) {
|
||||
this.expandedOutlineItems.delete(key);
|
||||
} else {
|
||||
this.expandedOutlineItems.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
isOutlineItemExpanded(item: PdfOutlineItem): boolean {
|
||||
const key = `${item.title}-${item.pageNumber}`;
|
||||
return this.expandedOutlineItems.has(key);
|
||||
}
|
||||
|
||||
onOutlineItemClick(item: PdfOutlineItem): void {
|
||||
this.sidebarService.navigateToPage(item.pageNumber);
|
||||
}
|
||||
|
||||
isOutlineItemActive(item: PdfOutlineItem, siblings: PdfOutlineItem[] | null): boolean {
|
||||
if (!siblings) return this.currentPage >= item.pageNumber;
|
||||
|
||||
const itemIndex = siblings.findIndex(s => s.title === item.title && s.pageNumber === item.pageNumber);
|
||||
const nextSibling = siblings[itemIndex + 1];
|
||||
|
||||
if (nextSibling) {
|
||||
return this.currentPage >= item.pageNumber && this.currentPage < nextSibling.pageNumber;
|
||||
} else {
|
||||
return this.currentPage >= item.pageNumber;
|
||||
}
|
||||
}
|
||||
|
||||
hasActiveChild(item: PdfOutlineItem): boolean {
|
||||
if (!item.children || item.children.length === 0) return false;
|
||||
|
||||
return item.children.some((child, index) => {
|
||||
if (this.isOutlineItemActive(child, item.children)) return true;
|
||||
if (this.hasActiveChild(child)) return true;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private autoExpandToCurrentPage(): void {
|
||||
if (!this.pdfOutline) return;
|
||||
|
||||
const expandParents = (items: PdfOutlineItem[] | null): void => {
|
||||
if (!items) return;
|
||||
|
||||
for (const item of items) {
|
||||
if (item.children && item.children.length > 0) {
|
||||
if (this.hasActiveChild(item) || this.isOutlineItemActive(item, items)) {
|
||||
const key = `${item.title}-${item.pageNumber}`;
|
||||
this.expandedOutlineItems.add(key);
|
||||
}
|
||||
expandParents(item.children);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
expandParents(this.pdfOutline);
|
||||
}
|
||||
|
||||
onBookmarkClick(cfi: string): void {
|
||||
this.sidebarService.navigateToBookmark(cfi);
|
||||
}
|
||||
|
||||
+4
-32
@@ -2,9 +2,8 @@ import {inject, Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {CbxPageInfo, CbxReaderService} from '../../../../book/service/cbx-reader.service';
|
||||
import {NewPdfReaderService, PdfOutlineItem} from '../../../../book/service/new-pdf-reader.service';
|
||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||
import {Book, BookType} from '../../../../book/model/book.model';
|
||||
import {Book} from '../../../../book/model/book.model';
|
||||
import {BookMark, BookMarkService, CreateBookMarkRequest} from '../../../../../shared/service/book-mark.service';
|
||||
import {BookNoteV2, BookNoteV2Service, CreateBookNoteV2Request, UpdateBookNoteV2Request} from '../../../../../shared/service/book-note-v2.service';
|
||||
|
||||
@@ -21,14 +20,12 @@ export type CbxSidebarTab = 'pages' | 'bookmarks' | 'notes';
|
||||
export class CbxSidebarService {
|
||||
private urlHelper = inject(UrlHelperService);
|
||||
private cbxReaderService = inject(CbxReaderService);
|
||||
private pdfReaderService = inject(NewPdfReaderService);
|
||||
private bookMarkService = inject(BookMarkService);
|
||||
private bookNoteV2Service = inject(BookNoteV2Service);
|
||||
|
||||
private destroy$ = new Subject<void>();
|
||||
private bookId!: number;
|
||||
private altBookType?: string;
|
||||
private bookType!: BookType;
|
||||
|
||||
private _isOpen = new BehaviorSubject<boolean>(false);
|
||||
private _activeTab = new BehaviorSubject<CbxSidebarTab>('pages');
|
||||
@@ -39,8 +36,6 @@ export class CbxSidebarService {
|
||||
coverUrl: null
|
||||
});
|
||||
private _pages = new BehaviorSubject<CbxPageInfo[]>([]);
|
||||
private _pdfOutline = new BehaviorSubject<PdfOutlineItem[] | null>(null);
|
||||
private _pdfPageCount = new BehaviorSubject<number>(0);
|
||||
private _currentPage = new BehaviorSubject<number>(1);
|
||||
private _bookmarks = new BehaviorSubject<BookMark[]>([]);
|
||||
private _notes = new BehaviorSubject<BookNoteV2[]>([]);
|
||||
@@ -54,8 +49,6 @@ export class CbxSidebarService {
|
||||
activeTab$ = this._activeTab.asObservable();
|
||||
bookInfo$ = this._bookInfo.asObservable();
|
||||
pages$ = this._pages.asObservable();
|
||||
pdfOutline$ = this._pdfOutline.asObservable();
|
||||
pdfPageCount$ = this._pdfPageCount.asObservable();
|
||||
currentPage$ = this._currentPage.asObservable();
|
||||
bookmarks$ = this._bookmarks.asObservable();
|
||||
notes$ = this._notes.asObservable();
|
||||
@@ -63,14 +56,9 @@ export class CbxSidebarService {
|
||||
editNote$ = this._editNote.asObservable();
|
||||
bookmarksChanged$ = this._bookmarksChanged.asObservable();
|
||||
|
||||
get isPdf(): boolean {
|
||||
return this.bookType === 'PDF';
|
||||
}
|
||||
|
||||
initialize(bookId: number, book: Book, destroy$: Subject<void>, altBookType?: string): void {
|
||||
this.bookId = bookId;
|
||||
this.altBookType = altBookType;
|
||||
this.bookType = (altBookType as BookType) ?? book.primaryFile?.bookType!;
|
||||
this.destroy$ = destroy$;
|
||||
|
||||
this._bookInfo.next({
|
||||
@@ -86,25 +74,9 @@ export class CbxSidebarService {
|
||||
}
|
||||
|
||||
private loadPageInfo(): void {
|
||||
if (this.bookType === 'PDF') {
|
||||
this.pdfReaderService.getPageInfo(this.bookId, this.altBookType)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(pdfInfo => {
|
||||
this._pdfPageCount.next(pdfInfo.pageCount);
|
||||
this._pdfOutline.next(pdfInfo.outline);
|
||||
if (!pdfInfo.outline || pdfInfo.outline.length === 0) {
|
||||
const pages: CbxPageInfo[] = [];
|
||||
for (let i = 1; i <= pdfInfo.pageCount; i++) {
|
||||
pages.push({pageNumber: i, displayName: `Page ${i}`});
|
||||
}
|
||||
this._pages.next(pages);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.cbxReaderService.getPageInfo(this.bookId, this.altBookType)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(pages => this._pages.next(pages));
|
||||
}
|
||||
this.cbxReaderService.getPageInfo(this.bookId, this.altBookType)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(pages => this._pages.next(pages));
|
||||
}
|
||||
|
||||
private loadBookmarks(): void {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
@if (!isLoading) {
|
||||
<ngx-extended-pdf-viewer
|
||||
[src]="bookData"
|
||||
[authorization]="authorization"
|
||||
[textLayer]="true"
|
||||
[showHandToolButton]="true"
|
||||
[height]="'auto'"
|
||||
@@ -19,7 +20,8 @@
|
||||
(pagesLoaded)="onPdfPagesLoaded($event)"
|
||||
(pageChange)="onPageChange($event)"
|
||||
(zoomChange)="onZoomChange($event)"
|
||||
(spreadChange)="onSpreadChange($event)">
|
||||
(spreadChange)="onSpreadChange($event)"
|
||||
(annotationEditorEvent)="onAnnotationEditorEvent()">
|
||||
</ngx-extended-pdf-viewer>
|
||||
|
||||
<ng-template #additionalButtons>
|
||||
@@ -47,6 +49,10 @@
|
||||
<div class="verticalToolbarSeparator hiddenSmallView"></div>
|
||||
<pdf-toggle-secondary-toolbar></pdf-toggle-secondary-toolbar>
|
||||
<div class="verticalToolbarSeparator"></div>
|
||||
<pdf-highlight-editor></pdf-highlight-editor>
|
||||
<pdf-text-editor></pdf-text-editor>
|
||||
<pdf-draw-editor></pdf-draw-editor>
|
||||
<div class="verticalToolbarSeparator"></div>
|
||||
<button class="toolbar-btn" [title]="isDarkTheme ? 'Switch to Light Mode' : 'Switch to Dark Mode'" (click)="isDarkTheme = !isDarkTheme">
|
||||
@if (isDarkTheme) {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {NgxExtendedPdfViewerModule, ZoomType} from 'ngx-extended-pdf-viewer';
|
||||
import {NgxExtendedPdfViewerModule, NgxExtendedPdfViewerService, pdfDefaultOptions, ZoomType} from 'ngx-extended-pdf-viewer';
|
||||
import {PageTitleService} from "../../../shared/service/page-title.service";
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {forkJoin, Subscription} from 'rxjs';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {forkJoin, Subject, Subscription} from 'rxjs';
|
||||
import {debounceTime, map, switchMap} from 'rxjs/operators';
|
||||
import {BookSetting} from '../../book/model/book.model';
|
||||
import {UserService} from '../../settings/user-management/user.service';
|
||||
import {AuthService} from '../../../shared/service/auth.service';
|
||||
import {API_CONFIG} from '../../../core/config/api-config';
|
||||
import {PdfAnnotationService} from '../../../shared/service/pdf-annotation.service';
|
||||
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {MessageService} from 'primeng/api';
|
||||
@@ -21,47 +24,61 @@ import {Location} from '@angular/common';
|
||||
styleUrl: './pdf-reader.component.scss',
|
||||
})
|
||||
export class PdfReaderComponent implements OnInit, OnDestroy {
|
||||
constructor() {
|
||||
pdfDefaultOptions.rangeChunkSize = 512 * 1024;
|
||||
pdfDefaultOptions.disableAutoFetch = true;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
totalPages: number = 0;
|
||||
isDarkTheme = true;
|
||||
|
||||
rotation: 0 | 90 | 180 | 270 = 0;
|
||||
authorization = '';
|
||||
|
||||
page!: number;
|
||||
spread!: 'off' | 'even' | 'odd';
|
||||
zoom!: ZoomType;
|
||||
|
||||
bookData!: string | Blob;
|
||||
bookData!: string;
|
||||
bookId!: number;
|
||||
bookFileId?: number;
|
||||
private appSettingsSubscription!: Subscription;
|
||||
private annotationSaveSubject = new Subject<void>();
|
||||
private annotationSaveSubscription!: Subscription;
|
||||
private annotationsLoaded = false;
|
||||
|
||||
private bookService = inject(BookService);
|
||||
private userService = inject(UserService);
|
||||
private authService = inject(AuthService);
|
||||
private messageService = inject(MessageService);
|
||||
private route = inject(ActivatedRoute);
|
||||
private pageTitle = inject(PageTitleService);
|
||||
private readingSessionService = inject(ReadingSessionService);
|
||||
private location = inject(Location);
|
||||
private pdfViewerService = inject(NgxExtendedPdfViewerService);
|
||||
private pdfAnnotationService = inject(PdfAnnotationService);
|
||||
|
||||
ngOnInit(): void {
|
||||
this.annotationSaveSubscription = this.annotationSaveSubject
|
||||
.pipe(debounceTime(1500))
|
||||
.subscribe(() => this.persistAnnotations());
|
||||
|
||||
this.route.paramMap.subscribe((params) => {
|
||||
this.isLoading = true;
|
||||
this.bookId = +params.get('bookId')!;
|
||||
|
||||
this.bookService.getBookByIdFromAPI(this.bookId, false).pipe(
|
||||
switchMap((book) => {
|
||||
// Set the book file ID for progress tracking
|
||||
this.bookFileId = book.primaryFile?.id;
|
||||
|
||||
return forkJoin([
|
||||
this.bookService.getBookSetting(this.bookId, this.bookFileId!),
|
||||
this.bookService.getFileContent(this.bookId),
|
||||
this.userService.getMyself()
|
||||
]).pipe(map(([bookSetting, pdfData, myself]) => ({ book, bookSetting, pdfData, myself })));
|
||||
]).pipe(map(([bookSetting, myself]) => ({book, bookSetting, myself})));
|
||||
})
|
||||
).subscribe({
|
||||
next: ({ book, bookSetting, pdfData, myself }) => {
|
||||
next: ({book, bookSetting, myself}) => {
|
||||
const pdfMeta = book;
|
||||
const pdfPrefs = bookSetting;
|
||||
|
||||
@@ -76,7 +93,9 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
|
||||
this.spread = pdfPrefs.pdfSettings?.spread || myself.userSettings.pdfReaderSetting.pageSpread || 'odd';
|
||||
}
|
||||
this.page = pdfMeta.pdfProgress?.page || 1;
|
||||
this.bookData = pdfData;
|
||||
this.bookData = `${API_CONFIG.BASE_URL}/api/v1/books/${this.bookId}/content`;
|
||||
const token = this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
|
||||
this.authorization = token ? `Bearer ${token}` : '';
|
||||
this.isLoading = false;
|
||||
},
|
||||
error: () => {
|
||||
@@ -130,6 +149,13 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
|
||||
const percentage = this.totalPages > 0 ? Math.round((this.page / this.totalPages) * 1000) / 10 : 0;
|
||||
this.readingSessionService.startSession(this.bookId, "PDF", this.page.toString(), percentage);
|
||||
this.readingSessionService.updateProgress(this.page.toString(), percentage);
|
||||
this.loadAnnotations();
|
||||
}
|
||||
|
||||
onAnnotationEditorEvent(): void {
|
||||
if (this.annotationsLoaded) {
|
||||
this.annotationSaveSubject.next();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
@@ -138,6 +164,9 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
|
||||
this.readingSessionService.endSession(this.page.toString(), percentage);
|
||||
}
|
||||
|
||||
this.annotationSaveSubscription?.unsubscribe();
|
||||
this.persistAnnotations();
|
||||
|
||||
if (this.appSettingsSubscription) {
|
||||
this.appSettingsSubscription.unsubscribe();
|
||||
}
|
||||
@@ -151,4 +180,33 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
this.location.back();
|
||||
}
|
||||
|
||||
private loadAnnotations(): void {
|
||||
this.pdfAnnotationService.getAnnotations(this.bookId).subscribe({
|
||||
next: (response) => {
|
||||
if (response?.data) {
|
||||
const annotations = JSON.parse(response.data);
|
||||
for (const annotation of annotations) {
|
||||
this.pdfViewerService.addEditorAnnotation(annotation);
|
||||
}
|
||||
}
|
||||
this.annotationsLoaded = true;
|
||||
},
|
||||
error: () => {
|
||||
this.annotationsLoaded = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private persistAnnotations(): void {
|
||||
if (!this.annotationsLoaded || !this.bookId) {
|
||||
return;
|
||||
}
|
||||
const serialized = this.pdfViewerService.getSerializedAnnotations();
|
||||
if (serialized && serialized.length > 0) {
|
||||
const cleaned = serialized.map(({id, ...rest}: any) => rest);
|
||||
const data = JSON.stringify(cleaned);
|
||||
this.pdfAnnotationService.saveAnnotations(this.bookId, data).subscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
<ng-container *transloco="let t; prefix: 'settingsReader.streamingPdf'">
|
||||
<div class="pdf-preferences-container">
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('pageSpread') }}</label>
|
||||
<div class="button-group">
|
||||
@for (spread of pdfSpreads; track spread) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedPdfSpread === spread.key"
|
||||
(click)="selectedPdfSpread = spread.key">
|
||||
<i [class]="spread.icon"></i>
|
||||
<span class="option-text">{{ t(spread.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('pageSpreadDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('pageLayout') }}</label>
|
||||
<div class="button-group">
|
||||
@for (mode of pdfViewModes; track mode) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedPdfViewMode === mode.key"
|
||||
(click)="selectedPdfViewMode = mode.key">
|
||||
<i [class]="mode.icon"></i>
|
||||
<span class="option-text">{{ t(mode.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('pageLayoutDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('fitMode') }}</label>
|
||||
<div class="button-group">
|
||||
@for (mode of pdfFitModes; track mode) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedPdfFitMode === mode.key"
|
||||
(click)="selectedPdfFitMode = mode.key"
|
||||
[pTooltip]="t(mode.translationKey)"
|
||||
tooltipPosition="bottom">
|
||||
<i [class]="mode.icon"></i>
|
||||
<span class="option-text">{{ t(mode.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('fitModeDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('scrollMode') }}</label>
|
||||
<div class="button-group">
|
||||
@for (mode of pdfScrollModes; track mode) {
|
||||
<button
|
||||
type="button"
|
||||
class="option-button"
|
||||
[class.selected]="selectedPdfScrollMode === mode.key"
|
||||
(click)="selectedPdfScrollMode = mode.key">
|
||||
<i [class]="mode.icon"></i>
|
||||
<span class="option-text">{{ t(mode.translationKey) }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('scrollModeDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-item">
|
||||
<div class="setting-info">
|
||||
<div class="setting-label-row">
|
||||
<label class="setting-label">{{ t('backgroundColor') }}</label>
|
||||
<div class="theme-selector">
|
||||
@for (color of pdfBackgroundColors; track color) {
|
||||
<button
|
||||
type="button"
|
||||
class="theme-option"
|
||||
[class.selected]="selectedPdfBackgroundColor === color.key"
|
||||
[style.background-color]="color.color"
|
||||
(click)="selectedPdfBackgroundColor = color.key"
|
||||
[attr.aria-label]="t(color.translationKey)"
|
||||
[pTooltip]="t(color.translationKey)"
|
||||
tooltipPosition="bottom">
|
||||
@if (selectedPdfBackgroundColor === color.key) {
|
||||
<i class="pi pi-check"></i>
|
||||
}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<p class="setting-description">
|
||||
{{ t('backgroundColorDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-container>
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
@use '../../../../shared/styles/settings-shared' as settings;
|
||||
|
||||
.pdf-preferences-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 2rem;
|
||||
padding: 0.25rem 0;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.setting-label {
|
||||
display: block;
|
||||
font-weight: settings.$settings-section-title-weight;
|
||||
color: var(--p-text-color);
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.setting-label-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-label {
|
||||
margin-bottom: 0;
|
||||
flex-shrink: 0;
|
||||
min-width: 100px;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-description {
|
||||
color: var(--p-text-muted-color);
|
||||
font-size: settings.$settings-section-description-size;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.button-group {
|
||||
@include settings.settings-button-group;
|
||||
}
|
||||
|
||||
.theme-selector {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.theme-option {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
border-radius: 0.375rem;
|
||||
border: 1.5px solid transparent;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
i {
|
||||
color: white;
|
||||
font-size: settings.$settings-section-description-size;
|
||||
font-weight: bold;
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: var(--primary-color);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 25%, transparent);
|
||||
}
|
||||
}
|
||||
}
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode, UserSettings} from '../../user-management/user.service';
|
||||
import {ReaderPreferencesService} from '../reader-preferences.service';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
|
||||
@Component({
|
||||
selector: 'app-new-pdf-reader-preferences-component',
|
||||
imports: [
|
||||
FormsModule,
|
||||
TranslocoDirective,
|
||||
TooltipModule
|
||||
],
|
||||
templateUrl: './new-pdf-reader-preferences-component.html',
|
||||
styleUrl: './new-pdf-reader-preferences-component.scss'
|
||||
})
|
||||
export class NewPdfReaderPreferencesComponent {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
private static readonly SETTING_ROOT = 'newPdfReaderSetting';
|
||||
private static readonly PROP_PAGE_SPREAD = 'pageSpread';
|
||||
private static readonly PROP_PAGE_VIEW_MODE = 'pageViewMode';
|
||||
private static readonly PROP_FIT_MODE = 'fitMode';
|
||||
private static readonly PROP_SCROLL_MODE = 'scrollMode';
|
||||
private static readonly PROP_BACKGROUND_COLOR = 'backgroundColor';
|
||||
|
||||
readonly pdfSpreads = [
|
||||
{name: 'Even', key: PdfPageSpread.EVEN, icon: 'pi pi-align-left', translationKey: 'even'},
|
||||
{name: 'Odd', key: PdfPageSpread.ODD, icon: 'pi pi-align-right', translationKey: 'odd'}
|
||||
];
|
||||
|
||||
readonly pdfViewModes = [
|
||||
{name: 'Single Page', key: PdfPageViewMode.SINGLE_PAGE, icon: 'pi pi-book', translationKey: 'singlePage'},
|
||||
{name: 'Two Page', key: PdfPageViewMode.TWO_PAGE, icon: 'pi pi-copy', translationKey: 'twoPage'},
|
||||
];
|
||||
|
||||
readonly pdfFitModes = [
|
||||
{name: 'Fit Page', key: PdfFitMode.FIT_PAGE, icon: 'pi pi-window-maximize', translationKey: 'fitPage'},
|
||||
{name: 'Fit Width', key: PdfFitMode.FIT_WIDTH, icon: 'pi pi-arrows-h', translationKey: 'fitWidth'},
|
||||
{name: 'Fit Height', key: PdfFitMode.FIT_HEIGHT, icon: 'pi pi-arrows-v', translationKey: 'fitHeight'},
|
||||
{name: 'Actual Size', key: PdfFitMode.ACTUAL_SIZE, icon: 'pi pi-expand', translationKey: 'actualSize'},
|
||||
{name: 'Automatic', key: PdfFitMode.AUTO, icon: 'pi pi-sparkles', translationKey: 'automatic'}
|
||||
];
|
||||
|
||||
readonly pdfScrollModes = [
|
||||
{name: 'Paginated', key: PdfScrollMode.PAGINATED, icon: 'pi pi-book', translationKey: 'paginated'},
|
||||
{name: 'Infinite', key: PdfScrollMode.INFINITE, icon: 'pi pi-sort-alt', translationKey: 'infinite'}
|
||||
];
|
||||
|
||||
readonly pdfBackgroundColors = [
|
||||
{name: 'Gray', key: PdfBackgroundColor.GRAY, color: '#808080', translationKey: 'gray'},
|
||||
{name: 'Black', key: PdfBackgroundColor.BLACK, color: '#000000', translationKey: 'black'},
|
||||
{name: 'White', key: PdfBackgroundColor.WHITE, color: '#FFFFFF', translationKey: 'white'}
|
||||
];
|
||||
|
||||
get selectedPdfSpread(): PdfPageSpread {
|
||||
return this.userSettings.newPdfReaderSetting.pageSpread ?? PdfPageSpread.EVEN;
|
||||
}
|
||||
|
||||
set selectedPdfSpread(value: PdfPageSpread) {
|
||||
this.userSettings.newPdfReaderSetting.pageSpread = value;
|
||||
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_PAGE_SPREAD], value);
|
||||
}
|
||||
|
||||
get selectedPdfViewMode(): PdfPageViewMode {
|
||||
return this.userSettings.newPdfReaderSetting.pageViewMode ?? PdfPageViewMode.SINGLE_PAGE;
|
||||
}
|
||||
|
||||
set selectedPdfViewMode(value: PdfPageViewMode) {
|
||||
this.userSettings.newPdfReaderSetting.pageViewMode = value;
|
||||
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_PAGE_VIEW_MODE], value);
|
||||
}
|
||||
|
||||
get selectedPdfFitMode(): PdfFitMode {
|
||||
return this.userSettings.newPdfReaderSetting.fitMode ?? PdfFitMode.FIT_PAGE;
|
||||
}
|
||||
|
||||
set selectedPdfFitMode(value: PdfFitMode) {
|
||||
this.userSettings.newPdfReaderSetting.fitMode = value;
|
||||
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_FIT_MODE], value);
|
||||
}
|
||||
|
||||
get selectedPdfScrollMode(): PdfScrollMode {
|
||||
return this.userSettings.newPdfReaderSetting.scrollMode ?? PdfScrollMode.PAGINATED;
|
||||
}
|
||||
|
||||
set selectedPdfScrollMode(value: PdfScrollMode) {
|
||||
this.userSettings.newPdfReaderSetting.scrollMode = value;
|
||||
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_SCROLL_MODE], value);
|
||||
}
|
||||
|
||||
get selectedPdfBackgroundColor(): PdfBackgroundColor {
|
||||
return this.userSettings.newPdfReaderSetting.backgroundColor ?? PdfBackgroundColor.GRAY;
|
||||
}
|
||||
|
||||
set selectedPdfBackgroundColor(value: PdfBackgroundColor) {
|
||||
this.userSettings.newPdfReaderSetting.backgroundColor = value;
|
||||
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_BACKGROUND_COLOR], value);
|
||||
}
|
||||
}
|
||||
-18
@@ -67,24 +67,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">
|
||||
<i class="pi pi-file-pdf"></i>
|
||||
{{ t('streamingPdf.sectionTitle') }}
|
||||
</h3>
|
||||
<p class="section-description">
|
||||
{{ t('streamingPdf.sectionDesc') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-card">
|
||||
<app-new-pdf-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-new-pdf-reader-preferences-component>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (hasFontManagementPermission) {
|
||||
<div class="preferences-section">
|
||||
<div class="section-header">
|
||||
|
||||
+1
-2
@@ -11,7 +11,6 @@ import {EpubReaderPreferencesComponent} from './epub-reader-preferences/epub-rea
|
||||
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences/pdf-reader-preferences-component';
|
||||
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences/cbx-reader-preferences-component';
|
||||
import {CustomFontsComponent} from '../custom-fonts/custom-fonts.component';
|
||||
import {NewPdfReaderPreferencesComponent} from './new-pdf-reader-preferences/new-pdf-reader-preferences-component';
|
||||
import {SettingsApplicationModeComponent} from './settings-application-mode/settings-application-mode.component';
|
||||
|
||||
@Component({
|
||||
@@ -19,7 +18,7 @@ import {SettingsApplicationModeComponent} from './settings-application-mode/sett
|
||||
templateUrl: './reader-preferences.component.html',
|
||||
standalone: true,
|
||||
styleUrls: ['./reader-preferences.component.scss'],
|
||||
imports: [FormsModule, TooltipModule, TranslocoDirective, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent, CustomFontsComponent, NewPdfReaderPreferencesComponent, SettingsApplicationModeComponent]
|
||||
imports: [FormsModule, TooltipModule, TranslocoDirective, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent, CustomFontsComponent, SettingsApplicationModeComponent]
|
||||
})
|
||||
export class ReaderPreferences implements OnInit, OnDestroy {
|
||||
private readonly userService = inject(UserService);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class PdfAnnotationService {
|
||||
|
||||
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/pdf-annotations`;
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
getAnnotations(bookId: number): Observable<{ data: string }> {
|
||||
return this.http.get<{ data: string }>(`${this.url}/book/${bookId}`);
|
||||
}
|
||||
|
||||
saveAnnotations(bookId: number, data: string): Observable<void> {
|
||||
return this.http.put<void>(`${this.url}/book/${bookId}`, {data});
|
||||
}
|
||||
|
||||
deleteAnnotations(bookId: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.url}/book/${bookId}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user