.NET 8 Update (#2496)

This commit is contained in:
Joe Milazzo 2023-12-13 19:16:54 -06:00 committed by GitHub
parent 6d4d2d4a7f
commit b838fd53e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
75 changed files with 590 additions and 405 deletions

View file

@ -40,15 +40,13 @@ public class LibraryController : BaseApiController
private readonly IEventHub _eventHub;
private readonly ILibraryWatcher _libraryWatcher;
private readonly ILocalizationService _localizationService;
private readonly IStreamService _streamService;
private readonly IEasyCachingProvider _libraryCacheProvider;
private const string CacheKey = "library_";
public LibraryController(IDirectoryService directoryService,
ILogger<LibraryController> logger, IMapper mapper, ITaskScheduler taskScheduler,
IUnitOfWork unitOfWork, IEventHub eventHub, ILibraryWatcher libraryWatcher,
IEasyCachingProviderFactory cachingProviderFactory, ILocalizationService localizationService,
IStreamService streamService)
IEasyCachingProviderFactory cachingProviderFactory, ILocalizationService localizationService)
{
_directoryService = directoryService;
_logger = logger;
@ -58,7 +56,6 @@ public class LibraryController : BaseApiController
_eventHub = eventHub;
_libraryWatcher = libraryWatcher;
_localizationService = localizationService;
_streamService = streamService;
_libraryCacheProvider = cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.Library);
}
@ -157,7 +154,7 @@ public class LibraryController : BaseApiController
}));
}
if (!Directory.Exists(path)) return Ok(_directoryService.ListDirectory(Path.GetDirectoryName(path)));
if (!Directory.Exists(path)) return Ok(_directoryService.ListDirectory(Path.GetDirectoryName(path)!));
return Ok(_directoryService.ListDirectory(path));
}

View file

