Revamp the CBX reader layout for improved structure and usability (#2330)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+8
@@ -1,5 +1,6 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.response.CbxPageInfo;
|
||||
import com.adityachandel.booklore.service.reader.CbxReaderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -27,4 +28,11 @@ public class CbxReaderController {
|
||||
public List<Integer> listPages(@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
return cbxReaderService.getAvailablePages(bookId);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get page info for a CBX book", description = "Retrieve page information including display names for a CBX book.")
|
||||
@ApiResponse(responseCode = "200", description = "Page info returned successfully")
|
||||
@GetMapping("/{bookId}/page-info")
|
||||
public List<CbxPageInfo> getPageInfo(@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
return cbxReaderService.getPageInfo(bookId);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.adityachandel.booklore.model.dto.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CbxPageInfo {
|
||||
private int pageNumber;
|
||||
private String displayName;
|
||||
}
|
||||
+31
@@ -14,6 +14,8 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.pdfbox.io.IOUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.response.CbxPageInfo;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -80,6 +82,35 @@ public class CbxReaderService {
|
||||
}
|
||||
}
|
||||
|
||||
public List<CbxPageInfo> getPageInfo(Long bookId) {
|
||||
Path cbxPath = getBookPath(bookId);
|
||||
try {
|
||||
List<String> imageEntries = getImageEntriesFromArchiveCached(cbxPath);
|
||||
List<CbxPageInfo> pageInfoList = new ArrayList<>();
|
||||
for (int i = 0; i < imageEntries.size(); i++) {
|
||||
String entryPath = imageEntries.get(i);
|
||||
String displayName = extractDisplayName(entryPath);
|
||||
pageInfoList.add(CbxPageInfo.builder()
|
||||
.pageNumber(i + 1)
|
||||
.displayName(displayName)
|
||||
.build());
|
||||
}
|
||||
return pageInfoList;
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to read archive for book {}", bookId, e);
|
||||
throw ApiError.FILE_READ_ERROR.createException("Failed to read archive: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String extractDisplayName(String entryPath) {
|
||||
String fileName = baseName(entryPath);
|
||||
int lastDotIndex = fileName.lastIndexOf('.');
|
||||
if (lastDotIndex > 0) {
|
||||
return fileName.substring(0, lastDotIndex);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void streamPageImage(Long bookId, int page, OutputStream outputStream) throws IOException {
|
||||
Path cbxPath = getBookPath(bookId);
|
||||
CachedArchiveMetadata metadata = getCachedMetadata(cbxPath);
|
||||
|
||||
Reference in New Issue
Block a user