Feature: Add EPUB conversion support for CBX files to Kobo Sync (#1538)

* Feature/kobo sync cbx support (#3)

* Feature: Add CBX syncing support to Kobo sync (#2)

* feat: add cbx sync support

* fix: phrasing of setting description to align with CBX terminology

* fix: resolve issue with CBX setting persistence

* fix: updated dev docker compose to align with Dockerfile

* feat: add cbx files as allowed entitlements

* fix: relax tomcat query characters for kobo sync

* fix: remove hardcoded epub restrictions

* fix: reduce image size and resolve relative content paths

* fix: resolve issues with the image file encoding

* feat: add rar and cb7 support

* feat: bring generated epub more in line with epub standard

* fix: resolve issues with extra metadata fields

* fix: make css background colour white to improve e-ink performance

* cleanup: code comments

* feat: add cbx unit tests

* fix: update zipfile to use builder pattern as current method is deprecated

* fix: remove comments

* fix: replace regex pattern to a simpler check

* fix: remove unused imports

* fix: update epub template to use standard language string

* fix: missing line end on css

* fix: remove duplicate query characters

* fix: grammer issue

* fix: resolve typo in the entitlement service test

* fix: redundant imports and update long types

* chore: update test descriptions for cbx conversion

* fix: add check for larger images in archive files. unlikely to occur.

* fix: merge temp dir logic for the book download

* fix: update kobo entitlement to always report the format as epub3

* fix: implement suggested changes around javadocs and some edge cases to handle gracefully

* chore: cleanup variable names to be clearer in download service

* feat: change function to extract to disk instead of storing images in memory

* fix: add temp file clean up into the conversion service

* fix: add visual divider to seperate CBX and EPUB settings

* fix: update lambdas to use method references

* fix: reword setting description for cbx to epub sync

---------

Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com>
This commit is contained in:
CounterClops
2025-11-30 09:53:26 -07:00
committed by GitHub
co-authored by Aditya Chandel
parent e47046aa20
commit dfb73d50d9
22 changed files with 1912 additions and 16 deletions
@@ -17,6 +17,8 @@ app:
server:
forward-headers-strategy: native
port: 8080
tomcat:
relaxed-query-chars: '[,],%,{,},|'
spring:
servlet:
@@ -0,0 +1,38 @@
/* EPUB 3.0 compliant stylesheet for comic books - optimized for e-ink readers */
@page {
margin: 0;
padding: 0;
background-color: #ffffff;
}
html, body {
height: 100vh;
width: 100vw;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #ffffff;
}
body {
display: flex;
align-items: center;
justify-content: center;
background-color: #ffffff;
}
div {
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
background-color: #ffffff;
}
img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
display: block;
}
@@ -0,0 +1,7 @@
<#ftl output_format="XML" encoding="UTF-8">
<?xml version="1.0" encoding="UTF-8"?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="${contentOpfPath}" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
@@ -0,0 +1,110 @@
<#ftl output_format="XML" encoding="UTF-8">
<?xml version="1.0" encoding="UTF-8"?>
<package version="3.0" unique-identifier="BookID" xmlns="http://www.idpf.org/2007/opf">
<metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">${title!""}</dc:title>
<#if subtitle?has_content>
<meta property="title-type" refines="#title">main</meta>
<meta property="display-seq" refines="#title">1</meta>
<dc:title id="subtitle">${subtitle}</dc:title>
<meta property="title-type" refines="#subtitle">subtitle</meta>
<meta property="display-seq" refines="#subtitle">2</meta>
</#if>
<#if authors?has_content>
<#list authors as author>
<dc:creator id="creator${author?index}">${author}</dc:creator>
<meta property="role" refines="#creator${author?index}" scheme="marc:relators">aut</meta>
</#list>
</#if>
<dc:language>${language!""}</dc:language>
<#if publisher?has_content>
<dc:publisher>${publisher}</dc:publisher>
</#if>
<#if publishedDate?has_content>
<dc:date>${publishedDate}</dc:date>
</#if>
<#if description?has_content>
<dc:description>${description}</dc:description>
</#if>
<#-- Series metadata -->
<#if seriesName?has_content>
<meta property="belongs-to-collection" id="series">${seriesName}</meta>
<meta property="collection-type" refines="#series">series</meta>
<#if seriesNumber?has_content>
<meta property="group-position" refines="#series">${seriesNumber}</meta>
</#if>
</#if>
<#-- Identifiers -->
<dc:identifier id="BookID">${identifier!""}</dc:identifier>
<#if isbn13?has_content>
<dc:identifier id="isbn13">${isbn13}</dc:identifier>
<meta refines="#isbn13" property="identifier-type" scheme="onix:codelist5">15</meta>
</#if>
<#if isbn10?has_content>
<dc:identifier id="isbn10">${isbn10}</dc:identifier>
<meta refines="#isbn10" property="identifier-type" scheme="onix:codelist5">02</meta>
</#if>
<#if asin?has_content>
<dc:identifier id="asin">${asin}</dc:identifier>
<meta refines="#asin" property="identifier-type">ASIN</meta>
</#if>
<#if goodreadsId?has_content>
<dc:identifier id="goodreads">${goodreadsId}</dc:identifier>
<meta refines="#goodreads" property="identifier-type">GOODREADS</meta>
</#if>
<#-- Categories/Subjects -->
<#if categories?has_content>
<#list categories as category>
<dc:subject>${category}</dc:subject>
</#list>
</#if>
<#-- Tags as additional subjects -->
<#if tags?has_content>
<#list tags as tag>
<dc:subject>${tag}</dc:subject>
</#list>
</#if>
<#if pageCount?has_content>
<meta property="schema:numberOfPages">${pageCount}</meta>
</#if>
<#-- EPUB 3.0 required metadata -->
<meta property="dcterms:modified">${modified!""}</meta>
<meta name="cover" content="cover" />
<#-- Comic-specific metadata -->
<meta property="rendition:layout">pre-paginated</meta>
<meta property="rendition:orientation">auto</meta>
<meta property="rendition:spread">landscape</meta>
</metadata>
<manifest>
<item id="cover" href="${coverImagePath}" media-type="image/jpeg" properties="cover-image" />
<item id="ncx" href="${tocNcxPath}" media-type="application/x-dtbncx+xml" />
<item id="nav" href="${navXhtmlPath}" properties="nav" media-type="application/xhtml+xml" />
<#-- Loop over the content file groups and emit the two items per entry -->
<#list contentFileGroups as file>
<item id="${'page_' + file.contentKey}" href="${file.htmlPath}" media-type="application/xhtml+xml" />
<item id="${'img_' + file.contentKey}" href="${file.imagePath}" media-type="image/jpeg" />
</#list>
<item id="css" href="${stylesheetCssPath}" media-type="text/css" />
</manifest>
<spine page-progression-direction="ltr" toc="ncx">
<#list contentFileGroups as file>
<itemref idref="page_${file.contentKey}" properties="page-spread-center" />
</#list>
</spine>
</package>
@@ -0,0 +1,15 @@
<#ftl output_format="XML" encoding="UTF-8">
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>Page ${pageNumber}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="${stylesheetPath}" />
</head>
<body>
<div>
<img src="${imageFileName}" alt="Comic page ${pageNumber}" role="img" aria-label="Comic book page ${pageNumber}" />
</div>
</body>
</html>
@@ -0,0 +1,47 @@
<#ftl output_format="XML" encoding="UTF-8">
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>Navigation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
body { font-family: sans-serif; margin: 20px; }
nav h1 { color: #333; }
nav ol { list-style-type: decimal; }
nav a { text-decoration: none; color: #0066cc; }
nav a:hover { text-decoration: underline; }
</style>
</head>
<body>
<nav epub:type="toc" id="toc">
<h1>Table of Contents</h1>
<ol>
<#if contentFileGroups?has_content>
<#list contentFileGroups as file>
<li>
<a href="${file.htmlPath?replace('OEBPS/', '')}">Page ${file?counter}</a>
</li>
</#list>
<#else>
<li>
<a href="Text/page-0001.xhtml">${title!'Unknown Comic'}</a>
</li>
</#if>
</ol>
</nav>
<nav epub:type="page-list" id="page-list">
<h1>List of Pages</h1>
<ol>
<#if contentFileGroups?has_content>
<#list contentFileGroups as file>
<li>
<a href="${file.htmlPath?replace('OEBPS/', '')}" epub:type="pagebreak">${file?counter}</a>
</li>
</#list>
</#if>
</ol>
</nav>
</body>
</html>
@@ -0,0 +1,24 @@
<#ftl output_format="XML" encoding="UTF-8">
<?xml version="1.0" encoding="UTF-8"?>
<ncx version="2005-1" xml:lang="${language!'en'}" xmlns="http://www.daisy.org/z3986/2005/ncx/">
<head>
<meta name="dtb:uid" content="${identifier}" />
<meta name="dtb:depth" content="1" />
<meta name="dtb:totalPageCount" content="${contentFileGroups?size}" />
<meta name="dtb:maxPageNumber" content="${contentFileGroups?size}" />
<meta name="generated" content="true" />
</head>
<docTitle>
<text>${title!'Unknown Comic'}</text>
</docTitle>
<navMap>
<navPoint id="cover" playOrder="1">
<navLabel>
<text>${title!'Unknown Comic'}</text>
</navLabel>
<#if contentFileGroups?has_content>
<content src="${contentFileGroups[0].htmlPath?replace('OEBPS/', '')}" />
</#if>
</navPoint>
</navMap>
</ncx>