Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
OPDS Fix (#737)
Joseph Milazzo69246d80fb34
diff --git a/API/Controllers/OPDSController.cs b/API/Controllers/OPDSController.csindex e7771c8e1..c9f460590 100644--- a/API/Controllers/OPDSController.cs+++ b/API/Controllers/OPDSController.cs@@ -17,6 +17,7 @@ using API.Interfaces.Services;using API.Services;using Kavita.Common;using Microsoft.AspNetCore.Mvc;+using Microsoft.Extensions.Logging;namespace API.Controllers{@@ -48,7 +49,6 @@ namespace API.Controllers_cacheService = cacheService;_readerService = readerService;-_xmlSerializer = new XmlSerializer(typeof(Feed));_xmlOpenSearchSerializer = new XmlSerializer(typeof(OpenSearchDescription));@@ -62,7 +62,7 @@ namespace API.Controllersif (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)return BadRequest("OPDS is not enabled on this server");var feed = CreateFeed("Kavita", string.Empty, apiKey);- feed.Id = "root";+ SetFeedId(feed, "root");feed.Entries.Add(new FeedEntry(){Id = "inProgress",@@ -140,9 +140,8 @@ namespace API.Controllersreturn BadRequest("OPDS is not enabled on this server");var userId = await GetUser(apiKey);var libraries = await _unitOfWork.LibraryRepository.GetLibrariesForUserIdAsync(userId);-var feed = CreateFeed("All Libraries", $"{apiKey}/libraries", apiKey);-+ SetFeedId(feed, "libraries");foreach (var library in libraries){feed.Entries.Add(new FeedEntry()@@ -181,7 +180,7 @@ namespace API.Controllersvar feed = CreateFeed("All Collections", $"{apiKey}/collections", apiKey);-+ SetFeedId(feed, "collections");foreach (var tag in tags){feed.Entries.Add(new FeedEntry()@@ -198,15 +197,6 @@ namespace API.Controllers});}- if (tags.Count == 0)- {- feed.Entries.Add(new FeedEntry()- {- Id = "0",- Title = "Nothing here",- });- }-return CreateXmlResult(SerializeXml(feed));}@@ -244,6 +234,7 @@ namespace API.Controllers});var feed = CreateFeed(tag.Title + " Collection", $"{apiKey}/collections/{collectionId}", apiKey);+ SetFeedId(feed, $"collections-{collectionId}");AddPagination(feed, series, $"{Prefix}{apiKey}/collections/{collectionId}");foreach (var seriesDto in series)@@ -270,7 +261,7 @@ namespace API.Controllersvar feed = CreateFeed("All Reading Lists", $"{apiKey}/reading-list", apiKey);-+ SetFeedId(feed, "reading-list");foreach (var readingListDto in readingLists){feed.Entries.Add(new FeedEntry()@@ -305,6 +296,7 @@ namespace API.Controllers}var feed = CreateFeed(readingList.Title + " Reading List", $"{apiKey}/reading-list/{readingListId}", apiKey);+ SetFeedId(feed, $"reading-list-{readingListId}");var items = (await _unitOfWork.ReadingListRepository.GetReadingListItemDtosByIdAsync(readingListId, userId)).ToList();foreach (var item in items)@@ -321,17 +313,6 @@ namespace API.Controllers});}- if (items.Count == 0)- {- feed.Entries.Add(new FeedEntry()- {- Id = "0",- Title = "Nothing here",- });- }---return CreateXmlResult(SerializeXml(feed));}@@ -357,6 +338,7 @@ namespace API.Controllers}, _filterDto);var feed = CreateFeed(library.Name, $"{apiKey}/libraries/{libraryId}", apiKey);+ SetFeedId(feed, $"library-{library.Name}");AddPagination(feed, series, $"{Prefix}{apiKey}/libraries/{libraryId}");foreach (var seriesDto in series)@@ -381,6 +363,7 @@ namespace API.Controllers}, _filterDto);var feed = CreateFeed("Recently Added", $"{apiKey}/recently-added", apiKey);+ SetFeedId(feed, "recently-added");AddPagination(feed, recentlyAdded, $"{Prefix}{apiKey}/recently-added");foreach (var seriesDto in recentlyAdded)@@ -388,16 +371,6 @@ namespace API.Controllersfeed.Entries.Add(CreateSeries(seriesDto, apiKey));}- if (recentlyAdded.Count == 0)- {- feed.Entries.Add(new FeedEntry()- {- Id = "0",- Title = "Nothing here",- });- }--return CreateXmlResult(SerializeXml(feed));}@@ -421,6 +394,7 @@ namespace API.ControllersResponse.AddPaginationHeader(pagedList.CurrentPage, pagedList.PageSize, pagedList.TotalCount, pagedList.TotalPages);var feed = CreateFeed("In Progress", $"{apiKey}/in-progress", apiKey);+ SetFeedId(feed, "in-progress");AddPagination(feed, pagedList, $"{Prefix}{apiKey}/in-progress");foreach (var seriesDto in pagedList)@@ -428,15 +402,6 @@ namespace API.Controllersfeed.Entries.Add(CreateSeries(seriesDto, apiKey));}- if (pagedList.Count == 0)- {- feed.Entries.Add(new FeedEntry()- {- Id = "0",- Title = "Nothing here",- });- }-return CreateXmlResult(SerializeXml(feed));}@@ -460,7 +425,7 @@ namespace API.Controllersvar series = await _unitOfWork.SeriesRepository.SearchSeries(libraries.Select(l => l.Id).ToArray(), query);var feed = CreateFeed(query, $"{apiKey}/series?query=" + query, apiKey);-+ SetFeedId(feed, "search-series");foreach (var seriesDto in series){feed.Entries.Add(CreateSeries(seriesDto, apiKey));@@ -469,6 +434,11 @@ namespace API.Controllersreturn CreateXmlResult(SerializeXml(feed));}+ private static void SetFeedId(Feed feed, string id)+ {+ feed.Id = id;+ }+[HttpGet("{apiKey}/search")][Produces("application/xml")]public async Task<IActionResult> GetSearchDescriptor(string apiKey)@@ -502,6 +472,7 @@ namespace API.Controllersvar series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);var volumes = await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(seriesId, userId);var feed = CreateFeed(series.Name + " - Volumes", $"{apiKey}/series/{series.Id}", apiKey);+ SetFeedId(feed, $"series-{series.Id}");feed.Links.Add(CreateLink(FeedLinkRelation.Image, FeedLinkType.Image, $"/api/image/series-cover?seriesId={seriesId}"));foreach (var volumeDto in volumes){@@ -525,6 +496,7 @@ namespace API.Controllers_chapterSortComparer);var feed = CreateFeed(series.Name + " - Volume " + volume.Name + " - Chapters ", $"{apiKey}/series/{seriesId}/volume/{volumeId}", apiKey);+ SetFeedId(feed, $"series-{series.Id}-volume-{volume.Id}-chapters");foreach (var chapter in chapters){feed.Entries.Add(new FeedEntry()@@ -555,6 +527,7 @@ namespace API.Controllersvar files = await _unitOfWork.ChapterRepository.GetFilesForChapterAsync(chapterId);var feed = CreateFeed(series.Name + " - Volume " + volume.Name + " - Chapters ", $"{apiKey}/series/{seriesId}/volume/{volumeId}/chapter/{chapterId}", apiKey);+ SetFeedId(feed, $"series-{series.Id}-volume-{volume.Id}-chapter-{chapter.Id}-files");foreach (var mangaFile in files){feed.Entries.Add(CreateChapter(seriesId, volumeId, chapterId, mangaFile, series, volume, chapter, apiKey));diff --git a/UI/Web/src/app/_services/message-hub.service.ts b/UI/Web/src/app/_services/message-hub.service.tsindex ba62adb49..1365746ed 100644--- a/UI/Web/src/app/_services/message-hub.service.ts+++ b/UI/Web/src/app/_services/message-hub.service.ts@@ -1,4 +1,5 @@import { EventEmitter, Injectable } from '@angular/core';+import { Router } from '@angular/router';import { HubConnection, HubConnectionBuilder } from '@microsoft/signalr';import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';import { ToastrService } from 'ngx-toastr';@@ -49,7 +50,7 @@ export class MessageHubService {isAdmin: boolean = false;- constructor(private modalService: NgbModal, private toastr: ToastrService) {+ constructor(private modalService: NgbModal, private toastr: ToastrService, private router: Router) {}@@ -111,7 +112,8 @@ export class MessageHubService {payload: resp.body});this.seriesAdded.emit(resp.body);- if (this.isAdmin) {+ // Don't show the toast when user has reader open+ if (this.isAdmin && this.router.url.match(/\d+\/manga|book\/\d+/gi) !== null) {this.toastr.info('Series ' + (resp.body as SeriesAddedEvent).seriesName + ' added');}});