fix(epub): support cover edits when media type changes (#2281)

This commit is contained in:
James Ward
2026-09-12 13:03:49 -04:00
committed by GitHub
parent d75c1282f4
commit 828806a4aa
2 changed files with 47 additions and 3 deletions
@@ -550,6 +550,18 @@ public class EpubMetadataWriter implements MetadataWriter {
throw new IOException("Failed to parse container.xml to locate OPF path", e);
}
if (existingCoverItem != null) {
String existingMediaType = existingCoverItem.getAttribute("media-type");
if (!existingMediaType.equals(mediaType)) {
// If the existing cover item exists but has a different media type we can't
// use it. However, because it's _possible_ that the cover MAY be used elsewhere
// in the epub (such as referenced in HTML) we cannot delete the manifest item
// or the file. All we can do is discard it as the existing cover manifest item,
// and treat the epub as if it has no cover, and place a new cover manifest item.
existingCoverItem = null;
}
}
Path opfDir = opfPath.getParent();
if (existingCoverItem != null) {