mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-10-11 22:50:00 +00:00
Merge pull request #18283 from chino/fix/epub-zip-paths-windows
Fix EPUB metadata and covers not loading on Windows
This commit is contained in:
@@ -245,6 +245,7 @@
|
||||
- [scr4bble](https://github.com/scr4bble)
|
||||
- [Mateus Bandeira](https://github.com/mateusbandeiraa)
|
||||
- [TheDreadPirate](https://github.com/thedreaddpirate)
|
||||
- [Daniel Aquino](https://github.com/chino)
|
||||
- [klizas](https://github.com/klizas)
|
||||
|
||||
# Emby Contributors
|
||||
|
||||
@@ -64,7 +64,8 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
||||
}
|
||||
|
||||
var cover = coverReference.Value;
|
||||
var coverFile = epub.GetEntry(cover.Path);
|
||||
// ZIP entry names always use '/', but the cover path is built with Path.Combine, which uses '\' on Windows
|
||||
var coverFile = epub.GetEntry(cover.Path.Replace('\\', '/'));
|
||||
|
||||
if (coverFile == null)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
@@ -17,7 +16,7 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
||||
/// <returns>The content file path.</returns>
|
||||
public static string? ReadContentFilePath(ZipArchive epub)
|
||||
{
|
||||
var container = epub.GetEntry(Path.Combine("META-INF", "container.xml"));
|
||||
var container = epub.GetEntry("META-INF/container.xml");
|
||||
if (container == null)
|
||||
{
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using MediaBrowser.Providers.Books.OpenPackagingFormat;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Providers.Tests.Books;
|
||||
|
||||
public class EpubUtilsTests
|
||||
{
|
||||
[Fact]
|
||||
public void ReadContentFilePath_ReadsRootFileFromContainer()
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true))
|
||||
{
|
||||
using var writer = new StreamWriter(archive.CreateEntry("META-INF/container.xml").Open(), Encoding.UTF8);
|
||||
writer.Write(
|
||||
"""
|
||||
<?xml version="1.0"?>
|
||||
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
||||
<rootfiles>
|
||||
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
|
||||
</rootfiles>
|
||||
</container>
|
||||
""");
|
||||
}
|
||||
|
||||
stream.Position = 0;
|
||||
using var epub = new ZipArchive(stream, ZipArchiveMode.Read);
|
||||
|
||||
Assert.Equal("OEBPS/content.opf", EpubUtils.ReadContentFilePath(epub));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user