Skip to content

Commit

Permalink
Fixed a bug where there could be a duplicate key in OPDS for some uni…
Browse files Browse the repository at this point in the history
…que configurations.
  • Loading branch information
majora2007 committed Sep 8, 2024
1 parent 49c4969 commit ddb22ba
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions API/Controllers/OPDSController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ public async Task<IActionResult> GetSeries(string apiKey, int seriesId)
feed.Links.Add(CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"{baseUrl}api/image/series-cover?seriesId={seriesId}&apiKey={apiKey}"));

var chapterDict = new Dictionary<int, short>();
var fileDict = new Dictionary<int, short>();
var seriesDetail = await _seriesService.GetSeriesDetail(seriesId, userId);
foreach (var volume in seriesDetail.Volumes)
{
Expand All @@ -881,12 +882,14 @@ public async Task<IActionResult> GetSeries(string apiKey, int seriesId)
foreach (var chapter in chaptersForVolume)
{
var chapterId = chapter.Id;
if (chapterDict.ContainsKey(chapterId)) continue;
if (!chapterDict.TryAdd(chapterId, 0)) continue;

var chapterDto = _mapper.Map<ChapterDto>(chapter);
foreach (var mangaFile in chapter.Files)
{
chapterDict.Add(chapterId, 0);
// If a chapter has multiple files that are within one chapter, this dict prevents duplicate key exception
if (!fileDict.TryAdd(mangaFile.Id, 0)) continue;

feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, volume.Id, chapterId, _mapper.Map<MangaFileDto>(mangaFile), series,
chapterDto, apiKey, prefix, baseUrl));
}
Expand All @@ -905,6 +908,8 @@ public async Task<IActionResult> GetSeries(string apiKey, int seriesId)
var chapterDto = _mapper.Map<ChapterDto>(chapter);
foreach (var mangaFile in files)
{
// If a chapter has multiple files that are within one chapter, this dict prevents duplicate key exception
if (!fileDict.TryAdd(mangaFile.Id, 0)) continue;
feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, chapter.VolumeId, chapter.Id, _mapper.Map<MangaFileDto>(mangaFile), series,
chapterDto, apiKey, prefix, baseUrl));
}
Expand All @@ -916,6 +921,9 @@ public async Task<IActionResult> GetSeries(string apiKey, int seriesId)
var chapterDto = _mapper.Map<ChapterDto>(special);
foreach (var mangaFile in files)
{
// If a chapter has multiple files that are within one chapter, this dict prevents duplicate key exception
if (!fileDict.TryAdd(mangaFile.Id, 0)) continue;

feed.Entries.Add(await CreateChapterWithFile(userId, seriesId, special.VolumeId, special.Id, _mapper.Map<MangaFileDto>(mangaFile), series,
chapterDto, apiKey, prefix, baseUrl));
}
Expand Down

0 comments on commit ddb22ba

Please sign in to comment.