Added series subscriptions. Added series searching. Fixed database relations. Added logging for library controller.
This commit is contained in:
@ -5,7 +5,7 @@ import { PinoLogger } from 'nestjs-pino';
|
||||
import { GoogleSearchContext } from 'src/providers/contexts/google.search.context';
|
||||
import { BookSearchResultDto } from 'src/providers/dto/book-search-result.dto';
|
||||
import { ProvidersService } from 'src/providers/providers.service';
|
||||
import { CreateSeriesSubscriptionJobDto } from 'src/series/dto/create-series-subscription-job.dto';
|
||||
import { SeriesSubscriptionJobDto } from 'src/series/dto/series-subscription-job.dto';
|
||||
import { LibraryService } from './library.service';
|
||||
|
||||
@Processor('library')
|
||||
@ -27,7 +27,7 @@ export class LibraryConsumer extends WorkerHost {
|
||||
});
|
||||
|
||||
if (job.name == 'new_series') {
|
||||
const series: CreateSeriesSubscriptionJobDto = job.data;
|
||||
const series: SeriesSubscriptionJobDto = job.data;
|
||||
const books = await this.search(job, series, null);
|
||||
|
||||
let counter = 0;
|
||||
@ -51,8 +51,8 @@ export class LibraryConsumer extends WorkerHost {
|
||||
}
|
||||
}
|
||||
} else if (job.name == 'update_series') {
|
||||
const series: CreateSeriesSubscriptionJobDto = job.data;
|
||||
const existingBooks = await this.library.getBooksFromSeries(series);
|
||||
const series: SeriesSubscriptionJobDto = job.data;
|
||||
const existingBooks = await this.library.findBooksFromSeries(series);
|
||||
const existingVolumes = existingBooks.map(b => b.volume);
|
||||
const lastPublishedBook = existingBooks.sort((a, b) => b.publishedAt.getTime() - a.publishedAt.getTime())[0];
|
||||
const books = await this.search(job, series, lastPublishedBook?.publishedAt);
|
||||
@ -100,7 +100,7 @@ export class LibraryConsumer extends WorkerHost {
|
||||
return null;
|
||||
}
|
||||
|
||||
private async search(job: Job, series: CreateSeriesSubscriptionJobDto, after: Date|null): Promise<{ result: BookSearchResultDto, score: number }[]> {
|
||||
private async search(job: Job, series: SeriesSubscriptionJobDto, after: Date | null): Promise<{ result: BookSearchResultDto, score: number }[]> {
|
||||
let context = this.provider.generateSearchContext(series.provider, series.title) as GoogleSearchContext;
|
||||
context.maxResults = '40';
|
||||
if (after) {
|
||||
@ -131,7 +131,7 @@ export class LibraryConsumer extends WorkerHost {
|
||||
.sort((a, b) => a.result.volume - b.result.volume || b.score - a.score)
|
||||
.filter((_, index, arr) => index == 0 || arr[index - 1].result.volume != arr[index].result.volume);
|
||||
job.updateProgress(25);
|
||||
|
||||
|
||||
this.logger.debug({
|
||||
class: LibraryConsumer.name,
|
||||
method: this.search.name,
|
||||
@ -185,7 +185,7 @@ export class LibraryConsumer extends WorkerHost {
|
||||
});
|
||||
}
|
||||
|
||||
private toScore(book: BookSearchResultDto, series: CreateSeriesSubscriptionJobDto): ({ result: BookSearchResultDto, score: number }) {
|
||||
private toScore(book: BookSearchResultDto, series: SeriesSubscriptionJobDto): ({ result: BookSearchResultDto, score: number }) {
|
||||
if (!book) {
|
||||
return {
|
||||
result: null,
|
||||
|
Reference in New Issue
Block a user