Skip to content

Commit

Permalink
Switched to the new API for Kavita+ which reduces some time
Browse files Browse the repository at this point in the history
  • Loading branch information
majora2007 committed Jan 17, 2024
1 parent 6348bda commit 0e7a346
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
13 changes: 7 additions & 6 deletions API/Controllers/MetadataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using API.DTOs;
using API.DTOs.Filtering;
using API.DTOs.Metadata;
using API.DTOs.Recommendation;
using API.DTOs.SeriesDetail;
using API.Entities.Enums;
using API.Extensions;
Expand All @@ -22,7 +21,7 @@ namespace API.Controllers;
#nullable enable

public class MetadataController(IUnitOfWork unitOfWork, ILocalizationService localizationService, ILicenseService licenseService,
IRatingService ratingService, IReviewService reviewService, IRecommendationService recommendationService)
IRatingService ratingService, IReviewService reviewService, IRecommendationService recommendationService, IExternalMetadataService metadataService)
: BaseApiController
{
/// <summary>
Expand Down Expand Up @@ -199,11 +198,13 @@ public async Task<ActionResult<SeriesDetailPlusDto>> GetKavitaPlusSeriesDetailDa
return Ok(seriesDetail);
}

seriesDetail = await metadataService.GetSeriesDetail(User.GetUserId(), seriesId);

// Temp solution, needs to be updated with new API
seriesDetail.Ratings = await ratingService.GetRatings(seriesId);
seriesDetail.Reviews = await reviewService.GetReviewsForSeries(User.GetUserId(), seriesId);
seriesDetail.Recommendations =
await recommendationService.GetRecommendationsForSeries(User.GetUserId(), seriesId);
// seriesDetail.Ratings = await ratingService.GetRatings(seriesId);
// seriesDetail.Reviews = await reviewService.GetReviewsForSeries(User.GetUserId(), seriesId);
// seriesDetail.Recommendations =
// await recommendationService.GetRecommendationsForSeries(User.GetUserId(), seriesId);

return Ok(seriesDetail);

Expand Down
2 changes: 1 addition & 1 deletion API/Services/Plus/ExternalMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ExternalMetadataService(IUnitOfWork unitOfWork, ILogger<ExternalMetadataS
await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId,
SeriesIncludes.Metadata | SeriesIncludes.Library | SeriesIncludes.Volumes | SeriesIncludes.Chapters);
if (series == null || series.Library.Type == LibraryType.Comic) return new SeriesDetailPlusDto();
var license = await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey);
var license = (await _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.LicenseKey)).Value;

var user = await _unitOfWork.UserRepository.GetUserByIdAsync(userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ interface StoryLineItem {
isChapter: boolean;
}

const KavitaPlusSupportedLibraryTypes = [LibraryType.Manga, LibraryType.Book];

@Component({
selector: 'app-series-detail',
templateUrl: './series-detail.component.html',
Expand Down Expand Up @@ -583,20 +585,17 @@ export class SeriesDetailComponent implements OnInit, AfterContentChecked {
});
this.setContinuePoint();

if (KavitaPlusSupportedLibraryTypes.includes(this.libraryType) && loadExternal) {
this.loadPlusMetadata(this.seriesId);
}

forkJoin({
libType: this.libraryService.getLibraryType(this.libraryId),
series: this.seriesService.getSeries(seriesId)
}).subscribe(results => {
this.libraryType = results.libType;
this.series = results.series;

const KavitaPlusSupportedLibraryTypes = [LibraryType.Manga, LibraryType.Book];

if (KavitaPlusSupportedLibraryTypes.includes(this.libraryType) && loadExternal) {
//this.loadReviews(true);
this.loadPlusMetadata(this.seriesId);
}

this.titleService.setTitle('Kavita - ' + this.series.name + ' Details');

this.seriesActions = this.actionFactoryService.getSeriesActions(this.handleSeriesActionCallback.bind(this))
Expand Down Expand Up @@ -693,19 +692,19 @@ export class SeriesDetailComponent implements OnInit, AfterContentChecked {
}
}

loadRecommendations() {
this.seriesService.getRecommendationsForSeries(this.seriesId).subscribe(rec => {
rec.ownedSeries.map(r => {
this.seriesService.getMetadata(r.id).subscribe(m => r.summary = m.summary);
});
this.combinedRecs = [...rec.ownedSeries, ...rec.externalSeries];
this.hasRecommendations = this.combinedRecs.length > 0;
this.cdRef.markForCheck();
});
}
// loadRecommendations() {
// this.seriesService.getRecommendationsForSeries(this.seriesId).subscribe(rec => {
// rec.ownedSeries.map(r => {
// this.seriesService.getMetadata(r.id).subscribe(m => r.summary = m.summary);
// });
// this.combinedRecs = [...rec.ownedSeries, ...rec.externalSeries];
// this.hasRecommendations = this.combinedRecs.length > 0;
// this.cdRef.markForCheck();
// });
// }

loadPlusMetadata(seriesId: number) {
this.metadataService.getSeriesMetadataFromPlus(this.seriesId).subscribe(data => {
this.metadataService.getSeriesMetadataFromPlus(seriesId).subscribe(data => {
if (data === null) return;

// Reviews
Expand All @@ -721,12 +720,9 @@ export class SeriesDetailComponent implements OnInit, AfterContentChecked {
this.cdRef.markForCheck();
});
}
loadReviews(loadRecs: boolean = false) {
loadReviews() {
this.seriesService.getReviews(this.seriesId).subscribe(reviews => {
this.reviews = [...reviews];
if (loadRecs) {
this.loadRecommendations(); // We do this as first load will spam 3 calls on API layer
}
this.cdRef.markForCheck();
});
}
Expand Down

0 comments on commit 0e7a346

Please sign in to comment.