refactor(epub): use archiveservice instead of epub4j to read archive (#2066)
This commit is contained in:
@@ -11,11 +11,11 @@ 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.service.ArchiveService;
|
||||
import org.booklore.util.FileUtils;
|
||||
import org.grimmory.epub4j.domain.*;
|
||||
import org.grimmory.epub4j.epub.CoverDetector;
|
||||
import org.grimmory.epub4j.epub.EpubReader;
|
||||
import org.grimmory.epub4j.native_parsing.NativeArchive;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.*;
|
||||
@@ -73,6 +73,7 @@ public class EpubReaderService {
|
||||
.maximumSize(MAX_CACHE_ENTRIES)
|
||||
.expireAfterAccess(Duration.ofMinutes(30))
|
||||
.build();
|
||||
private final ArchiveService archiveService;
|
||||
|
||||
private record CachedEpubMetadata(EpubBookInfo bookInfo, long lastModified,
|
||||
Set<String> validPaths,
|
||||
@@ -380,9 +381,7 @@ public class EpubReaderService {
|
||||
}
|
||||
|
||||
private void streamEntryFromZip(Path epubPath, String entryName, OutputStream outputStream) throws IOException {
|
||||
try (NativeArchive archive = NativeArchive.open(epubPath)) {
|
||||
archive.streamEntry(entryName, outputStream);
|
||||
}
|
||||
archiveService.transferEntryTo(epubPath, entryName, outputStream);
|
||||
}
|
||||
|
||||
private String guessContentType(String path) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.booklore.model.dto.response.EpubSpineItem;
|
||||
import org.booklore.model.dto.response.EpubTocItem;
|
||||
import org.booklore.model.entity.BookEntity;
|
||||
import org.booklore.repository.BookRepository;
|
||||
import org.booklore.service.ArchiveService;
|
||||
import org.booklore.util.FileUtils;
|
||||
import org.grimmory.epub4j.domain.*;
|
||||
import org.grimmory.epub4j.epub.EpubWriter;
|
||||
@@ -17,6 +18,7 @@ import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
@@ -40,6 +42,9 @@ class EpubReaderServiceTest {
|
||||
@Mock
|
||||
BookRepository bookRepository;
|
||||
|
||||
@Spy
|
||||
ArchiveService archiveService = new ArchiveService();
|
||||
|
||||
@InjectMocks
|
||||
EpubReaderService epubReaderService;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user