@ -99,7 +99,7 @@ public class OpdsController : BaseApiController
if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)
return BadRequest(await _localizationService.Translate(userId, "opds-disabled"));
var (baseUrl, prefix) = await GetPrefix();
var (_, prefix) = await GetPrefix();
var feed = CreateFeed("Kavita", string.Empty, apiKey, prefix);
SetFeedId(feed, "root");
@ -141,10 +141,37 @@ public class OpdsController : BaseApiController
});
break;
case DashboardStreamType.RecentlyUpdated:
// TODO: See if we can implement this and use (count) on series name for number of updates
feed.Entries.Add(new FeedEntry()
{
Id = "recentlyUpdated",
Title = await _localizationService.Translate(userId, "recently-updated"),
Content = new FeedEntryContent()
{
Text = await _localizationService.Translate(userId, "browse-recently-updated")
},
Links = new List<FeedLink>()
{
CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, $"{prefix}{apiKey}/recently-updated"),
}
});
break;
case DashboardStreamType.MoreInGenre:
// TODO: See if we can implement this
var randomGenre = await _unitOfWork.GenreRepository.GetRandomGenre();
if (randomGenre == null) break;
feed.Entries.Add(new FeedEntry()
{
Id = "moreInGenre",
Title = await _localizationService.Translate(userId, "more-in-genre", randomGenre.Title),
Content = new FeedEntryContent()
{
Text = await _localizationService.Translate(userId, "browse-more-in-genre", randomGenre.Title)
},
Links = new List<FeedLink>()
{
CreateLink(FeedLinkRelation.SubSection, FeedLinkType.AtomNavigation, $"{prefix}{apiKey}/more-in-genre?genreId={randomGenre.Id}"),
}
});
break;
case DashboardStreamType.SmartFilter:
@ -632,6 +659,61 @@ public class OpdsController : BaseApiController
return CreateXmlResult(SerializeXml(feed));
}
[HttpGet("{apiKey}/more-in-genre")]
[Produces("application/xml")]
public async Task<IActionResult> GetMoreInGenre(string apiKey, [FromQuery] int genreId, [FromQuery] int pageNumber = 1)
{
var userId = await GetUser(apiKey);
if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)
return BadRequest(await _localizationService.Translate(userId, "opds-disabled"));
var (baseUrl, prefix) = await GetPrefix();
var genre = await _unitOfWork.GenreRepository.GetGenreById(genreId);
var seriesDtos = await _unitOfWork.SeriesRepository.GetMoreIn(userId, 0, genreId, GetUserParams(pageNumber));
var seriesMetadatas = await _unitOfWork.SeriesRepository.GetSeriesMetadataForIds(seriesDtos.Select(s => s.Id));
var feed = CreateFeed(await _localizationService.Translate(userId, "more-in-genre", genre.Title), $"{prefix}{apiKey}/more-in-genre", apiKey, prefix);
SetFeedId(feed, "more-in-genre");
AddPagination(feed, seriesDtos, $"{prefix}{apiKey}/more-in-genre");
foreach (var seriesDto in seriesDtos)
{
feed.Entries.Add(CreateSeries(seriesDto, seriesMetadatas.First(s => s.SeriesId == seriesDto.Id), apiKey, prefix, baseUrl));
}
return CreateXmlResult(SerializeXml(feed));
}
[HttpGet("{apiKey}/recently-updated")]
[Produces("application/xml")]
public async Task<IActionResult> GetRecentlyUpdated(string apiKey, [FromQuery] int pageNumber = 1)
{
var userId = await GetUser(apiKey);
if (!(await _unitOfWork.SettingsRepository.GetSettingsDtoAsync()).EnableOpds)
return BadRequest(await _localizationService.Translate(userId, "opds-disabled"));
var (baseUrl, prefix) = await GetPrefix();
var seriesDtos = (await _unitOfWork.SeriesRepository.GetRecentlyUpdatedSeries(userId, PageSize)).ToList();
var seriesMetadatas = await _unitOfWork.SeriesRepository.GetSeriesMetadataForIds(seriesDtos.Select(s => s.SeriesId));
var feed = CreateFeed(await _localizationService.Translate(userId, "recently-updated"), $"{prefix}{apiKey}/recently-updated", apiKey, prefix);
SetFeedId(feed, "recently-updated");
//AddPagination(feed, seriesDtos, $"{prefix}{apiKey}/recently-updated");
foreach (var groupedSeries in seriesDtos)
{
var seriesDto = new SeriesDto()
{
Name = $"{groupedSeries.SeriesName} ({groupedSeries.Count})",
Id = groupedSeries.SeriesId,
Format = groupedSeries.Format,
LibraryId = groupedSeries.LibraryId,
};
var metadata = seriesMetadatas.First(s => s.SeriesId == seriesDto.Id);
feed.Entries.Add(CreateSeries(seriesDto, metadata, apiKey, prefix, baseUrl));
}
return CreateXmlResult(SerializeXml(feed));
}
[HttpGet("{apiKey}/on-deck")]
[Produces("application/xml")]
public async Task<IActionResult> GetOnDeck(string apiKey, [FromQuery] int pageNumber = 1)
@ -1161,7 +1243,7 @@ public class OpdsController : BaseApiController
var userId = await GetUser(apiKey);
var progress = await _unitOfWork.AppUserProgressRepository.GetUserProgressDtoAsync(chapterId, userId);
// TODO: Type could be wrong
// NOTE: Type could be wrong, there is nothing I can do in the spec
var link = CreateLink(FeedLinkRelation.Stream, "image/jpeg",
$"{prefix}{apiKey}/image?libraryId={libraryId}&seriesId={seriesId}&volumeId={volumeId}&chapterId={chapterId}&pageNumber=" + "{pageNumber}");
link.TotalPages = mangaFile.Pages;

View file

@ -19,13 +19,11 @@ public class StreamController : BaseApiController
{
private readonly IStreamService _streamService;
private readonly IUnitOfWork _unitOfWork;
private readonly ILogger<StreamController> _logger;
public StreamController(IStreamService streamService, IUnitOfWork unitOfWork, ILogger<StreamController> logger)
public StreamController(IStreamService streamService, IUnitOfWork unitOfWork)
{
_streamService = streamService;
_unitOfWork = unitOfWork;
_logger = logger;
}
/// <summary>

View file

@ -53,7 +53,7 @@ public class ThemeController : BaseApiController
{
await _themeService.UpdateDefault(dto.ThemeId);
}
catch (KavitaException ex)
catch (KavitaException)
{
return BadRequest(await _localizationService.Translate(User.GetUserId(), "theme-doesnt-exist"));
}