mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-03 13:44:31 -04:00
Beefed up ToC generation to handle new ways of packing epub. (#840)
This commit is contained in:
parent
e7e9e170ba
commit
d2807253c3
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using API.Data;
|
using API.Data;
|
||||||
@ -109,32 +110,12 @@ namespace API.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (navigationItem.Link == null)
|
CreateToCChapter(navigationItem, nestedChapters, chaptersList, mappings);
|
||||||
{
|
}
|
||||||
var item = new BookChapterItem()
|
|
||||||
{
|
if (navigationItem.NestedItems.Count == 0)
|
||||||
Title = navigationItem.Title,
|
{
|
||||||
Children = nestedChapters
|
CreateToCChapter(navigationItem, Array.Empty<BookChapterItem>(), chaptersList, mappings);
|
||||||
};
|
|
||||||
if (nestedChapters.Count > 0)
|
|
||||||
{
|
|
||||||
item.Page = nestedChapters[0].Page;
|
|
||||||
}
|
|
||||||
chaptersList.Add(item);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var groupKey = BookService.CleanContentKeys(navigationItem.Link.ContentFileName);
|
|
||||||
if (mappings.ContainsKey(groupKey))
|
|
||||||
{
|
|
||||||
chaptersList.Add(new BookChapterItem()
|
|
||||||
{
|
|
||||||
Title = navigationItem.Title,
|
|
||||||
Page = mappings[groupKey],
|
|
||||||
Children = nestedChapters
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +168,38 @@ namespace API.Controllers
|
|||||||
return Ok(chaptersList);
|
return Ok(chaptersList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CreateToCChapter(EpubNavigationItemRef navigationItem, IList<BookChapterItem> nestedChapters, IList<BookChapterItem> chaptersList,
|
||||||
|
IReadOnlyDictionary<string, int> mappings)
|
||||||
|
{
|
||||||
|
if (navigationItem.Link == null)
|
||||||
|
{
|
||||||
|
var item = new BookChapterItem()
|
||||||
|
{
|
||||||
|
Title = navigationItem.Title,
|
||||||
|
Children = nestedChapters
|
||||||
|
};
|
||||||
|
if (nestedChapters.Count > 0)
|
||||||
|
{
|
||||||
|
item.Page = nestedChapters[0].Page;
|
||||||
|
}
|
||||||
|
|
||||||
|
chaptersList.Add(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var groupKey = BookService.CleanContentKeys(navigationItem.Link.ContentFileName);
|
||||||
|
if (mappings.ContainsKey(groupKey))
|
||||||
|
{
|
||||||
|
chaptersList.Add(new BookChapterItem()
|
||||||
|
{
|
||||||
|
Title = navigationItem.Title,
|
||||||
|
Page = mappings[groupKey],
|
||||||
|
Children = nestedChapters
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("{chapterId}/book-page")]
|
[HttpGet("{chapterId}/book-page")]
|
||||||
public async Task<ActionResult<string>> GetBookPage(int chapterId, [FromQuery] int page)
|
public async Task<ActionResult<string>> GetBookPage(int chapterId, [FromQuery] int page)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user